Top 100 Java Interview Questions and Answers for Freshers in 2026
If you are a fresher preparing for a Java developer interview in Pune — at companies in Hinjewadi, Kharadi, Baner, or Magarpatta — this is the only list you need.
Java remains the most in-demand backend language in Pune's IT market in 2026. TCS, Infosys, Wipro, Persistent Systems, Zensar, KPIT, and hundreds of mid-size and product companies in Pune hire Java developers every month. And every single one of them asks questions from this list.
At Trimaya TechnoSol, FC Road, Deccan Gymkhana, Pune, our Java Full Stack students clear interviews at top Pune IT companies every month. This list is built from real interview feedback from our placed students.
Bookmark it. Study it. Clear your interview.
---
Section 1: Core Java Basics (Questions 1–20)
Q1. What is Java?
Java is a high-level, object-oriented, platform-independent programming language developed by Sun Microsystems (now Oracle). It follows the "Write Once, Run Anywhere" (WORA) principle — Java code compiles to bytecode that runs on any JVM regardless of the underlying operating system.
Q2. What is the difference between JDK, JRE, and JVM?
- JVM (Java Virtual Machine): Executes Java bytecode. Platform-specific.
- JRE (Java Runtime Environment): JVM + libraries needed to run Java programs.
- JDK (Java Development Kit): JRE + development tools (compiler, debugger). Used to write and compile Java programs.
Q3. What are the main features of Java?
Object-oriented, platform-independent, simple, secure, robust, multithreaded, portable, high-performance, distributed, and dynamic.
Q4. What is the difference between a compiled language and an interpreted language? Where does Java fit?
Compiled languages (C, C++) convert source code directly to machine code. Interpreted languages (Python) execute line by line. Java is both — it compiles to bytecode (compiled step), which the JVM then interprets or JIT-compiles at runtime.
Q5. What is a class in Java?
A class is a blueprint or template that defines the properties (fields) and behaviours (methods) of objects. It is the fundamental building block of object-oriented programming in Java.
Q6. What is an object in Java?
An object is an instance of a class. It has state (field values) and behaviour (methods). Objects are created using the `new` keyword.
Q7. What is the difference between `==` and `.equals()` in Java?
`==` compares object references (memory addresses). `.equals()` compares the content/value of objects. For String comparison, always use `.equals()` — `==` will return false even for strings with identical content if they are different objects in memory.
Q8. What is the difference between `String`, `StringBuilder`, and `StringBuffer`?
- String: Immutable. Every modification creates a new object. Thread-safe by nature.
- StringBuilder: Mutable. Not thread-safe. Faster for single-threaded string manipulation.
- StringBuffer: Mutable. Thread-safe (synchronized). Slower than StringBuilder.
Q9. What is the `final` keyword in Java?
- final variable: Value cannot be changed after assignment.
- final method: Cannot be overridden in a subclass.
- final class: Cannot be subclassed (e.g., String class is final).
Q10. What is the difference between `static` and `instance` variables?
Static variables belong to the class and are shared across all instances. Instance variables belong to each individual object and have separate values per object.
Q11. What is a constructor in Java?
A constructor is a special method called when an object is created. It has the same name as the class and no return type. Used to initialise object state. Java provides a default no-arg constructor if none is defined.
Q12. What is constructor overloading?
Defining multiple constructors in the same class with different parameter lists. Java determines which constructor to call based on the arguments passed at object creation.
Q13. What is the difference between `this` and `super` keywords?
`this` refers to the current class instance. `super` refers to the parent class. `this()` calls another constructor in the same class; `super()` calls the parent class constructor.
Q14. What is method overloading?
Defining multiple methods with the same name but different parameter lists (number, type, or order of parameters) within the same class. Resolved at compile time (static polymorphism).
Q15. What is method overriding?
Providing a new implementation for a method inherited from a parent class in the child class. The method signature must be identical. Resolved at runtime (dynamic polymorphism).
Q16. What is the difference between `break` and `continue`?
`break` exits the loop entirely. `continue` skips the current iteration and moves to the next one.
Q17. What are wrapper classes in Java?
Wrapper classes convert primitive types into objects. Examples: `Integer` (for int), `Double` (for double), `Boolean` (for boolean). Required when working with Collections, which only store objects.
Q18. What is autoboxing and unboxing?
Autoboxing is the automatic conversion of a primitive to its wrapper class (int → Integer). Unboxing is the reverse (Integer → int). Java handles this automatically since Java 5.
Q19. What is the difference between `int` and `Integer`?
`int` is a primitive type stored on the stack. `Integer` is a wrapper class (object) stored on the heap. `Integer` can be null; `int` cannot.
Q20. What is a package in Java?
A package is a namespace that organises related classes and interfaces. It prevents naming conflicts and controls access. Example: `java.util`, `java.io`, `com.trimaya.courses`.
---
Section 2: Object-Oriented Programming (Questions 21–40)
Q21. What are the four pillars of OOP?
Encapsulation, Inheritance, Polymorphism, and Abstraction.
Q22. What is encapsulation?
Bundling data (fields) and methods that operate on that data within a single class, and restricting direct access to fields using access modifiers (private). Access is provided through public getter and setter methods.
Q23. What is inheritance?
A mechanism where a child class acquires the properties and behaviours of a parent class using the `extends` keyword. Promotes code reuse. Java supports single and multilevel inheritance for classes.
Q24. What is polymorphism?
The ability of an object to take many forms. In Java: compile-time polymorphism (method overloading) and runtime polymorphism (method overriding with dynamic dispatch).
Q25. What is abstraction?
Hiding implementation details and exposing only the essential features. Achieved in Java through abstract classes and interfaces.
Q26. What is an abstract class?
A class declared with the `abstract` keyword that cannot be instantiated. It can have abstract methods (no body) and concrete methods (with body). Subclasses must implement all abstract methods.
Q27. What is an interface?
A reference type in Java that defines a contract — a set of abstract methods that implementing classes must provide. From Java 8, interfaces can also have default and static methods.
Q28. What is the difference between an abstract class and an interface?
- Abstract class: can have constructors, instance variables, concrete methods. Single inheritance only.
- Interface: no constructors, all fields are public static final by default. A class can implement multiple interfaces.
Q29. What is multiple inheritance? Does Java support it?
Multiple inheritance means a class inheriting from more than one class. Java does not support multiple inheritance for classes (to avoid the diamond problem) but supports it through interfaces.
Q30. What is the diamond problem?
When a class inherits from two classes that both inherit from the same parent, ambiguity arises about which parent's method to use. Java avoids this by not allowing multiple class inheritance.
Q31. What is a static method?
A method that belongs to the class rather than any instance. Called using the class name. Cannot access instance variables or instance methods directly.
Q32. Can we override a static method?
No. Static methods are resolved at compile time based on the reference type, not the object type. This is called method hiding, not overriding.
Q33. What is an inner class?
A class defined inside another class. Types: static nested class, inner class (non-static), local class (inside a method), and anonymous class.
Q34. What is an anonymous class?
A class without a name, defined and instantiated in a single expression. Commonly used to implement interfaces or extend abstract classes inline, especially in event handling and callbacks.
Q35. What is the `instanceof` operator?
Used to check whether an object is an instance of a specific class or interface. Returns true or false. Used before casting to avoid ClassCastException.
Q36. What is upcasting and downcasting?
Upcasting: assigning a child class object to a parent class reference (automatic, safe). Downcasting: casting a parent class reference back to a child class type (explicit, can throw ClassCastException if incorrect).
Q37. What is a covariant return type?
In Java 5+, an overriding method can return a subtype of the return type declared in the parent class method. This is called a covariant return type.
Q38. What is the `Object` class?
The root class of all Java classes. Every class in Java implicitly extends `Object`. Key methods: `toString()`, `equals()`, `hashCode()`, `clone()`, `getClass()`, `wait()`, `notify()`, `notifyAll()`.
Q39. What is the contract between `equals()` and `hashCode()`?
If two objects are equal according to `equals()`, they must have the same `hashCode()`. If you override `equals()`, you must also override `hashCode()`. Violating this breaks HashMap and HashSet behaviour.
Q40. What is a marker interface?
An interface with no methods, used to mark or tag a class for special treatment by the JVM or framework. Examples: `Serializable`, `Cloneable`, `Remote`.
---
Section 3: Collections Framework (Questions 41–60)
Q41. What is the Java Collections Framework?
A unified architecture for storing and manipulating groups of objects. Key interfaces: `Collection`, `List`, `Set`, `Queue`, `Map`. Key implementations: `ArrayList`, `LinkedList`, `HashSet`, `TreeSet`, `HashMap`, `TreeMap`.
Q42. What is the difference between `ArrayList` and `LinkedList`?
- `ArrayList`: backed by a dynamic array. Fast random access O(1). Slow insertion/deletion in the middle O(n).
- `LinkedList`: doubly linked list. Slow random access O(n). Fast insertion/deletion at ends O(1).
Q43. What is the difference between `HashSet`, `LinkedHashSet`, and `TreeSet`?
- `HashSet`: no order, no duplicates, O(1) operations.
- `LinkedHashSet`: maintains insertion order, no duplicates.
- `TreeSet`: sorted natural order, no duplicates, O(log n) operations.
Q44. How does `HashMap` work internally?
HashMap uses an array of buckets. The key's `hashCode()` determines the bucket index. If multiple keys hash to the same bucket (collision), they are stored in a linked list (or a balanced tree from Java 8 when the list exceeds 8 entries). `equals()` is used to find the exact key within a bucket.
Q45. What is the difference between `HashMap` and `Hashtable`?
`HashMap` is not synchronised (not thread-safe), allows one null key and multiple null values, faster. `Hashtable` is synchronised (thread-safe), does not allow null keys or values, slower.
Q46. What is `ConcurrentHashMap`?
A thread-safe version of `HashMap` that uses segment-level locking (Java 7) or CAS operations (Java 8+) instead of synchronising the entire map. Much better performance than `Hashtable` in concurrent environments.
Q47. What is the difference between `Iterator` and `ListIterator`?
`Iterator` traverses in one direction (forward only) and works on any Collection. `ListIterator` traverses in both directions and works only on Lists. `ListIterator` also allows modification during iteration.
Q48. What is the `Comparable` interface?
Used to define the natural ordering of objects. A class implements `Comparable` and overrides `compareTo()`. Used by `TreeSet`, `TreeMap`, and `Collections.sort()`.
Q49. What is the `Comparator` interface?
Used to define a custom ordering separate from the natural order. Passed as an argument to sorting methods. Allows multiple different sort orders for the same class.
Q50. What is the difference between `fail-fast` and `fail-safe` iterators?
Fail-fast iterators (ArrayList, HashMap) throw `ConcurrentModificationException` if the collection is modified during iteration. Fail-safe iterators (CopyOnWriteArrayList, ConcurrentHashMap) work on a copy of the collection and do not throw exceptions.
Q51. What is `Collections.unmodifiableList()`?
Returns a read-only view of a list. Any attempt to modify it throws `UnsupportedOperationException`. The underlying list can still be modified directly.
Q52. What is the difference between `List.of()` and `new ArrayList()`?
`List.of()` (Java 9+) creates an immutable list — no add, remove, or set operations allowed. `new ArrayList()` creates a mutable list.
Q53. What is a `PriorityQueue`?
A queue that orders elements by natural ordering or a custom Comparator. The head of the queue is always the smallest (or highest priority) element. Used in scheduling and graph algorithms.
Q54. What is `ArrayDeque`?
A resizable array implementation of the `Deque` interface. Faster than `Stack` for stack operations and faster than `LinkedList` for queue operations. Does not allow null elements.
Q55. What is the difference between `poll()` and `remove()` in a Queue?
Both remove and return the head element. `poll()` returns null if the queue is empty. `remove()` throws `NoSuchElementException` if the queue is empty.
Q56. What is `EnumSet` and `EnumMap`?
Specialised Set and Map implementations for use with enum types. Extremely fast and memory-efficient — backed by bit vectors internally.
Q57. What is the `Collections` utility class?
A class with static utility methods for collections: `sort()`, `reverse()`, `shuffle()`, `min()`, `max()`, `frequency()`, `disjoint()`, `synchronizedList()`, `unmodifiableList()`.
Q58. What is `Arrays.asList()` and what are its limitations?
Converts an array to a fixed-size List. You can update elements but cannot add or remove elements — those operations throw `UnsupportedOperationException`.
Q59. What is the initial capacity and load factor of `HashMap`?
Default initial capacity is 16 buckets. Default load factor is 0.75 — when 75% of buckets are filled, the HashMap resizes (doubles capacity and rehashes all entries).
Q60. What is `WeakHashMap`?
A HashMap where keys are held by weak references. If a key has no other strong references, it can be garbage collected — the entry is automatically removed. Used for caches.
---
Section 4: Exception Handling (Questions 61–75)
Q61. What is an exception in Java?
An exception is an event that disrupts the normal flow of program execution. Java uses a class hierarchy rooted at `Throwable`, with two main branches: `Error` (unrecoverable JVM errors) and `Exception` (recoverable application errors).
Q62. What is the difference between checked and unchecked exceptions?
Checked exceptions (e.g., `IOException`, `SQLException`) must be declared with `throws` or handled with try-catch at compile time. Unchecked exceptions (e.g., `NullPointerException`, `ArrayIndexOutOfBoundsException`) extend `RuntimeException` and do not require explicit handling.
Q63. What is the difference between `throw` and `throws`?
`throw` is used to explicitly throw an exception object. `throws` is used in a method signature to declare that the method may throw certain checked exceptions.
Q64. What is a `finally` block?
A block that always executes after try-catch, regardless of whether an exception was thrown or caught. Used for cleanup operations like closing database connections or file streams.
Q65. Can `finally` block be skipped?
Yes, in two cases: if `System.exit()` is called inside try or catch, or if the JVM crashes.
Q66. What is try-with-resources?
Introduced in Java 7. Automatically closes resources (that implement `AutoCloseable`) after the try block completes, even if an exception occurs. Eliminates the need for a finally block to close resources.
Q67. What is a custom exception?
A user-defined exception class that extends `Exception` (checked) or `RuntimeException` (unchecked). Used to represent application-specific error conditions with meaningful names and messages.
Q68. What is exception chaining?
Wrapping one exception inside another to preserve the original cause. Done by passing the original exception to the new exception's constructor as the `cause` parameter. Accessible via `getCause()`.
Q69. What is `NullPointerException` and how do you avoid it?
Thrown when you try to use a null reference. Avoid with null checks, `Optional` (Java 8+), defensive programming, and using `Objects.requireNonNull()` for parameter validation.
Q70. What is `StackOverflowError`?
Thrown when the call stack exceeds its limit, typically due to infinite recursion. It is an `Error`, not an `Exception`, and should not be caught in normal application code.
Q71. What is `OutOfMemoryError`?
Thrown when the JVM cannot allocate memory for a new object. Causes: memory leaks, very large data structures, insufficient heap size. Increase heap with `-Xmx` JVM flag or fix memory leaks.
Q72. What is multi-catch in Java 7+?
Allows catching multiple exception types in a single catch block using the pipe operator: `catch (IOException | SQLException e)`. Reduces code duplication.
Q73. What happens if an exception is thrown in a `finally` block?
The exception from the finally block replaces any exception from the try block. The original exception is lost unless explicitly preserved.
Q74. What is the difference between `Error` and `Exception`?
`Error` represents serious JVM-level problems (OutOfMemoryError, StackOverflowError) that applications should not try to recover from. `Exception` represents conditions that applications can and should handle.
Q75. What is `ClassNotFoundException` vs `NoClassDefFoundError`?
`ClassNotFoundException` is a checked exception thrown when a class is not found at runtime via reflection or `Class.forName()`. `NoClassDefFoundError` is an error thrown when a class was present at compile time but is missing at runtime.
---
Section 5: Java 8+ Features (Questions 76–90)
Q76. What are the major features introduced in Java 8?
Lambda expressions, Functional interfaces, Stream API, Optional class, default and static methods in interfaces, method references, new Date/Time API (`java.time`), and `CompletableFuture`.
Q77. What is a lambda expression?
A concise way to represent an anonymous function (a block of code that can be passed as an argument). Syntax: `(parameters) -> expression` or `(parameters) -> { statements }`. Requires a functional interface as the target type.
Q78. What is a functional interface?
An interface with exactly one abstract method. Annotated with `@FunctionalInterface` (optional but recommended). Examples: `Runnable`, `Callable`, `Comparator`, `Predicate`, `Function`, `Consumer`, `Supplier`.
Q79. What is the Stream API?
A sequence of elements supporting sequential and parallel aggregate operations. Streams do not store data — they process data from a source (collection, array, I/O). Key operations: `filter()`, `map()`, `reduce()`, `collect()`, `forEach()`, `sorted()`, `distinct()`, `limit()`.
Q80. What is the difference between `map()` and `flatMap()` in streams?
`map()` transforms each element to one output element (1-to-1). `flatMap()` transforms each element to zero or more elements and flattens the result into a single stream (1-to-many).
Q81. What is `Optional` in Java 8?
A container object that may or may not contain a non-null value. Used to avoid NullPointerException. Key methods: `of()`, `ofNullable()`, `isPresent()`, `get()`, `orElse()`, `orElseGet()`, `map()`, `filter()`.
Q82. What is a method reference?
A shorthand for a lambda expression that calls an existing method. Four types: static method reference (`ClassName::staticMethod`), instance method reference (`object::instanceMethod`), instance method of arbitrary object (`ClassName::instanceMethod`), constructor reference (`ClassName::new`).
Q83. What is the difference between `Predicate`, `Function`, `Consumer`, and `Supplier`?
- `Predicate
`: takes T, returns boolean. Used for filtering. - `Function
`: takes T, returns R. Used for transformation. - `Consumer
`: takes T, returns nothing. Used for side effects. - `Supplier
`: takes nothing, returns T. Used for lazy generation.
Q84. What is a default method in an interface?
A method with a body defined in an interface using the `default` keyword. Allows adding new methods to interfaces without breaking existing implementations. Introduced in Java 8.
Q85. What is `Collectors.groupingBy()`?
A terminal stream operation that groups elements by a classifier function into a `Map
Q86. What is the difference between `findFirst()` and `findAny()`?
`findFirst()` returns the first element in encounter order. `findAny()` returns any element (may be faster in parallel streams as it does not need to respect order).
Q87. What is `CompletableFuture`?
A class for asynchronous programming in Java 8+. Allows chaining async operations, combining multiple futures, and handling errors without blocking threads. Key methods: `supplyAsync()`, `thenApply()`, `thenCompose()`, `thenCombine()`, `exceptionally()`.
Q88. What is the new Date/Time API in Java 8?
The `java.time` package replaces the old `Date` and `Calendar` classes. Key classes: `LocalDate`, `LocalTime`, `LocalDateTime`, `ZonedDateTime`, `Duration`, `Period`, `DateTimeFormatter`. Immutable, thread-safe, and much more intuitive.
Q89. What are sealed classes in Java 17?
Classes declared with the `sealed` keyword that restrict which other classes can extend or implement them. The permitted subclasses are declared explicitly using the `permits` clause. Improves domain modelling and pattern matching.
Q90. What is a record in Java 16+?
A concise way to declare immutable data carrier classes. A record automatically generates constructor, getters, `equals()`, `hashCode()`, and `toString()` based on its components. Ideal for DTOs and value objects.
---
Section 6: Multithreading and Concurrency (Questions 91–100)
Q91. What is a thread in Java?
A thread is the smallest unit of execution within a process. Java supports multithreading — multiple threads running concurrently within the same JVM process, sharing heap memory but having their own stack.
Q92. What are the two ways to create a thread in Java?
- Extend the `Thread` class and override `run()`.
- Implement the `Runnable` interface and pass it to a `Thread` constructor. The second approach is preferred as it allows the class to extend another class.
Q93. What is the difference between `start()` and `run()`?
`start()` creates a new thread and calls `run()` in that new thread. Calling `run()` directly executes the method in the current thread — no new thread is created.
Q94. What is synchronisation in Java?
A mechanism to control access to shared resources by multiple threads. The `synchronized` keyword ensures only one thread executes a block or method at a time, preventing race conditions.
Q95. What is a deadlock?
A situation where two or more threads are blocked forever, each waiting for a resource held by the other. Prevention strategies: acquire locks in a consistent order, use timeout-based locking, use `tryLock()` from `java.util.concurrent.locks`.
Q96. What is the `volatile` keyword?
Ensures that a variable's value is always read from and written to main memory, not from a thread's local cache. Guarantees visibility but not atomicity. Use for simple flags; use `AtomicInteger` for compound operations.
Q97. What is the difference between `wait()` and `sleep()`?
`wait()` releases the lock and waits until notified (used for inter-thread communication, called on an object). `sleep()` pauses the thread for a specified time without releasing any locks.
Q98. What is an `ExecutorService`?
A higher-level thread management framework in `java.util.concurrent`. Manages a pool of threads, handles thread lifecycle, and provides `Future` objects for async results. Use `Executors.newFixedThreadPool()`, `newCachedThreadPool()`, or `newSingleThreadExecutor()`.
Q99. What is the difference between `Callable` and `Runnable`?
`Runnable` has a `run()` method that returns void and cannot throw checked exceptions. `Callable` has a `call()` method that returns a value and can throw checked exceptions. `Callable` is used with `ExecutorService.submit()` to get a `Future` result.
Q100. What is the Java Memory Model (JMM)?
The JMM defines how threads interact through memory — specifically, when writes by one thread become visible to other threads. It establishes happens-before relationships. Key rules: a write to a volatile variable happens-before every subsequent read of that variable; a thread's `start()` happens-before any action in the started thread.
---
How to Use This List for Your Java Interview in Pune
These 100 questions cover the core of what every Java interviewer at Pune IT companies — from TCS and Infosys in Hinjewadi to product companies in Kharadi and Baner — will test in a fresher interview.
Study strategy:
- Read each question and answer once without taking notes
- On the second pass, write the answer in your own words
- Practice explaining answers out loud — interviews are verbal, not written
- For Collections and Java 8, write small code examples to reinforce understanding
- Focus extra time on Q7, Q44, Q62, Q77–85 — these appear in almost every Pune Java interview
---
Prepare for Your Java Interview at Trimaya TechnoSol, Pune
At Trimaya TechnoSol, FC Road, Deccan Gymkhana, Pune, our Java Full Stack course includes dedicated interview preparation — mock technical rounds, HR rounds, aptitude practice, and live coding challenges — all modelled on real interview patterns from Pune IT companies.
Our students from Kothrud, Shivajinagar, Karve Nagar, Deccan, Paud Road, Sinhagad Road, and across Pune have cleared interviews at Persistent Systems, Zensar, Mphasis, KPIT, and dozens of product companies and startups.
Call us: +91 8237517669
Visit: Vikram Goldmine, 2nd Floor, Office No. 201, Opp. Venus Traders, FC Road, Deccan Gymkhana, Pune – 411004
WhatsApp: [wa.me/918237517669](https://wa.me/918237517669)
Book a free demo class today and see exactly how we prepare you to clear your Java interview and land the best possible package in Pune.