Garbage Collection Interview Questions
101) What is Garbage Collection?
Ans: Garbage collection is a process of reclaiming the runtime unused objects.It is performed for memory management.
102) What is gc()?
Ans: gc() is a daemon thread.gc() method is defined in System class that is used to send request to JVM to perform garbage collection.
103) What is the purpose of finalize() method?
Ans: finalize() method is invoked just before the object is garbage collected.It is used to perform cleanup processing.
104) Can an unrefrenced objects be refrenced again?
105) What kind of thread is the Garbage collector thread?
Ans: Daemon thread.
106) What is difference between final, finally and finalize?
Ans: final: final is a keyword, final can be variable, method or class.You, can't change the value of final variable, can't override final method, can't inherit final class.
finally: finally block is used in exception handling. finally block is always executed.
finalize(): finalize() method is used in garbage collection.finalize() method is invoked just before the object is garbage collected.The finalize() method can be used to perform any cleanup processing.
107) What is the purpose of the Runtime class?
Ans: The purpose of the Runtime class is to provide access to the Java runtime system.
108) How will you invoke any external process in Java?
Ans: By Runtime.getRuntime().exec(?) method.
I/O Interview Questions
109) What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
Ans: The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.
110) What an I/O filter?
Ans: An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.
Serialization Interview Questions
111) What is serialization?
Ans: Serialization is a process of writing the state of an object into a byte stream.It is mainly used to travel object's state on the network.
112) What is Deserialization?
Ans: Deserialization is the process of reconstructing the object from the serialized state.It is the reverse operation of serialization.
113) What is transient keyword?
Ans: If you define any data member as transient,it will not be serialized.
114) What is Externalizable?
Ans: Externalizable interface is used to write the state of an object into a byte stream in compressed format.It is not a marker interface.
115) What is the difference between Serializalble and Externalizable interface?
Ans: Serializable is a marker interface but Externalizable is not a marker interface.When you use Serializable interface, your class is serialized automatically by default. But you can override writeObject() and readObject() two methods to control more complex object serailization process. When you use Externalizable interface, you have a complete control over your class's serialization process.
Reflection Interview Questions
116) What is reflection?
Ans: Reflection is the process of examining or modifying the runtime behaviour of a class at runtime.It is used in:
- IDE (Integreted Development Environment) e.g. Eclipse, MyEclipse, NetBeans.
- Test Tools etc.
117) Can you access the private method from outside the class?
Ans: Yes, by changing the runtime behaviour of a class if the class is not secured.
Miscellaneous Interview Questions
118) What are wrapper classes?
Ans: Wrapper classes are classes that allow primitive types to be accessed as objects.
119) What is a native method?
Ans: A native method is a method that is implemented in a language other than Java.
120) What is the purpose of the System class?
Ans: The purpose of the System class is to provide access to system resources.