This article provides some characteristics that affect the performance of Java programming. In order to improve the performance of Java programs, some methods and techniques are often used.
1. Try to use the final modifier.
Classes with final modifiers cannot be derived. There are many examples of final applications in the Java core API, such as java. lang. String. Specifying final for the String class prevents the user from overwriting the length () method. In addition, if a class is final, all methods of the class are final. The java compiler will look for opportunities to inline (inline) All final methods (this is related to the specific compiler implementation ). This can increase the performance by an average of 50%.
2. Try to reuse objects.
In particular, the use of String objects should be replaced by StringBuffer in case of String connection. Because the system not only takes time to generate objects, it may also take time to recycle and process these objects. Therefore, generating too many objects will greatly affect the program performance.
3. Use local variables whenever possible.
The parameters passed during method calling and the temporary variables created in the call are saved in the Stack, which is faster. Other variables, such as static variables and instance variables, are created in Heap, which is slow.