Final, Static, finally, finalize comparison

Source: Internet
Author: User

Final, Static, finally, finalize comparison
Final keyword

1. The final modified class, which indicates that the class cannot be inherited, therefore, a class cannot be declared abstract and final class by a colleague;

2, the final modified variable, the variable must be assigned an initial value, and its values in the whole process will not change;

3, Final modification method, called the final method. It cannot be redefined by the quilt, i.e. it cannot be overwritten, nor can it be overloaded;

Notice the difference between it and the static

Static keyword


(1) The data or method of static definition can be called directly by the class without the instance of new class;

(2) static code block; Another key function of the static keyword is to form static blocks of code to optimize program performance.

an exception handling mechanism for Finally:java.

(1) Finally is the best complement to the Java exception handling model. The finally structure makes the code always executes, regardless of whether or not an exception occurs.

(2) Use finally to maintain the internal state of the object and to clean up non-memory resources.

(3) Especially in the case of shutting down the database connection, if the programmer puts the close () method of the database connection in the Finally, it will greatly reduce the chance of the program error.

a method name in the object class in Finalize:java.

Ava Technology uses the Finalize () method to do the necessary cleanup work before the garbage collector clears objects from memory.

This method is called by the garbage collector to this object when it determines that the object is not referenced.

It is defined in the object class, so all classes inherit it. Subclasses override the Finalize () method to organize system resources or perform other cleanup work.

The Finalize () method is called on the object before the object is deleted by the garbage collector.






Final, Static, finally, finalize comparison

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.