GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Runtime constant pool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Runtime constant pool" Watch "Runtime constant pool" New topic
Author

Runtime constant pool

Madan, Gopal
Ranch Hand

Joined: Aug 13, 2001
Posts: 86
The pool, with reference to String literals:
Is this pool, created/maintained by JVM
- on a per class basis?
- on a package basis? or
- for everything per JVM session
In JLS, in the section "3.10.5 String Literals", the code example output proves that a string literal has a unique reference from anywhere - class, same/different class(s), same/different package(s).
I guess, my question is :
Can i have the string literal "Hello" in any 2 different places and prove that they are not equal. I am trying to compare and contrast the code example in the section "3.10.5 String Literals" of JLS.
Thanks for any help
Madan
shweta agarwal
Greenhorn

Joined: Aug 30, 2001
Posts: 10
check this code out:
class StringTest{
public static void main(String s[]){
String a=" hello";
String b=" hello";
if (a.equals(b))
System.out.println(" Same contents");
else System.out.println(" Different contents");
if (a==b)
System.out.println(" same object");
else System.out.println(" Different objects");
}
i think this will solve ur problem since if u declare the string b in the above manner then it will be the same object that will be referred to.but if u declare b as
String b=new Sring(" hello");
then u get different results.
 
GeeCON Prague 2014
 
subject: Runtime constant pool