Interview questions · Tech stack

Java for Freshers Interview Questions & Answers (2026)

Freshers' Java interviews test core language fundamentals, object‑oriented principles, basic APIs, and problem‑solving ability. Candidates succeed by mastering syntax, explaining why constructs work, and demonstrating clean code practices. This guide provides the most common questions, the reasoning interviewers expect, common pitfalls, a focused study plan, and quick FAQs to boost confidence before the interview.

21 questions · updated Aug 29, 2026

Quick facts

Typical roundsPhone screen, technical coding test, on‑site or virtual interview with HR and senior developer
Key topicsOOP concepts, collections, exception handling, basic multithreading, Java 8 features
Success metricClarity of explanation, correct syntax, and ability to write simple, bug‑free code on a whiteboard

Questions

Beginner

What is the difference between JDK, JRE, and JVM?

JDK (Java Development Kit) includes the compiler, debugger, and tools needed to develop Java applications. JRE (Java Runtime Environment) contains the JVM and core libraries required to run Java programs but lacks development tools. JVM (Java Virtual Machine) is the runtime engine that executes bytecode, providing platform independence. Interviewers look for this layered view to confirm you understand the development‑runtime separation and can set up environments correctly.

GoogleMicrosoftAmazon

Explain the concept of OOP and its four main principles.

Object‑Oriented Programming models software as objects that combine state and behavior. The four pillars are Encapsulation (bundling data with methods and restricting direct access), Inheritance (creating new classes from existing ones to reuse code), Polymorphism (using a single interface to represent different underlying forms, typically via method overriding or overloading), and Abstraction (exposing only essential features while hiding complex implementation). Interviewers expect you to map each principle to a real‑world example.

IBMInfosysTCS

What is a constructor and how does it differ from a method?

A constructor is a special block invoked when an object is created; it has no return type and shares the class name. Unlike regular methods, constructors cannot be called directly after object creation and are used to initialize instance variables. Overloading constructors allows different initialization paths. Interviewers want to see you understand object lifecycle and that constructors set up invariants before the object is used.

AccentureCapgemini

How does the 'static' keyword affect variables and methods?

Static members belong to the class rather than any instance, meaning a single copy is shared across all objects. Static variables are initialized once when the class loads, and static methods can be called without creating an object, often used for utility functions. Interviewers look for awareness of memory implications and thread‑safety concerns when using static state.

WiproCognizant

What is the purpose of the 'final' keyword?

Final can be applied to classes, methods, or variables. A final class cannot be subclassed, a final method cannot be overridden, and a final variable's value cannot be changed after initialization. This enforces immutability and design contracts, which interviewers appreciate as a sign you understand how to protect critical code from unintended modification.

OracleAdobe

Describe the difference between '==', '.equals()', and 'compareTo()' for strings.

'==' checks reference equality, i.e., whether two variables point to the same object in memory. '.equals()' compares the logical content of two strings, returning true if characters match. 'compareTo()' provides ordering; it returns 0 when strings are equal, a negative number if the first is lexicographically smaller, and positive if larger. Interviewers expect you to choose the appropriate method based on intent.

NetflixUber

Intermediate

What is autoboxing and unboxing? Give an example.

Autoboxing automatically converts a primitive type to its wrapper class (e.g., int to Integer) when an object is required, while unboxing does the reverse. Example: Integer i = 5; // autoboxing int 5 to Integer. int j = i; // unboxing Integer back to int. Interviewers check that you understand this convenience feature and its potential for NullPointerException when unboxing a null wrapper.

Integer i = 5; int j = i;
PayPalShopify

Explain the difference between ArrayList and LinkedList.

ArrayList is backed by a dynamic array, offering O(1) random access but O(n) insertions/removals in the middle due to shifting. LinkedList uses a doubly‑linked list, providing O(1) insertions/removals at ends and O(n) traversal for random access. Interviewers want you to discuss trade‑offs, memory overhead of node objects, and typical use‑cases such as frequent inserts versus frequent reads.

SpotifySnapchat

What is the Java Collections Framework hierarchy?

At the top is the Collection interface, extended by List, Set, and Queue. List includes ArrayList, LinkedList, and Vector; Set includes HashSet, LinkedHashSet, and TreeSet; Queue includes PriorityQueue and Deque implementations. Map sits alongside Collection, with HashMap, LinkedHashMap, and TreeMap as common implementations. Interviewers expect you to name key interfaces and illustrate why you would choose one implementation over another.

AdobeSquare

How does the 'try‑with‑resources' statement work?

Introduced in Java 7, try‑with‑resources automatically closes any object that implements AutoCloseable at the end of the block, even if an exception occurs. The syntax declares the resource inside parentheses, e.g., try (BufferedReader br = new BufferedReader(...)) { … }. Interviewers look for understanding of resource leaks and the benefit of deterministic cleanup without a finally block.

try (BufferedReader br = new BufferedReader(new FileReader("file.txt"))) { /* use br */ }
LinkedInTwitter

What is the difference between HashMap and Hashtable?

Both store key‑value pairs, but HashMap is unsynchronized, allowing null keys and values, and generally offers better performance. Hashtable is synchronized, disallowing nulls, and is considered legacy. Interviewers expect you to mention thread‑safety concerns and why modern code prefers ConcurrentHashMap for concurrent scenarios.

eBayPayPal

Explain the concept of generics and why they are useful.

Generics enable type‑safe collections by allowing classes and methods to operate on objects of a specified type without casting. For example, List<String> ensures only strings are stored, catching type errors at compile time. They also improve readability and reduce runtime ClassCastException. Interviewers want to see you articulate compile‑time safety and how generics support reusable code.

DropboxGitHub

What is the difference between 'throw' and 'throws'?

'throw' is a statement used inside a method to actually raise an exception object. 'throws' is part of a method signature indicating that the method may propagate specified checked exceptions to its caller. Interviewers check that you understand exception flow control and the need to declare checked exceptions for compile‑time checking.

public void read() throws IOException { throw new IOException("File missing"); }
CiscoIntel

Advanced

How does the Java memory model handle synchronization?

The Java Memory Model (JMM) defines how threads interact through memory and ensures visibility and ordering guarantees. Synchronization via the 'synchronized' keyword establishes a happens‑before relationship: a thread releasing a lock flushes writes to main memory, and a thread acquiring the same lock sees those writes. Volatile variables provide similar visibility guarantees without mutual exclusion. Interviewers expect you to discuss atomicity, visibility, and ordering.

GoogleMicrosoft

What are the differences between 'synchronized' methods and synchronized blocks?

A synchronized method locks on the object's intrinsic lock (or class lock for static methods), affecting the entire method. A synchronized block allows finer‑grained control by locking on a specific object, reducing contention and improving concurrency. Interviewers look for awareness of lock scope, performance impact, and scenarios where a block is preferable to avoid unnecessary blocking.

AmazonNetflix

Explain the purpose and usage of the 'volatile' keyword.

Volatile tells the JVM that a variable's value may be modified by multiple threads. Reads/writes to a volatile variable are directly from/to main memory, guaranteeing visibility without locking. However, volatile does not provide atomicity for compound actions. Interviewers expect you to discuss when volatile is appropriate (e.g., flags) and its limitations compared to synchronized blocks.

OracleIBM

What is a deadlock and how can you prevent it?

A deadlock occurs when two or more threads hold locks that the others need, causing a circular wait. Prevention strategies include acquiring locks in a consistent order, using timeout-based lock attempts, or employing higher‑level concurrency utilities like java.util.concurrent locks. Interviewers want you to demonstrate awareness of lock ordering and design patterns that avoid deadlock.

MicrosoftGoogle

Describe the difference between Callable and Runnable.

Runnable's run() method returns void and cannot throw checked exceptions, making it suitable for tasks that don't produce a result. Callable's call() method returns a generic result and can throw exceptions, allowing the task's outcome to be retrieved via Future. Interviewers expect you to explain when you need a result or exception handling, justifying the choice.

AmazonUber

What is the purpose of the Java Stream API and how does it differ from traditional loops?

Streams provide a functional, declarative way to process collections, supporting lazy evaluation, pipelining, and parallel execution. Unlike explicit loops, streams separate the 'what' from the 'how', enabling concise code and potential performance gains via parallel streams. Interviewers look for understanding of intermediate vs. terminal operations and when streams improve readability without sacrificing control.

NetflixSpotify

Explain the concept of lambda expressions and functional interfaces.

Lambda expressions provide a concise syntax for implementing functional interfaces—interfaces with a single abstract method. For example, (x) -> x * x implements Function<Integer,Integer>. Lambdas enable passing behavior as data, facilitating higher‑order functions and stream operations. Interviewers expect you to discuss type inference, capture of effectively final variables, and the impact on readability and maintainability.

GoogleMicrosoft

What is the difference between shallow copy and deep copy?

A shallow copy duplicates the object's top‑level structure, copying references to nested objects, so changes to nested objects affect both copies. A deep copy recursively clones all referenced objects, producing an independent replica. Interviewers want you to mention Cloneable, copy constructors, and serialization as techniques for deep copying, and when each is appropriate.

OracleAdobe

Common mistakes

  • Confusing '==' with .equals() for object comparison
  • Neglecting to initialize collections before use
  • Using raw types instead of generics, leading to unchecked warnings
  • Overlooking exception handling and declaring throws unnecessarily
  • Misunderstanding thread safety of static fields

Study plan

  1. Review core language syntax and OOP fundamentals for 2 days
  2. Practice collection API usage and common algorithms for 3 days
  3. Master exception handling, I/O, and Java 8 features for 2 days
  4. Solve multithreading and concurrency problems for 2 days
  5. Mock interview with timed coding exercises for 1 day

FAQ

How many Java questions are typically asked in a fresher interview?

Most entry‑level interviews include 8‑12 Java questions, covering basics, collections, and a simple coding problem. The exact number varies by company but stays within that range.

Do I need to know Java 8 features for a freshers interview?

Yes, interviewers often expect familiarity with lambda expressions, streams, and functional interfaces, as they are now standard in most Java codebases.

What is the best way to demonstrate problem‑solving skills?

Explain your thought process aloud, write clean code on the whiteboard, and discuss edge cases and time‑space complexity before coding.

Should I memorize API method signatures?

Understanding the purpose and typical usage of key methods is more important than memorizing exact signatures; you can reference documentation during open‑book assessments.

How important is OOP design in a fresher interview?

Very important; interviewers assess whether you can model real‑world entities using classes, inheritance, and encapsulation, which shows readiness for larger codebases.

Related

Ready for your next interview?

Download MiPrep AI. Load your resume and the job description. Show up ready.

Free tier · No credit card · macOS 14+ · Windows 10+

Free tier · No credit card · Runs on your Mac or Windows machine