Write some small details of the code, mainly performance considerations.

Source: Internet
Author: User

1. String concatenation, when writing code in order to facilitate the use of the + number to splice strings, will create extra objects, should use StringBuffer or StringBuilder2. Basic type and package type: The basic type is much more efficient than the package type---because the encapsulation type is to be split into the basic type when the operation is done and the packet----compared to the efficiency--use the basic type as much as possible for no special reason. 3. Static methods are more efficient than abstract methods, and you can avoid just using a method of a class, and do not access the fields of this class. And to create an object that is not necessary. 4. For constants of classes, use theStaticfinal, the initialization of all constants in the Dex file can be initialized, avoiding the use of field search methods.
/** * Here's an egg, a little 13 *    /Normal constants when the JVM first loads the class file, go back and call a <clinit> method to assign a value to the normal constant. The final modified constant is not going to call the <clinit> method to assign the value, because the final particularity.

we generally feel that final and static is no different, one is only assigned once, one can be assigned multiple times. I also think, later neuropathy hair, found:
static acts on the member variable representation to save a copy. Note this copy. final action on a member variable indicates that the variable is immutable.
We all know one thing, replicas are used because of replacement values. The final representative does not have a copy. There is no problem with replacing values.  The assignment is not initialized. The initialization assignment is used here.

that's another question, what is final immutable?     when a class containing the final attribute is loaded into memory and instantiated, memory is allocated for the final property, and the property must be initialized and immutable. That is, if it is of the basic type, then its value can no longer be changed, and if it is an object, the reference is immutable and the object itself can be changed. ---The idea of Java programming

That is, the constant of the static final modifier corresponds to the concept of "123";
In this way, the JVM does not use field search to initialize. Instead, it uses a relatively lightweight, constant way.

forgetting to say static modifier's member variable, it is still, but we seem to be easy to ignore, he is a variable problem, is that the variable will be in the class loading, call the <clinit> method to initialize the assigned value.
constants are initialized directly when the JVM loads the class file.         It feels like no one can read, I write these ghosts ....
5. To understand the data structure of the container used, select an effective container to implement the data operation according to the advantages and disadvantages of its data structure. 6. In the for (), try not to invoke the method, can improve efficiency.     "Java programming thought" a book that has a lot of meaning can be seen. I don't know what to write, bye.                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp            -----Endingwar

At the end, attach a poem to motivate yourself and learn to appreciate the joy of learning:    Seven Times I have despised my Soul--kahlil Gibran
For the first time, when it could have been aggressive, but the second time, when it was empty, filled with love, and the third time, between difficulty and ease, it chose easy, and for the fourth time, it made a mistake, but relieved himself by the mistake of others, and fifth time, it was free and weak, but regarded it as the tenacity of life; sixth time, When it despised an ugly face, but did not know that it is the mask of a pair, the seventh time, it sideways in the sludge of life, although not reconciled, but also timid.

Write some small details of the code, mainly performance considerations.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.