Finalize (), final, and fianlly in Java

Source: Internet
Author: User

Java is similar to C ++. Java syntax is very similar to C ++. Java has classes, methods, and data members. Java classes have constructors, and Java has exception handling. However, if you have used C ++, you will find that Java also loses some features that may be familiar to you. One of these features is the destructor. Instead of using destructor, JAVA supports the finalize () method.

In this article, we will describe the differences between finalize () and c ++ destructor. Unlike Java, C ++ supports local objects (stack-based) and Global Objects (stack-based ). Because of this double support, C ++ also provides automatic constructor and destructor, which leads to calls to constructor and destructor (for heap objects) memory Allocation and release. In Java, all objects reside in the heap memory, so local objects do not exist. As a result, Java designers feel that they do not need destructor (as implemented in C ++ ).

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.