This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes about GC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "about GC" Watch "about GC" New topic

about GC

Sundar Murthi
Ranch Hand

Joined: Mar 05, 2004
Posts: 209

I found following one in mindQ mock exam??

How many objects are eligible for garbage collection once the execution has reached at label LineA.

The Ans Given as : 1

But regarding to string literals no one is garbage collectable.
so my ans is 0

is it ok???

kinly show some light on this.

tx in adv
Shilpi M Ag
Ranch Hand

Joined: May 07, 2004
Posts: 40

Yes I think you are right... We had a similar discussion some days back -

And the conclusion everyone found was that literals dont get garbage collected...Altho I was myself not very well convinced of the same... However I had accepted it.. But now this 2nd case (urs) has again made me think, if literals also get garbage collected!

Lets wait and see what everyone else has to say abt it!
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Literals are stored in the String pool which is not subject to regular garbage collection.

Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
The good new is, you're right. The answer should be 0. There are no objects eligible for Garbage Collection in that example. String literals are not eligible for garbage collection and, in that example, that's all you have.

The better new is that this is not on the SCJP exam. You'll have to answer questions about garbage collection, but you won't have to answer questions about Sting literals in terms of garbage collection.

SCJP Tipline, etc.
I agree. Here's the link:
subject: about GC
jQuery in Action, 3rd edition