Before performing the garbage collection the JVM called the finalize() method to cleanup the resources such as closing the file or socket connection etc.
The finalize() method is declared in the java.lang.Object class.
When you implement the finalize method, you are actually overriding it from the Object class.Your finalize() method must be declared as follows:
protected void finalize () throws throwable{//some cleanup code here}