Here are top selected core java interview questions asked in high level interviews, these questions may be helpful for both freshers or experienced professional going for interview.
51) What is a List interface in Java? What are its implementation classes?List interface is a part of Java Collections API, List interface extends Collection interface provides support for ordered collections of Objects. There are three well known implementation classes for List interface i.e. ArrayList, Vector and LinkedList , all these classes provides an ordered collection of objects and support duplicate values.
52) What is a Set interface in Java? What are the implementation classes ?Like List interface Set is another interface which is a part of Java Collections API and extends Collection interface, it does not permit duplicate values in it. The well known implementation classes for a Set interface are HashSet and TreeSet.
53) What is a Map interface in Java ? What are the implementation classes ?Like List and Set interfaces, Map is also a part of Java Collections API but it does not extends Collection interface. Map provides a key value pair of Objects and some implementation like HashMap permits null whereas some implementation like HashTable does not allows null. HashMap, TreeMap and HashTable are three well known implementation of a Map interface.
54) What is the advantage of an ArrayList over Arrays in Java ?ArrayList are resizable arrays, it can grow dynamically. ArrayList provides better implementation of searching, iterating, deleting or inserting an element than arrays.
55) What are well known implementations of a List interface in Java?List interface have three well known implementations, described below:
1) ArrayList: ArrayList is an growable array with fast iteration and fast random access. It is an ordered by index collection and is not sorted in nature. It can be considered over linkedlist when we need more iteration and random access and less insertion or deletion.
2) Vector: Vector are almost as same as the ArrayList except that, methods of an Vector are synchronized and hence safe to use in a thread environment. One should use arraylist over vector if there is no need of thread safety.
3) LinkedList: Linked list is another implementation of List interface in java, elements in a linked list are ordered by index and are double-linked to each other. Because of this it provides adding or removing elements from both sides and hence it may iterate slow than ArrayList but insertion and deletion is much more fast that ArrayList.
56) What are the well known implementations of Set interface in Java?There are three well known implementation of a Set interface as described below:
1) HashSet: A HashSet is an unsorted and unordered set, it uses the hash code of the objects being inserted, so the performance all depends on how well the hash code implementation is. This ensures uniqueness of elements and does not allow duplicates.
2) TreeSet: TreeSet is a sorted Set which ensures elements will be in ascending order naturally, it uses a red-black tree structure to store elements. Optionally we can construct a TreeSet with descending ordering of elements.
3) LinkedHashSet: LinkedHashSet is an ordered version of HashSet, when we uses HashSet we cannot predict the order of iteration, while in LinkedHashSet the order of elements remains unchanged.
57) What are the well know implementations of a Mao interface in Java?There are three well known implementation of a Map interface as described below:
1) HashMap: HashMap provides an unsorted and unordered collection to store key value pairs. It cares about uniqueness of keys, HashMap allows one null key and multiple null values in it.
2) HashTable: HashTable is a synchronized version of HashMap, all the methods in a HashTable are thread safe. HashTable does not allows null keys or null values.
3) TreeMap: Like TreeSet, TreeMap is an ordered Map, which persists elements in ascending order.