Hi
java gurus,
As explained in the 'awesome' K&B book (page 359):
".... JVM sets aside a special area of memory called the '
string constant pool'. When
the compiler encounters a string literal, it checks the pool if an identical string
exists....."
I have two doubts:
a) So in the following piece of code, is the "java" object is created in the pool twice??
As I understand, jvm creates this string in the pool then returns it's reference to 's'. but after
line#2 executes, reference to "java" is lost ...so after line#3 whether compiler will
create a new "java" in the pool and returns its reference or it will use the first one only?
If it uses the first one then how it gets to it as after line#2, the reference is kinda lost
in open space?
<code>
1. String s = "java";
2. String s = "language";
3. String s1 = "java";
</code>
b) Does the garbage collection also runs on this 'string constant pool' or what?
Thanks,
Deep