1. Why do we need Garbage collection in Java?
Garbage collection is a process
that takes care of all the unused objects and discards them from the
JVM. The resources used by those objects are
reclaimed.
2. Can you enforce Garbage
collection in Java?
No. You can enforce Garbage
collection in java, however we can give a hint to the JVM through some
commands to start thinking about garbage collection, but JVM may or may
not do it. System.gc() is one way to provide that
hint.
3. Describe the Garbage Collection
process in Java ?
The JVM spec mandates automatic
garbage collection outside of the programmers control. The System.gc()
or Runtime.gc() is merely a suggestion to the JVM to run the GC process
but is NOT guaranteed
4. What is the difference between
an Interface and an Abstract class?
An abstract class can have
instance methods that implement a default behavior. An Interface can
only declare constants and instance methods, but cannot implement
default behavior and all methods are implicitly abstract. An interface
has all public members and no implementation. An abstract class is a
class, which may have the usual flavors of class members (private,
protected, etc.), but has atleast one abstract
methods.
5. Explain the ways we can use
threads?
The thread could be created by
implementing the Runnable interface or by extending the Thread
class.
6. What is a
Map?
Map is an
Interface.