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