aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes  GC Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark " GC Doubt" Watch " GC Doubt" New topic
Author

GC Doubt

Ritu Kapoor
Ranch Hand

Joined: Oct 03, 2004
Posts: 102
Please have a look at the following code:



Answer: a,b,c

Well, Should not it be b(Sceptical about b),c.

Please clarify my doubt.

Thanks
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
I am also doubting a.Also b seems to be not in answer.

a is false as you can make a request to GCor not can make a explicit call to the Garbage Collector.
b is false as if suppose before a object is in the way for GCed an could not be collected due to some live reference then second time the finalize will not be called at all.
[ January 18, 2007: Message edited by: Sanjeev Singh ]

~Sanjeev Singh<br />SCJP 1.5
Andy Morris
Ranch Hand

Joined: May 30, 2004
Posts: 78
Well I think it probably depends how you read the question.

The finalise is always called before an object is garbage collected - I'd say that is true. It's just not always immediately before (i.e called the first time it was eligible), but it is always before. I'd doubt in the exam they'd give you a question that ambigious.

And again for invoking the gc using a runtime object, yes you can invoke it, but it doesn't say that it will do anything.
Mandeep kaur
Greenhorn

Joined: Aug 13, 2006
Posts: 8
ONLY B IS RIGHT
---WHENEVER A OBJECT IS ABOUT TO BE GARBAGE COLLECTED,BEFORETHIS OPERATION FINALIZER IS ALWAYS RUN.'
--YOU CAN ONLY REQUEST gARBAGE COLECTOR,YOU CANT BE SURE IT WILL RUN OR NOT
victor kamat
Ranch Hand

Joined: Jan 10, 2007
Posts: 247
Comments
1. a. is correct because you can explicitly call gc from a Runtime object
( I wrote code to so). Doesn't mean it will run.
2. b. is incorrect because finalize can be called on an object only once
(see K&B pg 253)
3. c and d are incorrect

So answer is a.

Where did you get this question from.
victor kamat
Ranch Hand

Joined: Jan 10, 2007
Posts: 247
See K&B ques 10 pg 263.

By "explicitly calling" the gc I understand as in the code below.
Am I mistaken ? The code compiles.

Runtime rt = Runtime.getRuntime();
rt.gc();
victor kamat
Ranch Hand

Joined: Jan 10, 2007
Posts: 247
This question is taken MindQ's Sun Certified Java Programmer Practice Test
Updated 4/7/99.

The answers that are given are a. b and c.

I disagree with b & c.

I would like one of our gurus to please answer this one.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GC Doubt