public class Garbage
{
int a=0;
public void add()
{
int c=10+20;
System.out.println(c);
System.out.println(a);
}
public static void main(String args[])
{
Garbage obj=new Garbage();
System.gc();
System.out.println("Garbage Collected");
obj.add();
}
}
Above is a code in java used for garbage collection. object
obj has been created for the class Garbage and system.gc
method is called. Then using that object add method is
called.System.gc method if called the obj should be garbage
collected?

Answer Posted / bhudeep

Java provides us one method System.gc()to call garbage
collection forcefully.But by calling System.gc() will not
ensure you that the object will be garbage collected.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between arraylist and hashset in java?

520


Why java is secure? Explain.

601


how to convert Java project into Maven ?

588


Differentiate between vector and array list.

638


Difference between arraylist and vector.

595






What is the difference between overriding & overloading?

567


What is your platform?s default character encoding and how to know this?

1754


What are variable arguments or varargs?

573


What is a parameter in a function?

530


What is difference between array and arraylist in java?

466


Does constructor return any value?

585


What is meant by main method?

585


What is the difference between menuitem and checkboxmenu item?

788


how a programmer confirms that the data submitted has been succesfully inserted into the database(either oracle or my sql).. How a programmer confirm if there is any problem with the program he wrote for insertion... ANS:--- >executeupdate method is having boolean return type, if anything goes wrong in data insertion or data updation, it would return false. otherwise, if it successfully inserts data into the database, it would return true NOW HOW TO I CHECK IN MY DURING EXECUTION WHETHER IT RETURNS TRUE OR FALSE... WELL IT WILL DISPLAY ANY MESSAGE OR NOT

1856


Which java collection does not allow null?

717