Java Garbage Collection Question and Answers

5. What is the purpose of finalization?
  The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.
 
Your Name Your Email-ID
Your Answer
6. What do you know about the garbage collector?
 
  • In Java, memory management is done automatically by JVM.
  • A programmer is free of this responsibility of handling memory.
  • A garbage collector is a part of JVM responsible for removing objects from heap, which is no longer in use.
  • The garbage collector typically runs in a background thread, periodically scanning the heap, identifying garbage objects, and releasing the memory they occupy so that the memory is a available for future objects.
 
Your Name Your Email-ID
Your Answer
7. What is the difference between serial and throughput garbage collector?
 
  • The throughput garbage collector uses a parallel version of the young generation collector and is meant to be used with applications that have medium to large data sets.
  • On the other hand, the serial collector is usually adequate for most small applications.
 
Your Name Your Email-ID
Your Answer
8. What is final, finalize() and finally?
 
  • final: final keyword can be used for class, method and variables.
  • A final class cannot be sub classed and it prevents other programmers from sub classing a secure class to invoke insecure methods.
  • A final method can't be overridden.
  • A final variable can't change from its initialized value.
  • finalize() – finalize() method is used just before an object is destroyed and can be called prior to garbage collection.
  • finally() - a key word used in exception handling, creates a block of code that will be executed after a try/catch block. The finally block will execute whether or not an exception is thrown.
 
Your Name Your Email-ID
Your Answer
1234 Page 2 of 4