• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

suggest JVM to run garbage collection ??

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...So, going back to the original question.
options A and B are the correct options
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic