[Careercup] 14.3 Final Finally Finalize the keyword comparison

Source: Internet
Author: User
Tags finally block

14.3 What is the difference between final, finally, and finalize?

This topic examines three of our Java final,finally and finalize keywords that look very similar to each other.

Don't look at them like three long, but it's not the same thing at all. Final is used before a variable, method, or class to indicate whether it is changeable. And finally is used in the Try/catch module, but the table of code is always executed. The Finalize method is called by the garbage manager when no references exist. Below to further differentiate them:

Final

Variables that act on the primary type: The value of the variable cannot be changed

Variables that work on reference types: Reference variables cannot point to other objects in the heap

Acting on a method: The method cannot be overridden

Acting on a class: The class cannot have subclasses

Finally

Finally block can be a try or catch, the inside of the code will always be executed (except the virtual machine or thread in the Try/catch end)

Finalize ()

The Finalize () method is called by the garbage collection mechanism when no reference exists. Regular backup to clean up resources, such as closing a file.

[Careercup] 14.3 Final Finally Finalize the keyword 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.