• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String Pool

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the exam purpose, you should not assume the existence of any String pool. You should consider String objects as normal garbage collectible objects.
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the following thread help
String Pool Redux ?
PS: Could you please write in plain english? Thank you
 
Saith Govind
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you valentin, so in the answer would be 2 objects are GC ed.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic