• 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

StringBuffer and the "String Constant Pool"

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, I'm studying for the SCJP exam using Kathy Sierra's book. In chapter 6 she explains how Strings are immutable, and how Java deals with its "String Pool". Two questions came to my mind that aren't covered in this study guide:

1) StringBuffer objects are direct subclasses of Object, and they are muttable. How java deals with them behind the curtains?

2) Is the "String Constant Pool" a reserved segment of the heap used for Strings only?
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java deals with StringBuffers just like any other object.

There is a 'pool' of String literals that is kept alive, but don't worry about that for the test. There is some heated debate about the specifics behind the String pool. For the short answer just understand that String literals and constants that are not created with the new operator are not subject to garbage collection because there is a reference kept in the String pool due to the Strings being interned.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We've got a whole forum devoted to SCJP here. This question belongs there; I will move it for you.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the "String Constant Pool" a reserved segment of the heap used for Strings only?

Mmmh, the String objects themselves are probably just normal objects on the heap. The String pool is really more of a table of references to these objects, which in certain cases may prevent the String objects on the heap from being garbage collected, and in other cases will not.

For purposes of studying for this SCJP exam, no knowledge of the String pool (or as I call it, the String intern pool) is important to you. Questions requiring this knowledge will not be asked. (Except on some mock exams, which you can ignore - the real exam does not have questions like this.)
 
Philip Pomario
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the tips, Jim. BTW, since you touched the mock exam topic, have you ever heard of the Whizlabs SCJP 1.4 Exam Simulator? Where can I find good mock exams w/ questions not far fetched from the real exam?
 
Philip Pomario
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just passed the SCJP1.4 exam and wanted to post this appreciation note to thank everyone who helped me understand Java a little better. Without your help this personal achievement wouldn't be possible.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "String literal pool" (if that is how you perceive it) is a class-loader wide concept, that is arguably (to death) a mere abstraction. String constants are placed in the "pool" at class load time (of the class that contains the literals).

I thought we cleared this one up?
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tony, you may have noticed that new people come through here all the time. You also may have noticed that posts have dates attached to them.
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Filipe, you're welcome. Congratulations!
 
reply
    Bookmark Topic Watch Topic
  • New Topic