File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes garbage collection question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "garbage collection question" Watch "garbage collection question" New topic
Author

garbage collection question

sarim raza
Ranch Hand

Joined: Nov 02, 2000
Posts: 232
CAN SOMEONE PLEASE EXPLAIN WHAT SHOULD BE THE CORRECT ANSWERS TO THE FOLLOWING THANKS!
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
Harpal Singh
Ranch Hand

Joined: Oct 10, 2000
Posts: 229
a) The garbage collector can be invoked explicitly using a Runtime object.
above is a contradictory statement allthough you can call system.gc() but there is no gurantee that Garbage collector will be called....
b) The finalize method is always called before an object is garbage collected.
b) is true
c) Any class that includes a finalize method should invoke its superclass' finalize method.
c is false
d) Garbage collection behavior is very predictable
d is very much false ......GC is unpredictable...it is JVM dependent....
Thanks ,
Harpal
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Sorry Harpal ... I need to quibble
a.) True. You can explicitly call the garbage collector; however, it won't necessarily run.
b.) agree, it's true
c.) True. While you don't have to call the superclasses finalize method; it is considered good programming practice, therefore you should call it.

... finalize invokes super.finalize ... Train yourself so that you always do so in any finalize method you write. If you don't invoke super.finalize, you may correctly finalize your own part of the object, but the superclass's part will not get finalized.
Java Programming Language: Second Edition p 49

d.) agree, it's false
------------------
Jane
The cure for boredom is curiosity.
There is no cure for curiousity.
-- Dorothy Parker
[This message has been edited by Jane Griscti (edited November 02, 2000).]
[This message has been edited by Jane Griscti (edited November 02, 2000).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 2547
b) The finalize method is always called before an object is garbage collected.
This looks true but actually may not be!
When an object is garbage collected the finalize method will be called. But if in finalize() we ressuruct the object what will happen? JLS says that finalize() is called ONLY ONCE during the life time of the object. Does it mean :
1. The GC will never try to collect this object again? (Implication is this object will live for ever!)
2. The GC will try to collect it but will not call the finalize() again. This mean, you just can't resurruct an object after one try! Ie. you actully can't save any object permanently!

-Paul.

------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
 
 
subject: garbage collection question
 
Threads others viewed
MindQ (Q.37) GC
garbage collection question.
garbage collection
GC question on MindQ no. 37
mindQ no.37
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture