- Cyber Success
- June 12, 2026
- Articles
Top 100 Java Interview Questions and Answers for Freshers in 2026
Java has not just survived the rise of newer languages – it has thrived. It powers the back-end of banks, e-commerce giants, Android applications, and enterprise systems worldwide. If you are stepping into the job market as a fresh developer in 2025, knowing the right java interview questions for freshers is the single most impactful thing you can do before walking into that interview room.
Most freshers make the same mistake: they memorize definitions but cannot explain the “why” behind them. Interviewers can spot this instantly. They want to see that you understand how Java actually works, not just what the textbook says. This guide covers 100 essential java interview questions and answers organized by topic – from basic syntax to multithreading – so you walk in prepared, confident, and able to hold a real technical conversation.
Why Java Interview Questions for Freshers Are Different from Experienced Roles
When you are a fresher, the interviewer is not expecting five years of production experience. What they are testing is your understanding of core java interview questions – the foundational concepts that will determine whether you can learn quickly on the job. The focus areas are predictable: object-oriented principles, data structures via collections, exception handling, basic concurrency, and string manipulation.
Experienced developers get grilled on system design, performance tuning, and architectural decisions. Freshers get tested on depth of conceptual understanding. The good news: these topics are finite and learnable. This guide maps all of them clearly.
Interview Stage | What They Test | Time Allocated |
Written / Online Round | Basic Java syntax, logic, output questions | 30-45 min |
Technical Round 1 | OOPs, Collections, Exception Handling, Strings | 45-60 min |
Technical Round 2 | Data Structures, Problem Solving, Core Java Coding | 60 min |
HR Round | Communication, Java project interest, career goals | 20-30 min |
Core Java Interview Questions and Answers Every Fresher Must Know
These are the questions that appear in almost every fresher-level Java interview. Get these right and you have covered the bulk of what interviewers expect from a new graduate.
Basic Java Syntax and Data Types – java interview questions and answers
Question | Answer |
What is Java and why is it platform-independent? | Java compiles source code into bytecode, which runs on the Java Virtual Machine (JVM). Since the JVM is available on Windows, Linux, Mac, and other platforms, the same compiled program runs everywhere without recompilation. This is the famous ‘Write Once, Run Anywhere’ property. |
What is the difference between JDK, JRE, and JVM? | JVM (Java Virtual Machine) executes bytecode at runtime. JRE (Java Runtime Environment) contains the JVM plus standard libraries needed to run Java programs. JDK (Java Development Kit) includes the JRE plus development tools like the javac compiler. To develop: use JDK. To only run: use JRE. |
What are primitive data types in Java? | Java has 8 primitive types: byte (8-bit), short (16-bit), int (32-bit), long (64-bit), float (32-bit decimal), double (64-bit decimal), char (16-bit Unicode), and boolean (true/false). These are stored directly in stack memory, not as objects, making them faster than wrapper classes. |
What is the difference between int and Integer? | int is a primitive data type that stores a raw number directly in memory. Integer is a wrapper class (object) that wraps an int value and provides utility methods like parseInt(), compareTo(), and MAX_VALUE. Integer is needed when working with collections like ArrayList, which cannot store primitives. |
What does the static keyword mean in Java? | static means the member belongs to the class itself, not to any specific object instance. A static variable is shared across all instances. A static method can be called without creating an object. The main method is static because the JVM needs to call it before any object is created. |
What is the difference between == and .equals() in Java? | == compares memory references (addresses) for objects, so it checks if two variables point to the exact same object. .equals() compares the actual content or value. For Strings: “hello” == “hello” may return false if the strings are in different memory locations, but “hello”.equals(“hello”) always returns true. |
OOPs Concepts in Java Interview Questions – The 4 Pillars
Object-Oriented Programming (OOP) forms the backbone of Java. Almost every core java interview question touches on one of its four pillars. Do not just define them – explain them with small examples.
OOPs Concept | Plain Definition | Real-World Example |
Encapsulation | Wrapping data (variables) and methods into one unit (class) and restricting direct access using access modifiers. | A bank account class with private balance and public deposit()/withdraw() methods – you cannot directly change the balance. |
Inheritance | A child class inherits properties and behaviors from a parent class, enabling code reuse. | A Dog class extends Animal class and inherits breathe() and eat() methods while adding its own bark() method. |
Polymorphism | One method or object behaving differently in different contexts. Two types: compile-time (method overloading) and runtime (method overriding). | A Shape class with a draw() method. Circle, Rectangle, and Triangle each override draw() differently. |
Abstraction | Hiding implementation details and showing only essential features to the user. | You use a TV remote without knowing the internal circuit logic. The interface (buttons) is exposed; the complexity is hidden. |
Interview Tip: When asked about OOPs, always follow with a one-line example. ‘Encapsulation is wrapping data in a class. For example, a BankAccount class keeps balance private and exposes only deposit() and withdraw().’
Question | Answer |
What is the difference between method overloading and method overriding? | Overloading: same method name, different parameters, happens in the same class (compile-time polymorphism). Overriding: a child class provides its own implementation of a parent’s method with the same signature (runtime polymorphism). Overloading is resolved at compile time; overriding is resolved at runtime. |
What is an abstract class in Java? | An abstract class cannot be instantiated. It can have abstract methods (no body) that must be implemented by subclasses, and concrete methods with full implementations. Use abstract classes when subclasses share common behavior but need to implement certain methods differently. |
What is an interface in Java? | An interface is a contract that defines method signatures without implementations. A class that implements an interface must provide implementations for all its methods. From Java 8 onward, interfaces can also have default and static methods with implementations. A class can implement multiple interfaces, enabling multiple inheritance of type. |
What is the difference between abstract class and interface? | Abstract class supports constructors, instance variables, and partial implementation. A class can extend only one abstract class. Interface supports only constants and abstract methods (pre-Java 8) and can be implemented by multiple classes. Use abstract class for IS-A relationships with shared code. Use interface for CAN-DO behavior contracts. |
Java Constructor Interview Questions
Question | Answer |
What is a constructor in Java? | A constructor is a special method that shares the class name and runs automatically when an object is created. It initializes object state. Unlike regular methods, constructors have no return type. If you do not write one, Java provides a default no-argument constructor automatically. |
What is constructor overloading? | Constructor overloading means defining multiple constructors in the same class with different parameter lists. This lets you create objects in different ways. Example: Person() creates a person with defaults, Person(String name) sets name only, Person(String name, int age) sets both. |
Can a constructor be private? | Yes. A private constructor prevents object creation from outside the class. This is used in the Singleton design pattern to ensure only one instance of a class exists. The class itself can still create an instance using a static factory method. |
What is constructor chaining? | Constructor chaining is calling one constructor from another. In the same class, use this() to call another constructor. In a subclass, use super() to call the parent class constructor. Constructor chaining avoids code duplication during initialization. |
Java Collections Interview Questions – What Hiring Managers Actually Ask
The Java Collections Framework is one of the most tested areas in core java interview questions for freshers. You need to know not just what each data structure does, but when to use it and how it works internally.
Collection | Backed By | Ordered? | Allows Duplicates? | Thread-Safe? | Best Use Case |
ArrayList | Dynamic array | Yes (insertion order) | Yes | No | Fast random access, frequent reads |
LinkedList | Doubly linked list | Yes (insertion order) | Yes | No | Frequent insertions/deletions |
HashSet | HashMap internally | No | No | No | Unique elements, fast lookup |
LinkedHashSet | LinkedHashMap | Yes (insertion order) | No | No | Unique + ordered elements |
TreeSet | Red-Black tree | Yes (sorted) | No | No | Sorted unique elements |
HashMap | Array of linked lists | No | Keys: No, Values: Yes | No | Key-value pairs, fast lookup |
LinkedHashMap | HashMap + linked list | Yes (insertion order) | Keys: No | No | LRU cache, ordered map |
TreeMap | Red-Black tree | Yes (sorted by key) | Keys: No | No | Sorted key-value pairs |
Question | Answer |
What is the difference between ArrayList and LinkedList? | ArrayList uses a resizable array internally. Random access (get by index) is O(1) but insertion/deletion in the middle is O(n) because elements must shift. LinkedList uses doubly linked nodes. Random access is O(n) but insertion/deletion at any position is O(1) once you have the reference. Use ArrayList for most cases; LinkedList when you do lots of front/middle inserts. |
How does HashMap work internally? | HashMap stores key-value pairs in an array of buckets. When you put a key, it calls hashCode() on the key to find the bucket index, then stores the entry there. If two keys hash to the same bucket (collision), they are stored in a linked list at that bucket (or a tree in Java 8+ for 8+ elements). Get retrieves by computing hashCode again, then uses equals() to find the exact key. |
What is the difference between HashMap and Hashtable? | HashMap is not thread-safe and allows one null key and multiple null values. Hashtable is synchronized (thread-safe) and does not allow null keys or values. Hashtable is a legacy class from Java 1.0. For thread safety today, use ConcurrentHashMap instead of Hashtable, as it is far more performant. |
What is the difference between Comparable and Comparator? | Comparable (java.lang) is implemented by the class itself. It defines the natural ordering via compareTo(). Comparator (java.util) is an external comparison strategy. Use Comparable when there is one natural sort order (e.g., String by alphabetic order). Use Comparator when you need multiple sort orders or cannot modify the class (e.g., sort Employee by salary OR name). |
Java Exception Handling Interview Questions Explained Simply
Exception handling is mandatory knowledge for any java fresher interview preparation. It shows you understand how to write robust, fault-tolerant programs.
Question | Answer |
What is an exception in Java? | An exception is an event that disrupts the normal flow of a program during runtime. Java handles exceptions through the try-catch-finally mechanism. There are checked exceptions (must be handled at compile time, e.g., IOException) and unchecked exceptions (occur at runtime, e.g., NullPointerException, ArrayIndexOutOfBoundsException). |
What is the difference between throw and throws? | throw is used to explicitly throw an exception from a method. throws is used in a method signature to declare that the method might throw certain checked exceptions, warning the caller to handle them. Example: public void readFile() throws IOException uses throws; inside the method, throw new IOException() uses throw. |
What is the finally block? | The finally block always executes regardless of whether an exception occurred or was caught. It is used to release resources like database connections, file handles, or network sockets. With Java 7+, you can use try-with-resources, which automatically closes resources that implement AutoCloseable. |
What is a custom exception? | A custom (user-defined) exception is created by extending Exception (for checked) or RuntimeException (for unchecked). Example: class InsufficientBalanceException extends RuntimeException. This lets you create meaningful, domain-specific errors that communicate intent better than generic exceptions. |
What is NullPointerException and how do you prevent it? | NullPointerException (NPE) occurs when you call a method or access a field on a null reference. Prevention: always check if an object is null before use, use Optional<T> (Java 8+) to represent potentially absent values, and use @NonNull annotations. Modern IDEs also flag potential NPE locations at compile time. |
Java Multithreading Interview Questions for Beginners
Java multithreading is a common topic in java interview questions and answers – even for freshers. You need not be an expert but you must understand the core concepts.
Question | Answer |
What is a Thread in Java? | A thread is the smallest unit of execution within a process. Java supports multithreading natively through the java.lang.Thread class and Runnable interface. Multiple threads share the same memory space, making them lighter than processes. Java programs always start with one thread – the main thread – and can spawn more. |
What are the two ways to create a Thread in Java? | First: extend the Thread class and override run(). Second: implement the Runnable interface and pass it to a Thread constructor. The Runnable approach is preferred because Java does not support multiple class inheritance, so implementing Runnable keeps your class free to extend another class. Callable (from Executors) is a third way if you need a return value. |
What is the synchronized keyword? | synchronized prevents multiple threads from accessing the same block or method simultaneously. When a thread enters a synchronized block, it acquires a lock on the object. Other threads must wait until the lock is released. This prevents race conditions but can reduce performance if overused. Prefer higher-level java.util.concurrent utilities for complex scenarios. |
What is the difference between wait() and sleep()? | wait() is an Object method that releases the lock and waits until another thread calls notify() or notifyAll(). It is used for thread communication. sleep() is a Thread method that pauses execution for a specified time without releasing any locks. Both can throw InterruptedException. Key difference: wait() releases the lock; sleep() does not. |
What is deadlock? | Deadlock occurs when two or more threads are each waiting for a lock that another thread holds, creating a circular dependency where no thread can proceed. Example: Thread A holds Lock 1 and waits for Lock 2; Thread B holds Lock 2 and waits for Lock 1. Prevention strategies: consistent lock ordering, lock timeout with tryLock(), and avoiding nested locks when possible. |
Java String Interview Questions You Cannot Afford to Miss
Strings appear in nearly every java coding interview question. The String class has unique behavior in Java that trips up many freshers.
Question | Answer |
Why is String immutable in Java? | String objects cannot be changed after creation. Any operation like concat() or replace() creates a new String object. Immutability provides security (strings used as class names, database URLs cannot be tampered with), allows safe sharing across threads without synchronization, and enables the String Pool optimization where identical literals share one object. |
What is the String Pool? | The String Pool (String Intern Pool) is a special memory area in the Java heap that stores unique String literals. When you write String s = “hello”, Java checks the pool first. If “hello” already exists, it reuses that object instead of creating a new one. This saves memory. Using new String(“hello”) bypasses the pool and creates a new object always. |
What is the difference between String, StringBuilder, and StringBuffer? | String is immutable – each modification creates a new object. StringBuilder is mutable and faster for string manipulation but not thread-safe. StringBuffer is mutable and thread-safe because its methods are synchronized, but slower. Rule: use String for read-only values, StringBuilder for single-thread string building, StringBuffer only when thread safety is required. |
How do you reverse a String in Java? | Common approach: new StringBuilder(str).reverse().toString(). Manual approach: iterate from last index to 0, appending each char to a StringBuilder. Alternatively, convert to char array, swap elements from both ends meeting in the middle. Interviewers often follow up with ‘without using reverse()’ – know the manual char-swap approach. |
What is the difference between String.length() and String.length for arrays? | String.length() is a method (parentheses required) that returns the number of characters in a String. Arrays use .length as a property (no parentheses). ArrayList and other collections use .size(). This distinction is a classic gotcha question. Interviewers test whether you instinctively know the correct accessor for each type. |
Java Interface vs Abstract Class – Key Interview Questions
The java interface vs abstract class interview question is almost guaranteed to appear. Here is how to answer it with nuance.
Feature | Abstract Class | Interface |
Can have constructor | Yes | No |
Instance variables | Yes | No (only static final constants) |
Multiple inheritance | No (only one class can be extended) | Yes (a class can implement many interfaces) |
Default methods | Yes (regular methods) | Yes, from Java 8 onward |
Access modifiers | All types allowed | Only public (pre-Java 9) |
When to use | Shared code + IS-A relationship | Shared contract + CAN-DO behavior |
Question | Answer |
What are default methods in interfaces (Java 8)? | Before Java 8, adding a new method to an interface broke all implementing classes. Default methods solve this: they have an implementation in the interface itself using the default keyword. Implementing classes inherit the default implementation but can override it. This enabled the Java 8 Streams API to add methods to Collection interfaces without breaking existing code. |
Can an interface have a constructor? | No. Interfaces cannot be instantiated and do not have constructors. You cannot create an object of an interface directly – you create an object of a class that implements the interface. However, interfaces can have static initializers (static blocks) in Java 9+. |
What is a Functional Interface? | A functional interface has exactly one abstract method. It can be used as the target for lambda expressions and method references. Java 8 introduced the @FunctionalInterface annotation. Examples include Runnable (run()), Comparator (compare()), and the new java.util.function interfaces like Predicate, Function, Consumer, and Supplier. |
Java 8+ Features in Core Java Interview Questions
Java 8 was a major release and interviewers frequently ask freshers about its key features. Even if your college course covered Java 7, you need to know these for 2025 interviews.
Java 8 Feature | What It Does | Simple Example |
Lambda Expressions | Concise anonymous functions that implement functional interfaces, eliminating the need for anonymous classes. | list.forEach(s -> System.out.println(s)); |
Stream API | Functional-style operations on collections: filter, map, reduce, collect. Supports parallel processing easily. | list.stream().filter(s->s.startsWith(“A”)).collect(Collectors.toList()); |
Optional<T> | A container that may or may not contain a non-null value. Avoids NullPointerException explicitly. | Optional.ofNullable(name).orElse(“Unknown”); |
Default Methods | Methods with bodies in interfaces. Enables backwards-compatible API evolution. | interface Greet { default String hello() { return “Hi”; } } |
Method References | Shorthand for lambdas that call an existing method. | list.forEach(System.out::println); |
Date/Time API | java.time package replaces the buggy Date and Calendar classes. | LocalDate.now() / LocalDateTime.now() |
Java Inheritance Interview Questions with Clear Explanations
Java inheritance questions test your understanding of IS-A relationships, the super keyword, and how method resolution works at runtime.
Question | Answer |
What is single, multilevel, and hierarchical inheritance? | Single: one child extends one parent (class Dog extends Animal). Multilevel: chain of inheritance (class Puppy extends Dog extends Animal). Hierarchical: multiple classes extend one parent (Dog and Cat both extend Animal). Java does NOT support multiple class inheritance (one class extending two classes) to avoid the Diamond Problem. |
What is the super keyword? | super refers to the immediate parent class. Use super() in a constructor to call the parent constructor. Use super.methodName() to call an overridden parent method. Use super.field to access a parent field hidden by a child field with the same name. The JVM automatically calls super() as the first statement if you do not write it explicitly. |
What is method hiding vs method overriding? | Method overriding applies to instance methods: a child class provides a new implementation for a parent method. The version called depends on the actual object type at runtime. Method hiding applies to static methods: a child class can define a static method with the same signature as the parent. The version called depends on the reference type at compile time, not the actual object. |
Can we override a private or static method? | No to both. Private methods are not inherited and cannot be overridden. Static methods are class-level, not instance-level; if a child defines the same static method, it is hiding, not overriding. The @Override annotation on such methods causes a compile error, which is the correct feedback. |
Java Interview Preparation Guide – 30-Day Roadmap for Freshers
Java fresher interview preparation does not need to take months. A focused 30-day plan covering the right topics in the right order is enough to clear most fresher-level technical rounds.
Week | Focus Area | Topics to Cover | Practice Goal |
Week 1 | Java Basics & OOPs | Syntax, data types, control flow, all 4 OOPs pillars, constructors, static vs instance | Write a mini banking system class hierarchy |
Week 2 | Collections & Strings | List, Set, Map implementations, Iterator, Comparable vs Comparator, String immutability, StringBuilder | Implement a word frequency counter using HashMap |
Week 3 | Exception Handling & I/O | Checked vs unchecked, try-catch-finally, custom exceptions, File I/O basics, try-with-resources | Build a file reader with proper exception handling |
Week 4 | Multithreading & Java 8 | Thread creation, synchronization, deadlock, Lambda, Streams, Optional, Date/Time API | Implement a thread-safe counter; rewrite using Streams |
Daily practice resources for java interview tips for freshers:
- LeetCode Easy problems: 1-2 per day for coding logic
- GeeksforGeeks Java: read one topic article daily
- Mock interviews: record yourself answering 5 questions aloud
- Flashcards: create cards for definitions you keep forgetting
Frequently Asked Questions – Java Interview Questions for Freshers
FAQ Question | Answer |
How many Java interview questions are typically asked in a fresher interview? | Most fresher technical rounds include 10-15 questions covering OOPs, Collections, Exception Handling, and basic coding. Some companies add a written test of 20-30 MCQs before the technical interview. Knowing the top 50-60 concepts deeply is more valuable than memorizing 200 surface-level answers. |
Should freshers know Java 8 features for interviews? | Yes. In 2025, Java 8 is considered a baseline expectation, not an advanced topic. Lambda expressions, Streams, and Optional are asked in almost all fresher interviews at product companies. At service companies the focus may still be Java basics, but knowing Java 8 features gives you a clear competitive edge. |
Is it okay to say ‘I don’t know’ in a Java interview? | Yes, but with a follow-up. Saying ‘I don’t know this exact API but here is how I would approach figuring it out’ shows intellectual honesty and problem-solving mindset. Never guess and state it as fact – interviewers test whether you genuinely know something or are bluffing. Honesty is respected. |
How important is OOPs in Java fresher interviews? | OOPs is the single most tested topic in java interview questions for freshers. Expect 3-5 direct OOPs questions in every technical round. You must be able to explain each of the four pillars with a concrete example, distinguish overloading vs overriding, and explain when to use abstract class vs interface. |
What Java version should freshers focus on? | Learn core Java up to Java 11 (Long-Term Support version). This covers all OOPs, Collections, Java 8 features, and modules (Java 9). Being aware of Java 17 and Java 21 LTS improvements is a bonus. Most enterprise projects still run Java 11 or 17, so mastering these versions covers real-world expectations. |
Can you recommend a revision strategy the night before a Java interview? | Do not try to learn new topics. Review your flashcards for OOPs, Collections comparisons, and exception hierarchy. Re-read 5-10 questions you found hardest during your prep. Do one easy LeetCode problem to warm up your coding brain. Sleep 7-8 hours. A rested, focused mind outperforms a cramming session every time. |

