Java interviews and campus tests lean heavily on object oriented behaviour rather than API recall. This set covers inheritance and polymorphism, interfaces and abstract classes, the collections framework, exception handling, multithreading, string handling, and JVM basics such as garbage collection. Output based questions are included because they expose the gaps that theory questions hide.
Which interface in Java Collections Framework does not allow duplicate elements?
Answer: B
Set interface explicitly does not allow duplicate elements. List allows duplicates, Queue is for ordered collections, and Map stores key-value pairs.
Q.55Easy
What is the underlying data structure of HashMap in Java?
Answer: B
HashMap uses a hash table with buckets (arrays of linked lists or red-black trees) to store key-value pairs for efficient O(1) average lookup time.
Q.56Easy
Which of the following maintains insertion order in Java?
Answer: C
LinkedHashSet maintains insertion order using a doubly-linked list. HashSet does not maintain order, TreeSet maintains sorted order, and ConcurrentHashMap doesn't guarantee insertion order.
Q.57Medium
What is the time complexity of get() operation in TreeMap?
Answer: B
TreeMap is based on Red-Black tree, so get(), put(), and remove() operations have O(log n) time complexity due to tree traversal.
Q.58Medium
What is the difference between ArrayList and Vector?
Answer: B
Vector is a legacy synchronized collection, while ArrayList is unsynchronized but faster. For thread-safety with ArrayList, use Collections.synchronizedList().
Q.59Medium
Which method of PriorityQueue returns the element without removing it?
Answer: C
peek() returns the head element without removing it. poll() removes and returns, remove() throws exception if empty, and pop() is not a PriorityQueue method.
Q.60Medium
What exception is thrown when you try to add a null value to a TreeSet?
Answer: A
TreeSet uses comparator or natural ordering, which cannot handle null values, throwing NullPointerException during insertion.