SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Sharad Golu wrote:Please confirm me, that how many string objects gets created totally for below code -
As per my understanding there will be two options:-
a) str, a,b,ab,c,abc (i.e. 6)
b) str, a,b,c,abc (i.e. 5)
Please confirm which one is correct and also let me know if i missed any other object.
“Everything should be as simple as it is, but not simpler.” Albert Einstein
“Everything should be as simple as it is, but not simpler.” Albert Einstein
Duc Vo wrote:(1) There is no object got created at compile time, it just compiles java code to bytecode.
(2) The three object "a", "b", and "c" should be created at the class loading time, i.e. when JVM loads the class
(3) There should be no interim "ab" object in the modern JVMs, they should use some other less expensive way to concatenate the string with the + operator. So it should depend on specific JVM implementation.
My opinion is still the same: there will be only 4 string objects created.
“Everything should be as simple as it is, but not simpler.” Albert Einstein
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankit Garg wrote:
This code will create 3 objects i.e. "ab", "c" and "abc"...
Harshana Dias wrote:
Ankit Garg wrote:
This code will create 3 objects i.e. "ab", "c" and "abc"...
Based on the earlier explanation its two right? "ab" and "abc"
Harshana Dias wrote:
Ankit Garg wrote:
This code will create 3 objects i.e. "ab", "c" and "abc"...
Based on the earlier explanation its two right? "ab" and "abc"
Don't get me started about those stupid light bulbs. |