Java Interview Questions: What Actually Gets Asked (and Why)

Most Java job postings get 200+ applicants. The phone screen is designed to cut that to 10. Interviewers aren't trying to trick you — they're running the same 30-question script they've used for three years, looking for candidates who understand why something works, not just that it does. This guide covers the Java interview questions that appear most often, with the level of answer that actually passes a screen.

Core Java Interview Questions

These come up in virtually every Java role, from junior to senior. If you can't answer these cold, you'll struggle before you even reach the technical deep-dive.

What is the difference between == and .equals()?

== compares object references (memory addresses). .equals() compares content, assuming the class has overridden it. String s1 = new String("hello") and String s2 = new String("hello") will return false for s1 == s2 but true for s1.equals(s2). String literals from the pool can fool you — "hello" == "hello" is true due to interning. Never use == on Strings in production code.

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

The JVM (Java Virtual Machine) executes bytecode. The JRE (Java Runtime Environment) is the JVM plus the standard libraries you need to run a program. The JDK (Java Development Kit) includes the JRE plus the compiler (javac) and tools like jdb and javap. You develop with the JDK, ship with the JRE, and the JVM is what actually runs at runtime. Newer JDK versions (17+) have largely collapsed this distinction — you can compile and run from one installation.

Explain checked vs. unchecked exceptions

Checked exceptions extend Exception (but not RuntimeException) and the compiler forces you to handle or declare them — IOException, SQLException. Unchecked exceptions extend RuntimeException and represent programming errors: NullPointerException, ArrayIndexOutOfBoundsException. The ongoing debate in Java circles is that checked exceptions tend to leak implementation details into APIs. Most modern frameworks (Spring, for example) deliberately wrap checked exceptions in unchecked ones for this reason.

What is autoboxing and when does it bite you?

Autoboxing is the automatic conversion between primitives (int, long) and their wrapper classes (Integer, Long). It bites you in two ways: performance (boxing allocates heap objects in tight loops) and null pointer exceptions (Integer i = null; int x = i; throws NPE at unboxing). A classic interview trap is Integer a = 127; Integer b = 127; a == b returns true because the JVM caches Integer values from -128 to 127. Change it to 128 and == returns false.

Object-Oriented Java Interview Questions

OOP questions sound basic but interviewers use them to probe depth. "Explain polymorphism" is a warmup; the follow-up is what matters.

Abstract class vs. interface — what's the real difference in Java 8+?

Before Java 8, the clean answer was: abstract classes have state and implementation, interfaces are pure contracts. Java 8 blurred this with default and static methods on interfaces. The remaining practical difference: a class can implement multiple interfaces but only extend one abstract class (single inheritance). Use an interface when you're defining a capability (Comparable, Serializable). Use an abstract class when you have shared state or a partial implementation that subclasses build on.

What is method overloading vs. overriding?

Overloading is compile-time polymorphism — multiple methods with the same name, different parameter signatures, resolved by the compiler. Overriding is runtime polymorphism — a subclass provides its own implementation of an inherited method, resolved at runtime via the vtable. The @Override annotation is worth using every time; it causes a compile error if you accidentally overload instead of override (a common source of bugs).

Explain the SOLID principles

Senior roles will ask for examples, not just definitions:

  • Single Responsibility: one class, one reason to change. A UserService shouldn't also handle email formatting.
  • Open/Closed: open for extension, closed for modification. Use interfaces so new behaviors don't require touching existing code.
  • Liskov Substitution: a subclass must be usable wherever its parent is used. A Square extending Rectangle and overriding setWidth to also set height violates this.
  • Interface Segregation: don't force clients to implement methods they don't need. Split fat interfaces.
  • Dependency Inversion: depend on abstractions, not concretions. This is what makes Spring's DI useful.

Collections and Data Structures

Collections questions are a standard mid-interview filter. Get the implementation details right.

How does HashMap work internally?

HashMap stores entries in an array of buckets. It calls hashCode() on the key, then compresses it to an array index. If two keys hash to the same bucket (collision), they're stored in a linked list at that bucket. Since Java 8, that linked list converts to a balanced tree (red-black tree) once a bucket exceeds 8 entries, dropping worst-case lookup from O(n) to O(log n). The default load factor is 0.75 — when 75% of buckets are occupied, the map resizes (doubles the array and rehashes everything). A good answer mentions that hashCode() and equals() must be consistent — if two objects are equal, they must return the same hash code.

ArrayList vs. LinkedList — when does it matter?

ArrayList is backed by an array. Random access is O(1). Insertion/deletion in the middle is O(n) because elements shift. LinkedList is a doubly-linked list. Random access is O(n). Insertion/deletion at either end or at a known node is O(1). In practice, ArrayList wins for almost every use case because CPU cache locality matters — iterating an array is significantly faster than pointer-chasing through a linked list, even when the O() notation looks equivalent. Use LinkedList only when you're doing heavy manipulation at both ends and rarely accessing by index.

What is the difference between Comparable and Comparator?

Comparable defines the natural ordering of a class — the class itself implements it via compareTo(). Comparator is an external comparison strategy, useful when you need multiple sort orders or can't modify the class. With Java 8 lambdas, Comparator.comparing(Person::getLastName).thenComparing(Person::getFirstName) is idiomatic. If you're sorting String objects (already Comparable) but want case-insensitive order, pass String.CASE_INSENSITIVE_ORDER as a Comparator.

Concurrency Java Interview Questions

Multithreading questions separate mid from senior. A lot of candidates know synchronized exists but can't explain what it actually does.

What does volatile do?

volatile guarantees that reads and writes to a variable go directly to main memory, bypassing CPU caches. Without it, each thread may work from a cached copy of a variable, leading to visibility bugs — Thread A updates a flag, Thread B never sees it. volatile fixes visibility but does not make compound operations atomic. i++ on a volatile int is still a race condition because it's read-modify-write. Use AtomicInteger for that.

synchronized vs. ReentrantLock

synchronized is a built-in keyword that acquires an intrinsic monitor lock. It's simpler but less flexible: you can't time out waiting for the lock, can't interrupt a blocked thread, and can't try to acquire without blocking. ReentrantLock (from java.util.concurrent.locks) supports all of those: tryLock(timeout), lockInterruptibly(), and fairness policies. Use synchronized for simple mutual exclusion; reach for ReentrantLock when you need those control knobs.

What is a deadlock and how do you avoid it?

A deadlock occurs when Thread A holds Lock 1 and waits for Lock 2, while Thread B holds Lock 2 and waits for Lock 1 — both block forever. Prevention strategies: always acquire multiple locks in a consistent global order (if every thread locks resource A before resource B, the cycle can't form); use tryLock with a timeout and back off on failure; minimize lock scope to reduce hold time; prefer higher-level concurrency utilities (ConcurrentHashMap, BlockingQueue) over hand-rolled locking.

Spring Boot and Modern Java

Most Java job postings in 2026 mention Spring Boot. Even if the role doesn't use it heavily, expect at least a few questions.

What is dependency injection and what problem does Spring solve?

Dependency injection means an object receives its dependencies from outside rather than creating them itself. This makes classes easier to test (swap the real database for a mock), easier to configure (change behavior via config, not code changes), and less coupled. Spring's IoC container manages object creation and wiring — you declare dependencies via @Autowired or constructor injection, and Spring resolves the graph at startup. Constructor injection is preferred: it makes dependencies explicit and guarantees the object is fully initialized.

What is the difference between @Component, @Service, @Repository, and @Controller?

All four are stereotypes for @Component — Spring scans for them and registers beans. The difference is semantic and tooling-related: @Repository triggers Spring's persistence exception translation (converts low-level SQL exceptions to Spring's DataAccessException hierarchy). @Service signals business logic. @Controller marks a web layer class. Use the right one for your layer — it communicates intent to teammates and enables future tooling support.

Top Courses to Prepare for Java Interviews

Targeted prep beats grinding random LeetCode problems. These courses specifically address the Java concepts that come up in interviews.

Object Oriented Programming in Java (Coursera)

Rated 9.7/10 and covers OOP design — the area where most interview candidates give surface-level answers. Worth it specifically for the section on inheritance vs. composition, which is a classic senior-level question.

GitHub Copilot Masterclass for Java, Spring, AI and IntelliJ (Udemy)

Rated 9.8/10. Covers Spring alongside modern AI-assisted tooling — interviewers at larger companies are now asking how candidates use AI tools in their workflow. Dual value: Spring prep and a differentiating talking point.

Docker, Docker Hub and Docker Compose for Java Developers (Udemy)

Rated 9.8/10. Backend Java roles almost universally expect Docker knowledge. This course is Java-specific, so the examples are directly applicable to what you'd be explaining in a technical screen.

Kubernetes for Java Developers: Hands-On Fundamentals (Udemy)

Rated 9.6/10. Senior and mid-level Java roles increasingly include Kubernetes in the job description. Covers the Java-specific deployment patterns (JVM memory tuning in containers, liveness vs. readiness probes) that interviewers expect you to know.

Java Spring Boot 4 for Protobuf & gRPC Microservice (Udemy)

Rated 9.5/10. If the role is microservices-focused, gRPC is showing up in interviews regularly. This course is narrow enough to prep specifically for those questions without wasting time on unrelated material.

FAQ: Java Interview Questions

How long does it take to prepare for a Java technical interview?

For a junior role (0-3 years), 4-6 weeks of focused prep is realistic if you already know basic syntax. Spend the first two weeks on core Java (this article's topics), then two weeks on data structures and algorithms, then at least a week doing mock interviews out loud — the ability to explain your reasoning while coding is a separate skill from coding itself. Senior roles add system design and distributed systems to the mix, which takes longer to develop genuine fluency in.

Do Java interviews always include LeetCode-style algorithmic questions?

Depends heavily on the company. FAANG and their imitators use heavy algorithmic screens. Startups and most enterprise companies (banks, insurance, healthcare IT) focus more on Java-specific concepts, Spring, databases, and practical problem-solving. Research the company's interview format before committing to an algorithm grind — check Glassdoor reviews for that specific company's process.

What Java version should I know for interviews?

Know Java 8 features cold: lambdas, streams, Optional, the new Date/Time API. For senior roles, know Java 11's module system and Java 17's sealed classes and pattern matching — Java 17 is the current LTS release and most new projects target it. You won't be tested on every feature, but being able to say "I use records for DTOs since Java 16 — it cuts the boilerplate significantly" signals you're keeping up.

How important is Spring Boot knowledge for Java interviews?

Very. A 2025 Indeed analysis of Java job postings found Spring or Spring Boot mentioned in over 70% of listings. Even if the job description doesn't require it, interviewers often ask about dependency injection and bean management because they want to understand how well you understand application architecture. Not knowing Spring at all is a red flag for most backend Java roles above the junior level.

What should I prepare for a Java system design interview?

For mid and senior roles, system design is usually a 45-60 minute session where you design something like a URL shortener or rate limiter. For Java specifically: know how to think about thread safety at the design level (not just synchronized blocks), understand connection pooling (HikariCP is the default in Spring Boot — know why it matters), and be able to discuss caching strategies. Knowing when to reach for Redis vs. a JVM-level cache like Caffeine is a good senior signal.

Is it worth memorizing specific Java API methods?

Memorize the contract, not the signature. Interviewers don't care if you remember whether Collections.sort() takes a Comparator as a second argument — they care that you know it exists, that it uses merge sort for stability, and that you'd use list.sort() in modern Java anyway. Spend your memory on behavior and tradeoffs, not exact method names.

Bottom Line

Java interviews are more predictable than most candidates realize. The same 30-40 questions appear across 80% of phone screens because interviewers are busy and these questions reliably filter for genuine understanding. Master the why behind HashMap's design, know the concurrency primitives well enough to spot race conditions in a code snippet, and understand Spring well enough to discuss design decisions — that covers most of what you'll face at the junior-to-mid level.

For senior roles, add system design depth and be ready to critique the tradeoffs in your own answers. The difference between a mid and senior candidate isn't usually knowing more facts — it's demonstrating that you've made the wrong choice before and learned from it.

Pick one course to fill your biggest gap, do mock interviews out loud (not just reading), and review the questions here until you can answer them without looking. That's the prep strategy that actually works.

Looking for the best course? Start here:

Related Articles

More in this category

Course AI Assistant Beta

Hi! I can help you find the perfect online course. Ask me something like “best Python course for beginners” or “compare data science courses”.