The difference between Java->final, finally, finalize

Source: Internet
Author: User

final: used when declaring a global variable, meaning that the variable cannot be modified , cannot beoverridden, is generally used to declare a constant, or the value of a system setting, a class that is decorated with it Cannot be inherited .

Example: publicstatic final String a = "123"
This means: public (all scopes visible), static (only one in the system), final (immutable) variable A, value 123

finally: used in the try-catch-finally block, the function is, whether the code executes a try or catch, will eventually execute the code in finally

Example:
try{
Here are some code that might appear to be abnormal
}catch (Exception e) {
Execute the code here if an exception occurs. Otherwise, do not execute
}finally{
regardless of whether there is an exception, execute the code here
}

Finalize: Summons the garbage Collector command, and once you use this method, the system will schedule a garbage collection
However, it is not immediately executed, and the point of execution is not deterministic.
It is not necessary to use Finalize () in the absence of special requirements, and it is good for the GC to manage itself.

The difference between Java->final, finally, finalize

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.