File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

suggest JVM to run garbage collection ??

 
Raju Sri
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
C. Magmanum
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
C. Magmanum
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5093
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
 
C. Magmanum
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...So, going back to the original question.
options A and B are the correct options
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic