Wednesday, May 2, 2012

memory management in java strings?

Hi i am new to java programming,i created strings object as given below

Case 1:

  String s1="mystring";//Address location is 1000
String s1="yourstring";
String s2="mystring";

Case 2:

  String s1=new String("mystring");//Address location is 1000
String s1=new String("yourstring");
String s2=new String("mystring");

with ref

as per my knowledge these string are stored in string constant pool for Case1 with specific memory locations,similarly in case2 objects are created in Heap does these memory will mange and freed if we assign same or different strings to String objects.


No comments:

Post a Comment