Wednesday, 11 July 2012


117) What is Garbage Collection?
Garbage collection is a process of reclaiming the runtime unused objects.It is performed for memory
management. more details...
118) 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.
119) What is the purpose of finalize() method?
finalize() method is invoked just before the object is garbage collected.It is used to perform cleanup
processing.
120) Can an unrefrenced objects be refrenced again?
Yes.
121)What kind of thread is the Garbage collector thread?
Daemon thread.
122)What is difference between final, finally and finalize?
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.
123)What is the purpose of the Runtime class?
The purpose of the Runtime class is to provide access to the Java runtime system.
124)How will you invoke any external process in Java?
By Runtime.getRuntime().exec(?) method.
Home Core Java Servlet JSP Mail API Hibernate Spring Android Interview Q Comment Ask Q7/11/12 Collection interview question - javatpoint
www.javatpoint.com/corejava-interview-questions-4 2/5
I/O Interview Questions
125)What is the difference between the Reader/Writer class hierarchy and the
InputStream/OutputStream class hierarchy?
The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy
is byte-oriented.
126)What an I/O filter?
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
127) What is serialization?
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. more details...
128) What is Deserialization?
Deserialization is the process of reconstructing the object from the serialized state.It is the reverse operation
of serialization.
129) What is transient keyword?
If you define any data member as transient,it will not be serialized.more details...
130)What is Externalizable?
Externalizable interface is used to write the state of an object into a byte stream in compressed format.It is
not a marker interface.
131)What is the difference between Serializalble and Externalizable interface?
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.
Networking Interview Questions
132)How do I convert a numeric IP address like 192.18.97.39 into a hostname like
java.sun.com?
By InetAddress.getByName("192.18.97.39").getHostName() where 192.18.97.39 is the IP address.
Reflection Interview Questions
133) What is reflection?7/11/12 Collection interview question - javatpoint
www.javatpoint.com/corejava-interview-questions-4 3/5
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.
Debugger
Test Tools etc.
134) Can you access the private method from outside the class?
Yes, by changing the runtime behaviour of a class if the class is not secured.more details...
Collection Interview Questions
In java, collection interview questions are mostly asked by the interviewers. Here is the list of mostly asked
collection interview questions with answers.
135) What is difference between ArrayList and Vector?
ArrayList Vector
1) ArrayList is not synchronized. 1) Vector is synchronized.
2) ArrayList is not a legacy class. 2) Vector is a legacy class.
3) ArrayList increases its size by 50% of the array
size.
3) Vector increases its size by doubling the array
size.
136) What is difference between ArrayList and LinkedList?
ArrayList LinkedList
1) ArrayList uses a dynamic array. 1) LinkedList uses doubly linked list.
2) ArrayList is not efficient for manipulation because a lot of shifting
is required.
2) LinkedList is efficient for
manipulation.
137) What is difference between HashMap and Hashtable?
HashMap Hashtable
1) HashMap is not synchronized. 1) Hashtable is synchronized.
2) HashMap can contain one null key and multiple null
values.
2) Hashtable cannot contain any null key nor
value.
138)What is hash-collision in Hashtable and how it is handled in Java?
Two different keys with the same hash value. Two different entries will be kept in a single hash bucket to
avoid the collision.
139) What is difference between HashSet and HashMap?
HashSet contains only values whereas HashMap contains entry(key,value).
140)What is difference between HashMap and TreeMap?
HashMap TreeMap
1) HashMap is can contain one null key. 1) TreeMap connot contain any null key.
2) HashMap maintains no order. 2) TreeMap maintains ascending order.
141) What is difference between HashSet and TreeSet?
HashSet maintains no order whereas TreeSet maintains ascending order.7/11/12 Collection interview question - javatpoint
www.javatpoint.com/corejava-interview-questions-4 4/5
<<prev next>>
142) What is difference between List and Set?
List can contain duplicate elements whereas Set contains only unique elements.
143) What is difference between Iterator and ListIterator?
Iterator traverses the elements in forward direction only whereas ListIterator traverses the elements in
forward and backward direction.
144) Can you make List,Set and Map elements synchronized?
Yes, Collections class provides methods to make List,Set or Map elements as synchronized:
public static List synchronizedList(List l){}
public static Set synchronizedSet(Set s){}
public static SortedSet synchronizedSortedSet(SortedSet s){}
public static Map synchronizedMap(Map m){}
public static SortedMap synchronizedSortedMap(SortedMap m){}
145) What is difference between Iterator and Enumeration?
Iterator Enumeration
1) Iterator can traverse legacy and non-legacy
elements.
1) Enumeration can traverse only legacy
elements.
2) Iterator is fail-fast. 2) Enumeration is not fail-fast.
3) Iterator is slower than Enumeration. 3) Enumeration is faster than Iterator.
146) What is difference between Comparable and Comparator?
Comparable Comparator
1) Comparable provides only one sort of sequence.
1) Comparator provides multiple sort of
sequences.
2) It provides one method named compareTo(). 2) It provides one method named compare().
3) It is found in java.lang package. 3) it is found in java.util package.
4) If we implement Comparable interface, actual class is
modified.
4) Actual class is not modified.
147) What is the Dictionary class?
The Dictionary class provides the capability to store key-value pairs.

No comments:

Post a Comment