Java Interview Questions

Java interview questions test your understanding of object-oriented programming, the JVM, collections, concurrency, and modern Java features. Java is still one of the most common languages in backend and enterprise hiring, and interviewers expect you to explain design trade-offs, not just recall syntax. This page covers 40 real Java interview questions with answers across four formats: multiple choice, written answers, spoken responses, and live coding challenges, the same mix used in modern technical interviews.

Practice each question in your browser with no signup required. Answers stay hidden until you attempt the question: type, speak, or code your response first, then compare it against the model answer. Questions range from fundamentals for your first developer job to scenario-based questions for senior roles, so you can find the gaps in your knowledge before the real interview.

40 questions with answersLast updated: Oct 19, 2026
Start a mock interview

How to practice

  1. Choose a question. Pick any of the 40 questions. They mix multiple choice, written, spoken, and coding, the same mix a real interviewer uses.
  2. Attempt your answer. Select a multiple-choice option, type your written response, record a spoken answer, or write code in the editor.
  3. Reveal the model answer. Once you have attempted the question, the model answer unlocks so you can compare it with yours.
  4. Move to the next question. Track how many questions you have attempted with the progress bar at the top of the page.
  5. Take a mock interview. When you are ready, try a full mock technical interview on Plaicer with AI-driven follow-up questions.

Java Interview Questions and Answers

0 of 40 attempted
1Multiple choice

How does Java achieve platform independence across different operating systems?

Attempt the question first to reveal the answer.

2Written answer

Explain how Java achieves the Write Once, Run Anywhere principle through bytecode and the JVM

Attempt the question first to reveal the answer.

3Spoken answer

Describe a situation where you had to debug a NullPointerException in production and how you resolved it

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Attempt the question first to reveal the answer.

4Coding

Create a BankAccount class that handles deposits and withdrawals with thread-safe operations

public class BankAccount {
    private double balance;
    
    public BankAccount(double initialBalance) {
        this.balance = initialBalance;
    }
    
    public synchronized void deposit(double amount) {
        // Implement deposit logic
    }
    
    public synchronized void withdraw(double amount) throws InsufficientFundsException {
        // Implement withdrawal logic
    }
    
    public synchronized double getBalance() {
        return balance;
    }
}

Attempt the question first to reveal the answer.

5Multiple choice

Explain the role of the Java Virtual Machine in program execution

Attempt the question first to reveal the answer.

6Written answer

Describe how the JVM acts as an intermediary between compiled Java code and the operating system

Attempt the question first to reveal the answer.

7Spoken answer

Explain how you would approach optimizing a Java application that has memory leaks

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Attempt the question first to reveal the answer.

8Coding

Create an inventory system where products can be added, sold, and restocked

public class InventoryItem {
    private String productName;
    private int quantity;
    private double price;
    
    public InventoryItem(String productName, int quantity, double price) {
        this.productName = productName;
        this.quantity = quantity;
        this.price = price;
    }
    
    public void sell(int units) throws OutOfStockException {
        // Implement sell logic
    }
    
    public void restock(int units) {
        // Implement restock logic
    }
}

Attempt the question first to reveal the answer.

9Multiple choice

What is the Just-in-Time compiler and when does it activate during runtime?

Attempt the question first to reveal the answer.

10Written answer

Explain the compilation process from source code through bytecode to native machine code

Attempt the question first to reveal the answer.

11Spoken answer

Walk through how you would implement a thread-safe singleton pattern and why each design choice matters

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Attempt the question first to reveal the answer.

12Coding

Write a method to process data from a file with proper exception handling and resource cleanup

import java.io.*;
import java.util.*;

public class DataProcessor {
    public List<String> processFile(String filePath) {
        // Implement file reading with try-with-resources
    }
}

Attempt the question first to reveal the answer.

13Multiple choice

Describe the different memory areas that the JVM allocates for a Java application

Attempt the question first to reveal the answer.

14Written answer

Describe each memory area in the JVM and what data is stored in each

Attempt the question first to reveal the answer.

15Spoken answer

Describe the difference between using synchronized blocks versus ReentrantLock for concurrent access

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Attempt the question first to reveal the answer.

16Coding

Create a thread-safe counter that increments when incremented from multiple threads

public class ThreadSafeCounter {
    private int count = 0;
    
    public void increment() {
        // Implement thread-safe increment
    }
    
    public int getCount() {
        // Implement thread-safe read
    }
}

Attempt the question first to reveal the answer.

17Multiple choice

What responsibility does the ClassLoader component have in the JVM?

Attempt the question first to reveal the answer.

18Written answer

Explain how the ClassLoader loads classes dynamically and the types of ClassLoaders

Attempt the question first to reveal the answer.

19Spoken answer

Explain how you would design a connection pool for managing database connections efficiently

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Attempt the question first to reveal the answer.

20Coding

Write a method to parse email addresses and validate their format

import java.util.regex.*;

public class EmailValidator {
    private static final String EMAIL_REGEX = "";
    
    public boolean isValidEmail(String email) {
        // Implement validation logic
    }
}

Attempt the question first to reveal the answer.

21Multiple choice

How does JDBC enable Java applications to interact with relational databases?

Attempt the question first to reveal the answer.

22Written answer

Describe the components and steps required to connect a Java application to a database

Attempt the question first to reveal the answer.

23Spoken answer

Walk through how you would implement custom exception classes for a banking application

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Attempt the question first to reveal the answer.

24Coding

Use Java Streams to filter and transform a collection of user objects

import java.util.*;
import java.util.stream.*;

public class UserProcessor {
    public List<String> getActiveUserEmails(List<User> users) {
        // Use streams to filter and map users
    }
}

Attempt the question first to reveal the answer.

25Multiple choice

Explain the process of creating a copy of an existing object in Java

Attempt the question first to reveal the answer.

26Written answer

Distinguish between shallow copy and deep copy when cloning objects

Attempt the question first to reveal the answer.

27Spoken answer

Describe how you would migrate legacy code from ArrayList to Stream API while maintaining backward compatibility

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Attempt the question first to reveal the answer.

28Coding

Sort a list of employee records by salary in descending order using a Comparator

import java.util.*;

public class EmployeeManager {
    public List<Employee> sortBySalary(List<Employee> employees) {
        // Implement sorting with custom comparator
    }
}

Attempt the question first to reveal the answer.

29Multiple choice

How does Java handle errors and unexpected events during program execution?

Attempt the question first to reveal the answer.

30Written answer

Explain the hierarchy of exception classes and how try-catch-finally blocks work

Attempt the question first to reveal the answer.

31Spoken answer

Explain your approach to choosing between inheritance and composition when designing class hierarchies

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Attempt the question first to reveal the answer.

32Coding

Create a generic Pair class that can hold two objects of any type

public class Pair<K, V> {
    private K first;
    private V second;
    
    public Pair(K first, V second) {
        this.first = first;
        this.second = second;
    }
    
    public K getFirst() {
        return first;
    }
    
    public V getSecond() {
        return second;
    }
}

Attempt the question first to reveal the answer.

33Multiple choice

How do compile-time and runtime exceptions differ in their handling requirements?

Attempt the question first to reveal the answer.

34Written answer

Compare how checked and unchecked exceptions are handled differently by the compiler

Attempt the question first to reveal the answer.

35Spoken answer

Describe how you would implement proper garbage collection tuning for a high-throughput application

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Attempt the question first to reveal the answer.

36Coding

Implement a thread-safe singleton for database connection management

public class DatabaseConnection {
    // Implement singleton pattern
    
    private DatabaseConnection() {
    }
    
    public static DatabaseConnection getInstance() {
        // Return singleton instance
    }
}

Attempt the question first to reveal the answer.

37Multiple choice

How does multithreading enable concurrent execution within a single Java process?

Attempt the question first to reveal the answer.

38Written answer

Explain the thread lifecycle and how threads communicate and synchronize with each other

Attempt the question first to reveal the answer.

39Spoken answer

Walk through how you would handle concurrent modifications to a shared collection in a multithreaded system

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Attempt the question first to reveal the answer.

40Coding

Implement a custom Iterator for a collection that filters elements during iteration

import java.util.*;

public class FilteredList<T> implements Iterable<T> {
    private List<T> items;
    
    public FilteredList(List<T> items) {
        this.items = items;
    }
    
    @Override
    public Iterator<T> iterator() {
        // Return custom iterator that filters
    }
}

Attempt the question first to reveal the answer.

Topics covered

  • JVM fundamentals: platform independence, bytecode, the JIT compiler
  • JVM memory areas and garbage collection tuning
  • Class loading: the ClassLoader and dynamic loading
  • Object-oriented design: inheritance vs composition, custom classes
  • Exception handling: checked vs unchecked, try-catch-finally, try-with-resources
  • Multithreading: thread lifecycle, synchronized, ReentrantLock, thread safety
  • Concurrent collections and safe shared state
  • Streams and Comparators: filtering, mapping, sorting
  • Generics and custom iterators
  • Design patterns and databases: Singleton, connection pooling, JDBC

Frequently asked questions

How many Java interview questions are on this page?
40 real Java interview questions across four formats: multiple choice (10), written answer (10), spoken answer (10), and coding (10).
Do I need to sign up to practice?
No. All 40 questions and model answers are free with no signup. You attempt each question first, and the model answer unlocks once you have engaged.
Who are these Java interview questions for?
Developers preparing for Java technical interviews at any level, from first job to senior engineer roles. Questions cover fundamentals through real-world scenarios.
What topics do the Java questions cover?
The questions cover JVM fundamentals, memory and garbage collection, and class loading. They also test object-oriented design, exception handling, and multithreading. Coding tasks include streams, generics, and thread-safe classes.
Can I practice coding questions in the browser?
Yes. Coding questions include starter code in an in-browser editor, so you can write your solution without installing anything.
How often are the questions updated?
The question bank is reviewed regularly and updated to reflect current Java interview patterns.
Can I take a full mock interview?
Yes. Plaicer's mock technical interview walks you through a realistic 30 to 45 minute interview with AI-driven follow-up questions.
Should I prepare for Java 8+ features or older versions?
Focus on modern Java (8 and later). Questions cover streams and Comparators alongside core OOP, the JVM, and multithreading.

Pick your language

View all programming interview questions

Need to run some Java code first?

Online Java Compiler

Reading answers is not the same as giving them. Sit a full mock interview and get scored on how you actually explain them.

Try a mock interview