aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String Pool Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "String Pool" Watch "String Pool" New topic
Author

String Pool

Saith Govind
Greenhorn

Joined: Jan 24, 2003
Posts: 13
I know this topic has been discussed a lot previously on this forum, but I'm still confused whether to assume the existence of string pool for exam purposes or not. In most of the mocks they are assuming the existence of pool.
For example:
How many objects are eligible for GC just after the method returns:
public void compute(Object p){
Object a = new Object();
int x=100;
String str= "abc";
}
If we assume string pool, the answer is 1
otherwise answer is 2, since "abc" is a new string object that is created.
Please correct me if I am wrong here
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
For the exam purpose, you should not assume the existence of any String pool. You should consider String objects as normal garbage collectible objects.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Chetan M
Ranch Hand

Joined: Dec 18, 2002
Posts: 43
Hi Valentin,
Since we are talking about string pool, can you please explain me what is the difference between
String str = "abc"; & String strNew = new String("abc"); and how JVM interprets the same..
[ March 19, 2003: Message edited by: Chetan M ]

No matter how much you know today, you will have to know more tomorrow.<br /> Hakunamatata !!!
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Does the following thread help
String Pool Redux ?
PS: Could you please write in plain english? Thank you
Saith Govind
Greenhorn

Joined: Jan 24, 2003
Posts: 13
thank you valentin, so in the answer would be 2 objects are GC ed.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: String Pool
 
Similar Threads
Strings and their constant pool
Question on Strings and String pool
String objects
need help for a question
Stack Variables and GC