Java is asked in more Indian fresher interviews than any other language — TCS, Infosys, Wipro, Cognizant, and most product companies test it by default. The problem: most freshers memorise definitions but can't apply concepts. Here are the 60 questions that actually get asked, with answers built for explaining, not just reciting.
OOP Fundamentals — Always Asked
1. What are the 4 pillars of OOP?
Encapsulation (bundling data + methods), Inheritance (IS-A relationship), Polymorphism (many forms — compile-time vs runtime), Abstraction (hiding implementation details). Know concrete examples of each.
2. Difference between Abstraction and Encapsulation?
Abstraction = hiding complexity (what). Encapsulation = hiding data (how). Abstract class/interface implements abstraction; private fields + getters/setters implement encapsulation.
3. What is method overloading vs overriding?
Overloading: same method name, different parameters (compile-time polymorphism, same class).
Overriding: same method signature in subclass (runtime polymorphism, inheritance required).
4. Can we override static methods in Java?
No — static methods are resolved at compile time (method hiding, not overriding). This is a common trick question.
5. What is the difference between abstract class and interface?
Abstract class: can have constructors, state, and partial implementation. Interface (Java 8+): default and static methods allowed; no state. A class can implement multiple interfaces but extend only one abstract class.
6. What is the diamond problem and how does Java solve it?
When multiple inheritance leads to ambiguity in which parent's method is called. Java avoids it by not allowing multiple class inheritance; interfaces with default methods use explicit override to resolve conflicts.
Java Collections — Heavily Tested
7. ArrayList vs LinkedList — when to use which?
ArrayList: O(1) random access, O(n) insert/delete in middle. LinkedList: O(1) insert/delete at head/tail, O(n) random access. Use ArrayList for most use cases; LinkedList when frequent head/tail insertions matter.
8. HashMap internal working?
HashMap stores key-value pairs in an array of buckets. Keys are hashed to bucket indices. Collisions (same bucket, different keys) are handled with chaining (linked list) or, since Java 8, red-black tree when bucket size > 8. Load factor default 0.75 — resize at 75% capacity.
9. HashMap vs Hashtable vs ConcurrentHashMap?
Hashtable: thread-safe but synchronized on every method (slow). ConcurrentHashMap: thread-safe with segment-level locking (Java 7) or CAS operations (Java 8+) — much faster. HashMap: not thread-safe.
10. What is the difference between Comparable and Comparator?
Comparable: natural ordering, implemented by the class itself (compareTo()). Comparator: custom ordering, external class/lambda. Use Comparator when you don't control the class or need multiple sort orders.
Exception Handling & Memory
11. Checked vs unchecked exceptions?
Checked: must be declared/handled at compile time (IOException, SQLException). Unchecked: RuntimeExceptions — NullPointerException, ArrayIndexOutOfBoundsException. Error: system-level (StackOverflowError, OutOfMemoryError).
12. What happens when you catch and swallow an exception?
The program continues but the error is silently ignored — dangerous in production. Always log the exception at minimum; propagate it if the caller should handle it.
13. What is the finally block?
Always executes after try/catch, even on exception or return (but NOT if System.exit() is called or JVM crashes). Use for resource cleanup (pre-Java 7); prefer try-with-resources (AutoCloseable) in modern code.
14. What is garbage collection?
JVM automatically manages memory. Objects become eligible for GC when no references point to them. GC algorithms: Serial, Parallel, G1 (default from Java 9+), ZGC (low-latency). You can hint with System.gc() but can't force it.
Java 8+ Features — Modern Fresher Questions
15. What are lambda expressions?
Anonymous functions — syntax: (params) -> body. Enable functional programming in Java. Example: list.sort((a, b) -> a.compareTo(b)).
16. What are Streams?
Functional pipeline for processing collections: filter → map → reduce → collect. Lazy evaluation — intermediate operations run only when terminal operation is called. Parallel streams use fork/join pool.
17. What is Optional?
Wrapper class to avoid NullPointerException. Optional.of(), Optional.ofNullable(), Optional.empty(). Use .orElse(), .orElseThrow(), .ifPresent(). Don't use Optional as method parameter — use it as return type.
18. Default and static methods in interfaces?
Java 8 allowed default methods (implementation in interface) to enable backward compatibility when adding new methods to existing interfaces. Static interface methods can be called without an instance.
Multithreading — Asked at Mid-Level Freshers
19. Thread vs Runnable vs Callable?
Runnable: run() returns void. Callable: call() returns a value and can throw checked exceptions. Thread: a thread of execution, takes Runnable/Callable in constructor.
20. What is the volatile keyword?
Forces all threads to read the variable from main memory, not CPU cache. Solves visibility problem but not atomicity — for compound operations use AtomicInteger or synchronized.
21. What is a deadlock? How do you prevent it?
Deadlock: two threads each hold a resource the other needs, both wait forever. Prevention: always acquire locks in the same order; use timeout-based lock acquisition (tryLock with timeout); avoid holding multiple locks.
22. ExecutorService vs creating new Thread directly?
Always prefer ExecutorService — it manages a thread pool, reuses threads, handles exceptions, and provides Future for async results. Creating new Thread() per task wastes resources and is uncontrolled.
Frequently asked questions
Ready to practice?
Practice technical Java questions in a mock interview format on HireStepX — AI evaluates your explanation depth, not just whether the answer is correct.
Start free practice