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 suggest JVM to run garbage collection ?? 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 "suggest JVM to run garbage collection ??" Watch "suggest JVM to run garbage collection ??" New topic
Author

suggest JVM to run garbage collection ??

Raju Sri
Ranch Hand

Joined: Mar 10, 2004
Posts: 108
Hi,
Question Which statements are true ?
A. Calling Runtime.gc() will suggest JVM to run garbage collection.
B. Calling System.gc() will suggest JVM to run garbage collection.
C. You cannot suggest JVM to run garbage collection.
D. Only option B is true.
If the above kind of question comes then how to answer ? .
As per my thinking option D is correct . Usually looking at the question we will think A and B options are true. Calling gc() method on Runtime need object instance as it is not static method like System.gc().
Pls clarify whether we have to conside Runtime.gc() as correct statement or not .
Regards
Raju


SCJP 1.4<br />SCWCD 1.4<br />SCBCD 1.3<br />SCDJWS 1.4
C. Magmanum
Ranch Hand

Joined: Apr 03, 2004
Posts: 35
Option A and B are right. U can suggest garbage collection but u can't force it.
the methods in A and B do not force garbage collection, they are merely encouraging the JVM to start garbage collection.
Raju Sri
Ranch Hand

Joined: Mar 10, 2004
Posts: 108
Hi Crusty ,
I think you didn't get my point. I know answer A and B are correct . But my question is how can we sure about Runtime.gc() is correct ?. To me if it is Runtime.getRuntime().gc() then it is correct becuase gc() method in Runtime is not static.
So I am just asking in exam if the statements says Runtime.gc() do we need to consider that as Runtime.getRuntime().gc() automatically ?

Regards
Raju
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Raju,
It is a poorly worded question and I doubt you run into such a dilemma on the exam. As it is now, option A would not compile, unless, of course, you had a variable named Runtime.
Corey


SCJP Tipline, etc.
C. Magmanum
Ranch Hand

Joined: Apr 03, 2004
Posts: 35
I think u should read the java API, but to save u time, here is a quote from the documentation

public class Runtime extends Object
Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method.
An application cannot create its own instance of this class.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
and therefore Runtime.getRunTime().gc(); would be incorrect too. It would need to be getRunTime().gc();
Of course it's easier to just use gc();


42
C. Magmanum
Ranch Hand

Joined: Apr 03, 2004
Posts: 35
...So, going back to the original question.
options A and B are the correct options
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: suggest JVM to run garbage collection ??