wood burning stoves 2.0
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

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Runtime constant pool" Watch "Runtime constant pool" New topic

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
shweta agarwal

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.
I agree. Here's the link: http://aspose.com/file-tools
subject: Runtime constant pool
It's not a secret anymore!