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 - Boone's Mock Q 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 "Garbage Collection - Boone Watch "Garbage Collection - Boone New topic
Author

Garbage Collection - Boone's Mock Q

Monisha Talwar
Ranch Hand

Joined: Feb 11, 2003
Posts: 102
Question 65: Which statements about garbage collection are true?
Select all valid answers.
(a)You can directly free the memory allocated by an object.
(b)You can directly run the garbage collector whenever you want to and it will be schedule in due time..
(c)The garbage collector informs your object when it is about to be garbage collected.
(d)The garbage collector reclaims an object�s memory as soon as it becomes a candidate for garbage collection.
(e)The garbage collector runs in low-memory situations.
Ans given : b, c and e
Question 65: b, c, e. You cannot directly free the memory allocated by an object, though you can set an object reference to null. Also, The garbage collector only runs in low-memory situations, and so does not always reclaim an object�s memory as soon as it becomes a candidate for garbage collection.
I agree with C and E but what about B?
The exact wording of B seems ambiguos, because you can suggest GC and it may run eventually, or may not at all! The wording "can run" seems to make it false!
Am I right?


Hey! It compiles! Ship it!
Carl Sampson
Greenhorn

Joined: Apr 09, 2003
Posts: 22
I would agree that B is false. Unless they consider suggesting the garbage collector run as directly running the garbage collector. Garbage collection may happen in due time, but you can't directly make the vm garbage collect.
B Mampilli
Ranch Hand

Joined: Aug 05, 2002
Posts: 61
hi
I feel that B is true because when the garbage collector is run using the command, the system schedules it for garbage collection but the time when it is be executed is not known.
So, by the ststement "you can run it whenever u want" the meaning is " run the command to schedule it for gc"...
just a thought...


Boney
SCJP, SCWCD
Charles Leung
Greenhorn

Joined: Mar 02, 2003
Posts: 16
After careful reading, I think option B is correct. When you called System.gc(), you know it will run in future. Although the exact time is unknown, you may say it is "scheduled".
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Charles Leung:
After careful reading, I think option B is correct. When you called System.gc(), you know it will run in future. Although the exact time is unknown, you may say it is "scheduled".
I disagree. It is not necessarily scheduled, and you are given no guarantees whatsoever that it will actually run before termination of the program. The only garbage collection guarantee the Java language gives you is that the garbage collector will run before an OutOfMemoryError is thrown.
Option B, IMHO, is blatantly incorrect. You cannot "directly run the garbage collector whenever you want to". The best you can do is "suggest that the Java virtual machine expend effort toward recycling unused objects".
- Peter
Neeraj Kumar
Greenhorn

Joined: Apr 10, 2003
Posts: 6
The wording of the option B is ambiguous as it attempts to join 2 totally contradictory statements with a conjunction.
The first part
You can directly run the garbage collector whenever you want to

attempts to suggest that you can invoke GC any time.. which FALSE. We can only "request" JVM to "run" GC.
While the second part
it will be schedule in due time

conveys the right and is TRUE.
So, in totality, it seems to me, that the answer is FALSE [ after all TRUE AND FALSE will give FALSE].
We can only hope such ambiguous statements do not appear in the exam
Charles Leung
Greenhorn

Joined: Mar 02, 2003
Posts: 16
Peter & Neeraj, I agree
thanks you
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Before deciding whether the second part is true, I wonder what exactly does it mean? Do you have any guarantees that the garbage collector is "scheduled" as such (apart from the concept of general thread scheduling, which is probably not meant here)? What exactly is "due time"? After all, the only real guarantee you have is that the garbage collector will run (not: be scheduled) before an OutOfMemoryError is thrown.
Even taken in isolation the second half seems very ambiguous and ill-defined. It can be given a valid meaning, as you do (and there's nothing wrong with that!), but it can easily be interpreted in ways that are not valid at all. At best, we can assign it an UNDEFINED truth value or throw an AmbiguousQuestionException
If my experience is anything to go by, the exam is much more carefully worded.
- Peter
[ April 10, 2003: Message edited by: Peter den Haan ]
Lih Chang
Greenhorn

Joined: Mar 21, 2003
Posts: 19
(c)The garbage collector informs your object when it is about to be garbage collected.

Can someone explain what does (c) exactly mean? Thanks.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by Lih Wang:

Can someone explain what does (c) exactly mean? Thanks.

Basically, that means that the garbage collector will give your object some warning that it is about to be garbage collected. In this case, that warning takes the form of invoking the object's finalize method. That method gives the object a chance to "clean up" anything that it needs to before it is obliterated.
I hope that helps,
Corey


SCJP Tipline, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection - Boone's Mock Q