It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes 1 more Q from PGJC Mock Exam 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 "1 more Q from PGJC Mock Exam" Watch "1 more Q from PGJC Mock Exam" New topic
Author

1 more Q from PGJC Mock Exam

Sahul Yasin
Ranch Hand

Joined: Aug 28, 2002
Posts: 48
Select two guaranteed behaviour of GC and Finalization Mechanism.
1. An object is deleted as soon as there are no more references that
denote the object.
2. The finalize() method will eventually be called on every object
3. The finalize() method will never be called more than once on an object
4. An object will not be garbage collected as long as it is possible for a
live thread to access it through a reference
5. The garbage collector will use a mark and sweep algorithm
hi, i think , the answers 1,2,3,4 are correct.But they said only 2 are correct answers ..how ?

[ January 15, 2004: Message edited by: Mohamed Yasin ]

Regards,<br />Yasin<br />SCJP,SCWCD,SCBCD
dennis zined
Ranch Hand

Joined: Mar 07, 2003
Posts: 330
Hi Mohamed.
Different vendors may implement garbage collection differently so there's no telling how soon an object will immediately be deleted when there are no more references that denote the object. Also there are different algorithms for a garbage collection not only mark-sweep. What is guaranteed however is that the finalize() method will eventually be called on an object before it is garbage collected but only happens once. So if you've coded, for example, logic in the finalize method that makes the object uneligible for garbage collection, the next time GC runs and if the object is eligible for garbage collection it will not call finalize() the second time around. So I think nos. 2, 3 are the right answers.


SCJP 1.4<br />SCWCD 1.4
Don Wood
Ranch Hand

Joined: Dec 05, 2003
Posts: 65
Jim,
Answer 2 is not right. Objects that are still referenced when the application ends are not garbage collected. Also, it is possible that objects that are eligible for garbage collection are not collected because the application ended.
I believe the correct answers are 3 and 4 although I don't like the wording of 4. The phrase "...as long as it is possible for a live thread to access it through a reference" is awkward at best. Changing this to, "...as long as a live thread has access to it through a reference" would improve things.
dennis zined
Ranch Hand

Joined: Mar 07, 2003
Posts: 330
Don,
No. 2 has the words "will eventually be called on every object". So I'm assuming that event will come when it has no more references that points to it.
I dont like the wording on 4 either so i'm not electing it to be the right answer.
Don Wood
Ranch Hand

Joined: Dec 05, 2003
Posts: 65
Dennis,

2. The finalize() method will eventually be called on every object

I guess we just read 2 differently. I don't see how we can correctly say that every object will have its finalize method called when some objects are still referenced when the application ends. It seems to me that the term "every object" is all inclusive so I can't see that every object will have its finalize method called.

So I'm assuming that event will come when it has no more references that points to it.

But what if there is no time when some object "has no more references that point to it"?
PS It seems I addressed my first response some mysterious cowpoke named Jim who has not weighed in on this question. It was dinner time so I guess I was weak from lack of grub. Beans, again.
dennis zined
Ranch Hand

Joined: Mar 07, 2003
Posts: 330
Good point Don.
Yeah, I was wondering who Jim was.
 
GeeCON Prague 2014
 
subject: 1 more Q from PGJC Mock Exam