Some characteristics that affect performance in Java programming

Source: Internet
Author: User

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.

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.