Number of string objects created in program : <pre><code>String s1="abc";                  //line 1
String s2 = new String ("abc");   //line 2
String s3 = "abc";                //line 3
String s4 = s1+s2+s3;             //line 4
</code></pre>

<p>I need to know how many objects are created in total.(Heap and SCP area). </p>

<p>At line 1, one object "abc" in SCP</p>

<p>At line 2, one object "abc" in heap</p>

<p>At line 3, s3 points already existing object "abc" in SCP</p>

<p>Till this point there are 2 objects. I am not able to figure out exactly how many after line 4. Is there a way to find out how many objects are created in these cases using a java program?</p>
