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 ++ ).