Finalization is the JVM's method for forcing the finalize methods in objects that are ready for finalization (that is objects that no longer have references to them in your app, or threads that have completed their run methods). The finalize method (though there seems to be some disagreement as to whether or not one should use it) can be seen as the objects destructor. One often uses it (correctly?) to free up certain resourses, set certain variables to null, etc.
Garbage Collection is the JVM's mechanism for cleaning up the system and freeing up space occupied by destroyed objects.
You can always force finalization or garbage collection by calling System.gc() and System.runFinalization, respectively. This can be useful when you want to ensure that system resources are freed at a specific point in your application instead of waiting for the JVM to get around to it when it sees fit.
I hope this has made sense, and that I have not made any huge mistakes in my explanation.
One important point here:
System.gc() and System.runFinalization() does not force garbage collection or finallization, they are suggestions for the JVM to do it, but the JVM does not have to do it right now. So you cannot ensure that system resources are freed at a specific points, and that's why it is not recommended to use finalize methods for this purpose, finalize methods can even not be called ever.
If you want to be sure that your resorces are freed at a specific point, write a cleanup method and call it when needed, instead of calling System.gc() or System.runFinalization().
The process of automatically reclaiming the memory that is no longer in use is known as garbage collection. Garbage collection is a runtime component of Java which sits on top of the heap: memory area from which Java objects are created and periodically scans it for objects which are eligible to be reclaimed since there are no references to these objects in the program. In Java, life of an object is determined by the variable that references it. As long there is atleast one variable in the program accessing the object, that object will not become a candidate for garbage collection. Object class defines finalize method. The signature of finalize method is is as follows. This method is automatically called before an object is destroyed: protected void finalize() throws Throwable Following are the important considerations you must be aware of. -Java does not guarantee that any particular object will be garbage collected, but make promise to call the finalize on an object before reclaiming the memory it occupies. -There is no guarantee what so ever as to when the finalize method is called. -There is no specific order in which the finalize method will be called. -Overriding finalize method in your class does not prioritize your object for garbage collection over any other object which do not have finalize method overridden in it's class. -Any exception thrown by the finalize method causes the finalization of that object to be stopped, but is not notified to the application and that object is still considered as finalized. -finalize can run only once on the object in it's entire life cycle. -finalize method defined in Object class, as such does nothing. In order to get some meaningful thing done , you will have to override this method in the subclass. -Unlike constructors, which are chained from the subclass to superclass, finalizers are not implicitly chained. It is considered a good programming practice if you call the superclass finalizer like super.finalize() in your subclass. -By default garbage collector will not execute the finalizers of any objects left on heap when the application exists There is simply no way to force garbage collection, but you can suggest your intention of getting the object gc'ed to Java Virtual Machine. Java provide following two methods: public static void runFinalization()The above method defined in Runtime class, runs finalization methods of any objects that have not yet been finalized. This methods only suggests the JVM to run the finalize methods on the objects which have not run and in any case cannot force it. public static void gc()The above method is also defined in Runtime class, runs garbage collector and tries to reclaim memory from unused objects. For more information you can go to following links: http://www.javaworld.com/javaworld/jw-06-1998/jw-06-techniques_p.html http://www.javacoffeebreak.com/articles/thinkinginjava/abitaboutgarbagecollection.html http://trident.mcs.kent.edu/~vmartin/proj/proj.html