This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String Object and String literall Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String Object and String literall" Watch "String Object and String literall" New topic
Author

String Object and String literall

mamidi venkat
Ranch Hand

Joined: Jul 03, 2007
Posts: 63
Hi All

I have one doubt regarding the String object and String literals .where the String object and String literals are stored. In String pool i.e String table or In Heap.Both String object and String literal are eligible for the garbage collection or not ??
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585
Hi,

When you say :



This goes to the String constant pool.

And when you say :



This goes to the heap, as well as to the pool.

Best of luck ...


Vassili ...
SCJP 5.0, SCWCD 1.4, SCJA 1.0
Thiru Mu
Greenhorn

Joined: Aug 30, 2007
Posts: 23
Hi,

I dont think String objects are stored in the pool. It is stored only in heap.

Also String objects are eligible for garbage collection not the litterls..please correct me if i am wrong..
[ September 04, 2007: Message edited by: Thiru Mu ]
Collins Mbianda
Ranch Hand

Joined: Aug 11, 2007
Posts: 259
Hi Thiru Mu !!!
You are rigth.

Find a very good article on String litterals here:
Strings, Literally


SCJP 5.0 | SCWCD 1.4
Gitesh Ramchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 274
Anything that is object and "only object" will be eligible for Garbage collection.
Collins Mbianda
Ranch Hand

Joined: Aug 11, 2007
Posts: 259
Originally posted by Gitesh Ramchandani:
Anything that is object and "only object" will be eligible for Garbage collection.


No !!!
String literals are objects.
Unlike most objects,they always have a reference to them from the String Literal Pool. That means that they always have a reference to them and are, therefore, not eligible for garbage collection.

Strings, Literally
 
 
subject: String Object and String literall
 
Similar Threads
String
counting String objects
Number Of Strings
"Strings"
Problem with String and StringXxx objects