wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes gc question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "gc question" Watch "gc question" New topic
Author

gc question

Yosi Hendarsjah
Ranch Hand

Joined: Oct 02, 2003
Posts: 164
From Dan Chisholm's mock:

Question: When the processing of line 2 begins, how many objects of type Q that were created at line 1 are eligible for garbage collection?
Answer: 9
Is it possible that before the for loop ends, some of the object of type Q have already garbage collected so when System.gc() is invoked the number of objects of type Q left are less than 9?
Kristof Camelbeke
Ranch Hand

Joined: Nov 28, 2001
Posts: 97
In my opinion I don't think so because you can only make objects eligible for GC in these cases : 1) Nulling a Reference (q1 = null; )
2) Reassigning a ref. variable (q1 = q2);
3) Isolating a ref.
David Hadiprijanto
Ranch Hand

Joined: Sep 14, 2003
Posts: 52
Hi Yosi,
I think you are right that some of the 9 objects created in line 1 might have been garbage collected before the loop ends.
But for the sake of the exam, I think the answer is indeed 9.
The SCJP exam expects us to know when such objects are eligible for GC, not when they are actually garbage collected. The keyword here is eligible.
So, I think the wording in Dan's exam is already correct, and the answer is 9.
Just my 2 cents.
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Yosi,
If I remember correctly, the real exam uses the words "are eligible". It would be more correct to use the words "have become eligible", because that would include those that have already been garbage collected. The next version of my exam will use the more correct wording.
Does anyone object to the new version?


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
David Hadiprijanto
Ranch Hand

Joined: Sep 14, 2003
Posts: 52

It would be more correct to use the words "have become eligible", because that would include those that have already been garbage collected.

Sounds like a better ambiguity-eliminator to me.
Dan, I admire your commitment to provide high quality SCJP mock exam.
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Thank you David.
Congratulations on your 100% score on the real exam!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: gc question