LATEST JOBS

module3

By sathesh on 2:08 AM

Filed Under:

this site contains all frequently asked questions in interviews.

1) Explain Java Collections Framework?

     Java Collections Framework provides a well designed set of interfaces and classes that support operations on a collection of objects.



2) Explain Iterator Interface.

     An Iterator is similar to the Enumeration interface. With the Iterator interface methods, you can traverse a collection from start to end and safely remove elements from the underlying collection. The iterator() method generally used in query operations.

Basic methods:

iterator.remove();

iterator.hasNext();

iterator.next();



3) Explain Enumeration Interface.

     The Enumeration interface allows you to iterate through all the elements of a collection. Iterating through an Enumeration is similar to iterating through an Iterator. However, there is no removal support with Enumeration.

Basic methods:

boolean hasMoreElements();

Object nextElement();


4) What is the difference between Enumeration and Iterator interface?

     The Enumeration interface allows you to iterate through all the elements of a collection. Iterating through an Enumeration is similar to iterating through an Iterator. However, there is no removal support with Enumeration.







5) Explain Set Interface.

     In mathematical concept, a set is just a group of unique items, in the sense that the group contains no duplicates. The Set interface extends the Collection interface. Set does not allow duplicates in the collection. In Set implementations null is valid entry, but allowed only once.



6) What are the two types of Set implementations available in the Collections Framework?

     HashSet and TreeSet are the two Set implementations available in the Collections Framework.



7) What is the difference between HashSet and TreeSet?

     HashSet Class implements java.util.Set interface to eliminate the duplicate entries and uses hashing for storage. Hashing is nothing but mapping between a key value and a data item, this provides efficient searching.


The TreeSet Class implements java.util.Set interface provides an ordered set, eliminates duplicate entries and uses tree for storage.



8) What is a List?

     List is an ordered and non duplicated collection of objects. The List interface extends the Collection interface.



9) What are the two types of List implementations available in the Collections Framework?

     ArrayList and LinkedList are the two List implementations available in the Collections Framework.



10) What is the difference between ArrayList and LinkedList?

     The ArrayList Class implements java.util.List interface and uses array for storage. An array storage's are generally faster but we cannot insert and delete entries in middle of the list. To achieve this kind of addition and deletion requires a new array constructed. You can access any element at randomly.


The LinkedList Class implements java.util.List interface and uses linked list for storage. A linked list allow elements to be added, removed from the collection at any location in the container by ordering the elements. With this implementation you can only access the elements in sequentially.



11) What collection will you use to implement a queue?

     LinkedList



12) Explain Map Interface.

     A map is a special kind of set with no duplicates. The key values are used to lookup, or index the stored data. The Map interface is not an extension of Collection interface, it has it's own hierarchy. Map does not allow duplicates in the collection. In Map implementations null is valid entry, but allowed only once.



13) What are the two types of Map implementations available in the Collections Framework?

     HashMap and TreeMap are two types of Map implementations available in the Collections Framework.



14) What is the difference between HashMap and TreeMap?

     The HashMap Class implements java.util.Map interface and uses hashing for storage. Indirectly Map uses Set functionality so, it does not permit duplicates. The TreeMap Class implements java.util.Map interface and uses tree for storage. It provides the ordered map.



15) Explain the functionality of Vector Class?

     Once array size is set you cannot change size of the array.
To deal with this kind of situations we use Vector. Vector grows and shrink it's size automatically. Vector allows to store only objects not primitives. To store primitives, convert primitives in to objects using wrapper classes before adding them into Vector. The Vector reallocates and resizes itself automatically.



16) What does the following statement convey?

Vector vt = new Vector(3, 10);



     vt is an instance of Vector class with an initial capacity of 3 and grows in increment of 10 in each relocation



17) How do you store a primitive data type within a Vector or other collections class?

     You need to wrap the primitive data type into one of the wrapper classes found in the java.lang package, like Integer, Float, or Double, as in:

Integer in = new Integer(5);




18) What is the difference between Vector and ArrayList?

     Vector and ArrayList are very similar. Both of them represent a growable array. The main difference is that Vector is synchronized while ArrayList is not.



19) What is the difference between Hashtable and HashMap?

     Both provide key-value access to data. The key differences are :

a. Hashtable is synchronised but HasMap is not synchronised.

b. HashMap permits null values but Hashtable doesn't allow null values.

c. iterator in the HashMap is fail-safe while the enumerator for the Hashtable is not fail safe.



20) How do I make an array larger?

     You cannot directly make an array larger. You must make a new (larger) array and copy the original elements into it, usually with System.arraycopy(). If you find yourself frequently doing this, the Vector class does this automatically for you, as long as your arrays are not of primitive data types.



21) Which is faster, synchronizing a HashMap or using a Hashtable for thread-safe access?

     Because a synchronized HashMap requires an extra method call, a Hashtable is faster for synchronized access.



22) In which package would you find the interfaces and classes defined in the Java Collection Framework?

     java.util



23) Which method in the System class allows you to copy elements from one array to another?

     System.arraycopy()



24) When using the System.arraycopy() method, What exception is thrown if the destination array is smaller than the source array?

     ArrayIndexOutofBoundsException



25) What is the use of Locale class?

     The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region



26) What is the use of GregorianCalendar class?

     The GregorianCalendar provides support for traditional Western calendars



27) What is the use of SimpleTimeZone class?

     The SimpleTimeZone class provides support for a Gregorian calendar



28) What is the use of ResourceBundle class?

     The ResourceBundle class is used to store locale-specific resources that can be loaded by a program to tailor the program's appearance to the particular locale in which it is being run.

0 comments for this post

Post a Comment