Monday, 24 February 2014

Java String Objects and object creation JVM

Java Object toString()  method:

This method is used to view the text format of object created in heap;

class ToStringTest{
  public static void main(String[] ags){   
    ToStringTest tst = new ToStringTest();
     System.out.println("Object value"+tst);
     System.out.println("Hash Code"+tst.hashCode());

  
  }
}
 
When JVM executing  this line (ToStringTest tst = new ToStringTest())
1)The tst reference variable created in the stack ,
 
2)By new operator object creation in heap.(memory space allocating for the object)
 
3)Assignment operator =  is used for the assign the created object to reference variable 
 
 
 
output is Object value  ToStringTest@35c41b
                                     Hash Code   32429958
32429958 is interger value for object creatd location heap


after the @ symbol. hex decimal value of object .that created in heap


No comments:

Post a Comment