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
posted
0
For the exam purpose, you should not assume the existence of any String pool. You should consider String objects as normal garbage collectible objects.
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
posted
0
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
posted
0
thank you valentin, so in the answer would be 2 objects are GC ed.