Purpose of finalization - Core Java

What is the purpose of finalization?

Finalization is the facility to invoke finalized() method. The purpose of finalization is to perform some action before the objects get cleaned up. This method performs the required cleanup before the garbage collection, which means the elimination of the ‘orphan objects’.

Finalization is provided by Java for classes that use native resources to perform clean up before the objects are subjected to garbage collection.

The native resources are beyond the control of Java's garbage collector.
The responsibility of cleaning up the native allocations depends on the object's finalization code.

Finalization is done so that the native resources are not left in the memory even after the Java instances are terminated by garbage collection.
Difference between the File and RandomAccessFile classes - Core Java
Difference between the File and RandomAccessFile classes - The File class is used to perform the operations on files and directories of the file system of an operating system...
StringBuilder vs. StringBuffer - Core Java
Difference between StringBuilder and StringBuffer - StringBuffer is thread safe, where as StringBuilder is not. In other words, StringBuffer class is synchronized and StringBuilder class is not synchronized...
How to implement shallow cloning and deep cloning - Core Java
Explain how to implement shallow cloning and deep cloning - Cloning is a process to create copies of objects...
Post your comment