Garbage Collection in Java

This program performs garbage collection. Free memory in java virtual machine is printed and then garbage collection is done using gc method of RunTime class, freeMemory method returns amount of free memory in jvm, getRunTime method is used to get reference of current RunTime object.
import java.util.*;
 
class GarbageCollection
{
   public static void main(String s[]) throws Exception
   {
      Runtime rs =  Runtime.getRuntime();
      System.out.println("Free memory in jvm (Java Virtual Machine) before Garbage Collection = "+rs.freeMemory());
      rs.gc();
      System.out.println("Free memory in jvm (Java Virtual Machine) after Garbage Collection = "+rs.freeMemory());
   }
}