Interviewer And Interviewee Guide

Java JNI Interview Question:

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

Submitted by: Administrator
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.
Submitted by: Administrator

Read Online Java JNI Job Interview Questions And Answers
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.