Core Java Interview Questions – 50 Questions (3 Years Experience)
SECTION 1: OOP & Basics (1–10)
1. What are the main principles of OOP in Java?
Answer: Encapsulation, Abstraction, Inheritance, Polymorphism. Example: Used
polymorphism for multiple payment methods.
2. Difference between == and .equals()
Answer: == compares references, .equals() compares values (override needed for custom
objects).
3. Difference between ArrayList and LinkedList
Answer: ArrayList → fast access, slow insert/delete; LinkedList → slow access, fast
insert/delete.
4. How does HashMap work internally?
Answer: Array of buckets, hash calculation, collisions via LinkedList/Tree. Resize at load
factor > 0.75.
5. Difference: HashMap, TreeMap, LinkedHashMap
Answer: HashMap → unordered, TreeMap → sorted, LinkedHashMap → insertion order.
6. String, StringBuilder, StringBuffer differences
Answer: String → immutable, StringBuilder → mutable, fast, not thread-safe; StringBuffer →
synchronized.
7. Java 8 features you used
Answer: Lambda expressions, Stream API, Optional, Date/Time API, Default & Static
methods in interfaces.
8. Multithreading: Runnable vs Thread
Answer: Runnable separates task from execution; Thread represents actual thread object.
9. synchronized, volatile, Lock
Answer: synchronized → exclusive access, volatile → visibility, Lock → advanced locking with
tryLock().
10. hashCode() & equals() contract
Answer: If [Link](b) → [Link]() == [Link](). Critical for HashMap/HashSet.
SECTION 2: Memory & Exception Handling (11–20)
11. Garbage collection & reference types
Answer: Automatic memory cleanup. Strong, Soft, Weak, Phantom references.
12. Difference between final, finally, finalize()
Answer: final → constant; finally → executes after try/catch; finalize() → called by GC.
13. Checked vs Unchecked exceptions
Answer: Checked → compile-time, must handle; Unchecked → runtime errors.
14. Stack vs Heap memory
Answer: Stack → primitives & references; Heap → objects, shared across threads.
15. Abstract class vs Interface
Answer: Abstract → base implementation; Interface → contract. Java 8+ allows default
methods.
16. Java Reflection
Answer: Inspect classes/methods/fields at runtime. Example: Dynamic class loading in
Spring.
17. Serialization & Deserialization
Answer: Object → byte stream and vice versa. Used in caching, REST transfer, session
storage.
18. transient keyword
Answer: Field not serialized. Example: private transient String password;
19. Comparator vs Comparable
Answer: Comparable → natural ordering (compareTo()), Comparator → custom ordering
(compare()).
20. wait(), notify(), notifyAll(), sleep()
Answer: wait → releases lock, sleep → retains lock, notify → wakes one thread, notifyAll →
wakes all.
SECTION 3: Collections & Generics (21–30)
21. Difference between List, Set, Map
Answer: List → ordered, duplicates allowed; Set → unique elements; Map → key-value pairs.
22. HashSet vs TreeSet vs LinkedHashSet
Answer: HashSet → unordered, TreeSet → sorted, LinkedHashSet → insertion order.
23. Generics in Java
Answer: Type safety at compile time; e.g., List<String> avoids casting.
24. Wildcards in Generics
Answer: ? extends T → upper bound, ? super T → lower bound.
25. Iterator vs ListIterator
Answer: Iterator → forward only; ListIterator → forward/backward.
26. Fail-fast vs Fail-safe iterators
Answer: Fail-fast → throw ConcurrentModificationException (ArrayList, HashMap), Fail-safe
→ work on copy (CopyOnWriteArrayList).
27. PriorityQueue
Answer: Implements heap; used for ordering elements by natural or custom comparator.
28. LinkedHashMap and accessOrder
Answer: Maintains insertion or access order (useful for LRU cache).
29. Difference between Enumeration and Iterator
Answer: Iterator → fail-fast, remove() supported; Enumeration → legacy, no remove().
30. ConcurrentHashMap vs HashMap
Answer: Thread-safe, segment-based locking, avoids concurrent modification issues.
SECTION 4: Multithreading & Concurrency (31–40)
31. Thread lifecycle
Answer: New → Runnable → Running → Waiting/Blocked → Terminated
32. Thread priorities
Answer: MIN_PRIORITY = 1, NORM_PRIORITY = 5, MAX_PRIORITY = 10
33. ExecutorService
Answer: Thread pool management; avoids frequent thread creation/destruction.
34. Callable vs Runnable
Answer: Callable → returns value, throws exception; Runnable → no return value.
35. Future & FutureTask
Answer: Async task result handling.
36. CountDownLatch
Answer: Blocks threads until count reaches zero; used for startup waits.
37. CyclicBarrier
Answer: Allows threads to wait for each other repeatedly (barrier synchronization).
38. Semaphore
Answer: Controls number of threads accessing resource concurrently.
39. ReentrantLock vs synchronized
Answer: ReentrantLock → more features (tryLock, interruptible); synchronized → intrinsic
locking.
40. Atomic classes
Answer: [Link] → AtomicInteger, AtomicReference for lock-free thread-
safe operations.
SECTION 5: Java 8+ Features (41–50)
41. Lambda expressions
Answer: Concise functional interface implementation.
[Link](name -> [Link](name));
42. Functional interfaces
Answer: Single abstract method interfaces; e.g., Runnable, Comparator.
43. Stream API
Answer: Map, filter, reduce, sorted, collect; supports lazy evaluation.
44. Optional class
Answer: Avoid NullPointerException; [Link](), [Link]().
45. Default & static methods in interfaces
Answer: Allow interface evolution without breaking existing implementations.
46. Method references
Answer: Shortcut for lambda expressions; ClassName::methodName.
47. New Date/Time API
Answer: LocalDate, LocalDateTime, ZonedDateTime for immutable, thread-safe date
handling.
48. CompletableFuture
Answer: Async programming, chaining tasks.
[Link](() -> "Hello").thenApply(s -> s + " World");
49. Parallel Streams
Answer: Process collections concurrently using multiple threads.
50. Collectors API
Answer: Aggregates results of streams; e.g., [Link](), [Link]().