Hi Teja
Garbage Collection is the responsibility of JVM. It uses algorithms. Garbage collection is only about memory. You dont know when JVM performs garbage collection whenever processor is free garbage is performed.
example is.
public class ABC
{
public static void prt(
String s)
{
System.out.println(s);
}
ABC()
{
this.prt("using this"); //it display 2nd
}
public static void main(String[] args)
{
prt("hello 2"); //first this display
ABC a=new ABC(); //constructor call
ABC b=new ABC();
ABC c=new ABC();
ABC d=new ABC();
System.gc();
System.runFinalization();
}
}
finalize is also used for observing the process of garbage collection.
you should never call finalize().
moreover
www.bruceeckel.com study chapter 04
------------------