All code in my posts, unless a source is explicitly mentioned, is my own.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
All code in my posts, unless a source is explicitly mentioned, is my own.
Ankit Garg wrote:"Punit" is not created because the compiler wipes that statement out. The compiler will remove the declaration of the final string and replace the value of the final constant with the actual value. So if you write this
final String s = "Punit";
String s1 = s + "Singh";
Then the compiler would make it
String s1 = "PunitSingh";
Punit (24 bytes)
PunitSoto (24 bytes)
Ruben (24 bytes)
PunitSingh (24 bytes)
PunitSoto Ruben (24 bytes)
SCJP 6
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankit Garg wrote:The program that you gave punit will look like this after compilation
SCJP 6
SCJP 6
All code in my posts, unless a source is explicitly mentioned, is my own.
Ruben Soto wrote:Yes, I think the same would happen if you had something like:
final String s = "Text";
String s1 = s; // "Text" will be created
Is it possible that this is too advanced for the purposes of the exam?
Bert mentioned that there won't be questions about Strings in the context of GC, but he didn't say anything about number of objects created questions.
What to answer if the exam asks how many Strings will be created in the StringTest2 example with a final String?
SCJP 6
Java hobbyist.
All code in my posts, unless a source is explicitly mentioned, is my own.
Punit Singh wrote:Excellent Stuff Ruben, I did all the things you said.
I ran this program:
Thanks
Sunil (SCJP 5)
sunil langeh wrote:
Hi puneet, I am little confused with line 2 (String s0 = s + "Singh"), As i am thinking there are 2 objects
1. "Singh"
2. s +"Singh" = Punitsingh which is assigning to String S0
Please clear it to me..
SCJP 6
Thanks
Sunil (SCJP 5)
String buffers are used by the compiler to implement the binary string concatenation operator +. For example, the code:
x = "a" + 4 + "c"
is compiled to the equivalent of:
x = new StringBuffer().append("a").append(4).append("c")
.toString()
Pavel Cherkashin - <br />SCJP, SCWCD, SCDJWS, SCBCD, SCEA, ...<br />www.linkedin.com/in/pcherkas
Java hobbyist.
Pavel Cherkashin wrote:one more fly in the ointment
did You forget about java.lang.StringBuffer
String buffers are used by the compiler to implement the binary string concatenation operator +. For example, the code:
x = "a" + 4 + "c"
is compiled to the equivalent of:
x = new StringBuffer().append("a").append(4).append("c")
.toString()
SCJP 6
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
|