Java JNI Question:
Download Questions PDF

What is finalize()? Is finalize() similar to a destructor?

Answer:

The finalize() method of java is invoked by JVM to reclaim the inaccessible memory location, When the ‘orphan’ object (without reference) is to be released, JVM invokes the finalize() method, when the next garbage collection passes and reclaims the memory space. Choosing to use finalize() provides the ability for performing some important cleanup action at the time of garbage collection.

The destructor of C++ language will always destroy the objects. But Garbage collection is not destruction. In case, some functionality needs to be performed prior to garbage collection. The respective functionality must be hard coded by the developer. As Java has no destructor or similar concept, the process need to be embedded into a method for cleanup. The finalize() method can be overridden to perform this cleanup.

Download Java JNI Interview Questions And Answers PDF

Previous QuestionNext Question
Why does Java have different data types for integers and floating-point values?Explain the advantages and disadvantages of using JNI?