This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Once more CLEAN BOWLED  in Garbage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Once more CLEAN BOWLED  in Garbage collection" Watch "Once more CLEAN BOWLED  in Garbage collection" New topic
Author

Once more CLEAN BOWLED in Garbage collection

MONZY THARIAN
Ranch Hand

Joined: Feb 21, 2001
Posts: 63
It seems i am getting CLEAN BOWLED in Garbage collection questions.
37. Which of the following statements about Java's garbage collection are true?
a) The garbage collector can be invoked explicitly using a Runtime object.
b) The finalize method is always called before an object is garbage collected.
c) Any class that includes a finalize method should invoke its superclass' finalize method.
d) Garbage collection behavior is very predictable.
According to me the correct answer is B.
Can any one give me the correct answer.
Monzy

Think Big . So shall you become big.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
My answer would be both (b) & (c) .... (b) is obvious
(c) is because Finalizers are not chained implicitly like constructors. Therefore, a super.finalize() call is essential in any overridden finalize() method.
This is not related to this question..but did you know that finalize can be overloaded? ...It would be definitely worthwhile to write a small program and find out a specific case in which this is possible.

Shyam
[This message has been edited by Shyamsundar Gururaj (edited November 23, 2001).]
MONZY THARIAN
Ranch Hand

Joined: Feb 21, 2001
Posts: 63
Shyam,
This question is from MindQ's mock exam. what i feel is that answer they have got is wrong. Even (b) and (c) is wrong.
I am aware of overloading fundas of finalize() method , but i do not feel in SJCP exams such qustions with non relevant answers will be asked. Can some certified guys give more suggestions.
Monzy :-(
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Originally posted by MONZY THARIAN:
Shyam,
This question is from MindQ's mock exam. what i feel is that answer they have got is wrong. Even (b) and (c) is wrong.
I am aware of overloading fundas of finalize() method , but i do not feel in SJCP exams such qustions with non relevant answers will be asked. Can some certified guys give more suggestions.
Monzy :-(


Monzy :-(
Monzy...I am certified too
Trust me..the questions on the exam will be clearly worded and absolutely unequivocal.
As far as the above question goes...the reason why I specified (b) and (c) only ...leaving out (a) is because ... although Java provides facilities to invoke GC explicitly ( System.gc() and System.run.Finalization() ), it is a request and not a demand. They need not be necessarily honored by the JVM.
Option (D) is ruled out for obvious reasons...GC is at the mercy of the beast

Pardon me if I have posted material redundant to you. But it might be useful for others.
Hope this helps
Shyam

[This message has been edited by Shyamsundar Gururaj (edited November 23, 2001).]
MONZY THARIAN
Ranch Hand

Joined: Feb 21, 2001
Posts: 63
Shyam a million thanks to u for helping me understand certain topic. I wrote ( i am aware in my earlier post) because just to make it clear.
Otherwise i am very much grateful to u for spending your valuable time for me
Cheers buddy :-)
Monzy
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
c is wrong. If the class extends from Object: finalize method in Object does nothing, so why invoking it?


SCJP2. Please Indent your code using UBB Code
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Jose, I don't want to be picky but there is a difference between "should" and "must". "Should" lets the decision open to the programmer, "must" doesn't. What do you think ?
I hate being picky on wording issues, but sometimes it's worth it.

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Hi Val

"Should" lets the decision open to the programmer, "must" doesn't.

Do you mean in the exam we have to pay attection to this difference between should and must?
Is this difference important for all the questions in the exam?
I don't think so, because I know the exam is properly worded even regarding non English mother-tongue speakers. So in the exam I don't expect subtlety meaning issues.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
you're right SCJP exam should not be an english grammar lesson...
But sometimes it helps to be picky on wording

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
Caroline Bogart
Greenhorn

Joined: Nov 21, 2001
Posts: 24
<CODE>
a) The garbage collector can be invoked explicitly using a Runtime object.
</CODE>
I would be picky about this wording and I think it's ambiguous. Please tell me what you think of my argument.
Invoking the garbage collector is a discrete action. Whether that gc actually does anything is a separate action.
There is no difference between requesting that the gc do its job and invoking the gc. Once the gc examines the situation, it might or might not do its job. But it must be invoked before it can make that decision. Therefore (a) is true, the garbage collector can be invoked explicitly using System or Runtime.
Once invoked, it may continue or not continue.
Please tell me what you think.
Ms. Literal,
Caroline

[This message has been edited by Caroline Bogart (edited November 23, 2001).]


I love JavaRanch!
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Caroline,
I agree with you. In the context of this question choice (a) would also be an answer. But the wording is definitely ambiguous.

------------------
Shyam
Sun Certified Programmer for the Java�2 Platform
Caroline Bogart
Greenhorn

Joined: Nov 21, 2001
Posts: 24
What would the exam interpret (a) to be? Right (because I'm right) or wrong (because they're going for "You can't make the gc do anything")?

Originally posted by Shyamsundar Gururaj:
Caroline,
I agree with you. In the context of this question choice (a) would also be an answer. But the wording is definitely ambiguous.


------------------
I love JavaRanch!
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
The questions in the actual exam will be refreshingly unambiguous.
Mike Cunningham
Ranch Hand

Joined: Nov 14, 2000
Posts: 129
In a Java Cert. book that was recently released (Mike Meyer's Passport) it says that your program cannot explicitly reclaim unused memory by invoking System.gc(). This is because the JVM treats the System.gc() method as a request that it may honor or ignore.
By the way, what's the Ranch etiquitte on quoting from other books such as the variety of Certification books available?
- Mike
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Mike Cunningham:
By the way, what's the Ranch etiquitte on quoting from other books such as the variety of Certification books available?
Quote from the Passport book as much as possible and treat it as the authoritative reference after the JLS. It will make you very popular with the local bartenders
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Once more CLEAN BOWLED in Garbage collection