There are many ways:
By nulling the reference
By assigning a reference to another
By anonymous object etc.
Java Garbage Collection Scenario
1) By nulling a reference:
Employee e=new Employee();
e=null;
2) By assigning a reference to another:
Employee e1=new Employee();
Employee e2=new Employee();
e1=e2;//now the first object referred by e1 is available for garbage collection
3) By anonymous object:
new Employee();