Java Garbage Collection Question and Answers

9. What is gc()?
  gc() is a daemon thread.gc() method is defined in System class that is used to send request to JVM to perform garbage collection.
 
Your Name Your Email-ID
Your Answer
10. Explain the keywords native, transient, volatile, finally?
 
  • native – to use methods which written in other language.
  • transient – if u declare state of a class as transient then it's not saved in persistent area.
  • volatile – this is not optimized at the time of optimization because its value may be changed implicitly or explicitly.
  • finally – finally is used to do work prior of closing the program because of exception. It's always called be compiler either exception generated or not.
 
Your Name Your Email-ID
Your Answer
11. Does garbage collection guarantee that a perform will not run out of memory?
 
  • Garbage collection does not guarantee that a program will not run out of memory. As garbage collection is JVM dependent then it is possible for programs to use memory resources faster than they are garbage collected.
  • Moreover garbage method will be run before an object is Garbage collected, it is called by the garbage collector on an object when garbage collection determines that there no more references to the object.
  • The garbage collection is controlled, it means you cannot predict when it will happen, you thus cannot predict exactly when the finalize method will run. Once a variable is no longer referenced by anything it is available for garbage collection.
 
Your Name Your Email-ID
Your Answer
12. What is phantom memory?
 
  • Phantom memory is false memory.
  • Memory that does not exist in reality.
 
Your Name Your Email-ID
Your Answer
1234 Page 3 of 4