"Eppur si muove!"
Hello everyone!
I just want to clarify for everyone what's on the exam and what's NOT!
Understanding String immutability IS on the exam, and it's big!
Understanding when (non-String), objects are eligible for GC IS on the exam, and it's big and complicated!!!
However, because the String constant pool is a bit vague, the exam WILL NOT ask you to know when String objects are eligible for the GC.
So I'd recommend that you start this thread all over again using objects of a type other than String - otherwise this whole thread is confusing and misleading!
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
"Eppur si muove!"
SCJP SCWCD SCBCD <br /> <br />what u do in life echos in eternity!
Originally posted by Vijayakeerthy Parsuvanath:
But how many String objects will be lost in your code ?
Now tell me in the following code how many String objects will be created before the println statement in the following code
"Eppur si muove!"
I think it should be 5 because the line String s2 = new String("xyz");
creates two objects one in the normal (nonpool) memory and the other
in the pool memory (i.e. for the literal "xyz").
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
"Eppur si muove!"
SCJP SCWCD SCBCD <br /> <br />what u do in life echos in eternity!
String objects created as follows. "winter","winter"(lost),
"winter summer","fall"(lost),"winter fall(lost),"winter summer winter(lost),
"winter"(lost),"winter winter" .
String s1 = "winter"; //1
String s2 = s1 + "summer"; //2
s1.concat("fall"); //3
s2.concat(s1); //4
s1 +="winter"; //5
System.out.println(s1 + " " + s2);//6
Originally posted by Gian Franco Casula:
...(before and not including the println statement)
"Eppur si muove!"
SCJP SCWCD SCBCD <br /> <br />what u do in life echos in eternity!
SCJP 1.4
"Eppur si muove!"
SCJP 1.4