Interview questions
Java Developer Interview Questions
28 Java interview questions on OOP, collections, JVM internals, concurrency, Spring and design, with what strong answers include. For both sides.

What's here
28 Java Developer interview questions, grouped into 6 areas: oop fundamentals, core java, collections and concurrency, jvm internals and memory, frameworks, data and apis and performance, design and situational questions. Each one comes with why it is worth asking and what a strong answer contains, so the same question can be scored the same way by different interviewers.
- Use a short, realistic coding exercise in Java rather than puzzles unrelated to the job.
- Ask follow-up 'why' questions; definitions are easy to memorise, trade-offs are not.
- Include at least one concurrency question for back-end roles.
Cohesyve finds, contacts and tests Java Developer candidates on the real work, then ranks them for these interviews. 14-day free trial for 10 candidates, not charged until it ends.
Preparing for this interview yourself? Practise it free →These Java interview questions cover what most Java developer interviews test: object-oriented programming, collections, JVM internals and concurrency first, then frameworks and design. Java developers build and maintain applications on the JVM, most often back-end services, APIs and enterprise systems, frequently with frameworks such as Spring. These questions cover core language knowledge, collections and concurrency, frameworks and data access, performance and design, so interviewers can see how candidates reason about real code rather than recite definitions. Interviewers can use the 'what to look for' notes as a scoring guide; candidates can use them to see what a strong answer contains.
OOP Fundamentals
The object-oriented basics that open most Java interviews, and that juniors and seniors alike should explain with their own examples.
- 1
What are the four principles of object-oriented programming, and how does Java support each one?
Why ask it
The most common opening Java interview question; the examples show whether the candidate has applied the ideas or only memorised them.What to look for
Encapsulation (private fields behind methods that protect invariants), inheritance (extends, and why composition is often preferred), polymorphism (a reference of a supertype calling an overridden method at run time) and abstraction (interfaces and abstract classes hiding implementation). Strong answers give a short example from their own code for each. - 2
What is the difference between an abstract class and an interface? When would you choose each?
Why ask it
A design-judgement question that also shows whether the candidate knows how interfaces have changed.What to look for
A class can extend one class but implement many interfaces; abstract classes can hold state and constructors; interfaces can now carry default and static methods, so the old 'interfaces have no implementation' answer is out of date. Default methods exist so an interface can gain new methods without breaking classes that already implement it. Choose an interface for a capability many unrelated types share, an abstract class for shared state and code in a family of related types. - 3
Explain method overloading versus method overriding.
Why ask it
Separates compile-time from run-time polymorphism.What to look for
Overloading: same name, different parameter lists, resolved at compile time. Overriding: a subclass redefines an inherited method with the same signature, chosen at run time by the object's actual type. Mentions @Override to catch mistakes, and that static and private methods are not overridden. - 4
What is the difference between == and equals() for objects?
Why ask it
A frequent source of real bugs, especially with strings and boxed numbers.What to look for
== compares references (or primitive values); equals() compares logical equality as the class defines it. Strong candidates mention string comparison bugs, Integer caching making == appear to work for small values, and that equals() must be overridden together with hashCode(). - 5
What do final, finally and finalize mean in Java?
Why ask it
A classic trio that checks precision and whether the candidate knows finalize is on its way out.What to look for
final: a variable cannot be reassigned, a method cannot be overridden, a class cannot be extended. finally: a block that runs after try/catch for clean-up. finalize: a method the garbage collector could call before reclaiming an object; finalization was deprecated for removal in JDK 18 (JEP 421), and the recommended replacements are try-with-resources and, for long-lived resources, the Cleaner API.
Before the Java Developer interviews, see who can do the work
Cohesyve finds and contacts Java Developer candidates from your job description and tests each one on an AI job simulation of the role, so these questions go to a ranked shortlist. 14-day free trial for 10 candidates, not charged until it ends.
Core Java
Language fundamentals every Java developer should explain clearly.
- 6
What is the contract between equals() and hashCode(), and what goes wrong if you break it?
Why ask it
A classic source of subtle bugs in collections.What to look for
Equal objects must have equal hash codes; overriding one without the other breaks HashMap and HashSet lookups. Strong candidates mention using the same fields in both and keeping them stable for objects used as keys. - 7
Explain the difference between checked and unchecked exceptions. When would you use each?
Why ask it
Shows API design judgement.What to look for
Checked exceptions must be declared or handled; unchecked (RuntimeException subclasses) need not. Sensible views on when callers can recover, avoiding swallowed exceptions, and using try-with-resources for cleanup. - 8
Why is String immutable in Java, and what are the practical consequences?
Why ask it
Tests understanding of the JVM and performance.What to look for
Safety for sharing and hashing, the string pool, thread safety, and the cost of repeated concatenation in loops (use StringBuilder). - 9
What have you used from modern Java versions, such as records, switch expressions or virtual threads?
Why ask it
Shows whether the candidate keeps up with the language.What to look for
Concrete uses: records for immutable data carriers, switch expressions and pattern matching for cleaner code, virtual threads (final in JDK 21) for high-concurrency request handling. Honest about which versions their projects used.
Collections and Concurrency
Choosing the right data structures and writing safe concurrent code.
- 10
When would you choose ArrayList, LinkedList, HashMap, TreeMap or LinkedHashMap?
Why ask it
Data structure choice affects correctness and performance.What to look for
ArrayList for indexed access and most lists, LinkedList rarely, HashMap for fast lookup, TreeMap for sorted keys, LinkedHashMap for insertion or access order (for example a simple LRU cache). Big-O awareness without reciting tables. - 11
How does ConcurrentHashMap differ from a synchronised HashMap?
Why ask it
Concurrency knowledge is essential for back-end services.What to look for
Finer-grained locking and non-blocking reads in ConcurrentHashMap versus one lock for the whole map, atomic methods such as computeIfAbsent, and no null keys or values. - 12
What is a race condition? Show how you would fix one in a counter shared between threads.
Why ask it
Tests practical thread-safety skills.What to look for
Explaining interleaved read-modify-write, then fixes: synchronized, AtomicInteger or LongAdder, or avoiding shared state. Awareness of the volatile keyword's limits (visibility, not atomicity). - 13
How do you use ExecutorService and CompletableFuture?
Why ask it
Modern Java concurrency relies on these rather than raw threads.What to look for
Thread pools sized for the workload, submitting tasks, composing async steps with thenApply or thenCompose, handling exceptions, and shutting down executors properly. - 14
How would you diagnose a deadlock in production?
Why ask it
Real-world debugging skill.What to look for
Taking thread dumps (jstack or similar), identifying threads waiting on each other's locks, and fixing by consistent lock ordering, timeouts or reducing lock scope.
JVM Internals and Memory
How Java code actually runs: the questions that separate developers who can debug production from those who cannot.
- 15
What is the difference between the JDK, the JRE and the JVM?
Why ask it
A basic question that shows whether the candidate understands the toolchain they use every day.What to look for
The JVM runs bytecode; the runtime environment adds the class libraries the JVM needs to run applications; the JDK adds development tools such as the compiler (javac), jar and debugging tools. Bonus: mentions that .java files compile to platform-independent .class bytecode, which the JVM interprets and JIT-compiles. - 16
How is JVM memory organised? What lives on the heap and what lives on the stack?
Why ask it
Essential for reasoning about memory errors and performance.What to look for
Objects live on the heap, shared by all threads and managed by the garbage collector; each thread has its own stack of frames holding local variables and references. Class metadata is held outside the heap: since JDK 8 (JEP 122) the permanent generation is gone and class metadata is allocated in native memory, usually called metaspace. Strong candidates connect StackOverflowError to deep recursion and OutOfMemoryError to the heap or metaspace. - 17
How does class loading work in Java?
Why ask it
Explains a family of confusing errors such as ClassNotFoundException and NoClassDefFoundError.What to look for
The built-in loaders: the bootstrap class loader, the platform class loader and the system (application) class loader, which loads classes from the class path and module path. A class loader normally delegates to its parent before trying to find a class itself. Good answers explain how duplicate or conflicting JARs cause problems in application servers and fat JARs. - 18
What does the volatile keyword guarantee, and when is it not enough?
Why ask it
Tests understanding of the Java memory model rather than just locks.What to look for
volatile guarantees visibility: a write by one thread is seen by later reads in other threads, and it prevents certain reorderings. It does not make compound actions such as count++ atomic, so a shared counter still needs AtomicInteger or a lock. Typical correct use: a stop flag read by a worker thread.
Frameworks, Data and APIs
How the candidate builds real services.
- 19
Explain dependency injection and how Spring implements it.
Why ask it
Spring is widely used for Java services.What to look for
Inversion of control, beans managed by the container, constructor injection preferred, and how this helps testing and loose coupling. Awareness of bean scopes. - 20
What is the N+1 query problem in JPA or Hibernate, and how do you fix it?
Why ask it
A common performance problem in data-heavy apps.What to look for
Lazy loading triggering one query per related entity; fixes include fetch joins, entity graphs, batch fetching or DTO projections, confirmed by checking the SQL logs. - 21
How do you handle transactions in a Spring application?
Why ask it
Data integrity depends on transaction boundaries.What to look for
@Transactional on service methods, understanding of propagation and rollback rules (unchecked exceptions by default), the self-invocation proxy pitfall, and keeping transactions short. - 22
How do you design a REST API for a new resource?
Why ask it
API design affects every client.What to look for
Resource-oriented URLs, correct HTTP methods and status codes, validation, consistent error responses, pagination, versioning approach and documentation. - 23
How do you test a Java service?
Why ask it
Testing habits predict code quality.What to look for
Unit tests with JUnit and a mocking library, integration tests against real databases (for example with containers), contract or API tests, and a view on what not to mock.
Performance, Design and Situational Questions
JVM behaviour, design choices and how the candidate works under pressure.
- 24
A service's memory use keeps growing until it crashes. How do you investigate?
Why ask it
Memory leaks are a common production issue.What to look for
Monitoring heap usage, taking a heap dump, analysing it with a profiler to find retained objects, typical causes (unbounded caches, static collections, listeners never removed), and verifying the fix. - 25
What do you know about garbage collection, and when have you tuned it?
Why ask it
Shows JVM depth.What to look for
Generational collection basics, awareness of different collectors and their trade-offs between pause time and throughput, and a habit of measuring before tuning. Honest answers if they have not needed to tune. - 26
How would you break a large monolithic Java application into services, if at all?
Why ask it
Tests architectural judgement.What to look for
Questioning whether it is needed, identifying boundaries by business domain, extracting gradually, handling data ownership, and weighing operational complexity. - 27
Tell me about a production incident you helped resolve.
Why ask it
Real stories show debugging and ownership.What to look for
Calm triage, using logs, metrics and traces, a fix or rollback, communication with the team, and a blameless follow-up that prevented repeats. - 28
How do you review a pull request from a teammate?
Why ask it
Code review shapes team quality.What to look for
Checking correctness, tests, readability and design, kind and specific comments, distinguishing blocking issues from preferences, and reviewing promptly.
Running the interview well
- 1Use a short, realistic coding exercise in Java rather than puzzles unrelated to the job.
- 2Ask follow-up 'why' questions; definitions are easy to memorise, trade-offs are not.
- 3Include at least one concurrency question for back-end roles.
- 4Ask about a production incident to see debugging habits and ownership.
- 5Tailor the framework questions to your stack, but let candidates from other frameworks show transferable understanding.
- 6Check testing habits as seriously as coding ability.
- 7Calibrate depth to seniority: senior candidates should discuss JVM behaviour and system design confidently.
Common questions
What questions are asked in a Java developer interview?
Expect core Java (equals and hashCode, exceptions, immutability, generics), collections, concurrency, Spring and JPA or Hibernate, REST API design, testing, JVM memory and garbage collection, plus a coding exercise and questions about past projects.
What are the most common core Java interview questions?
The questions that come up most often are the OOP principles, abstract classes versus interfaces, overloading versus overriding, == versus equals() and the equals/hashCode contract, checked versus unchecked exceptions, String immutability, choosing between ArrayList, LinkedList, HashMap and TreeMap, how ConcurrentHashMap works, race conditions and volatile, and how JVM memory and garbage collection work. Freshers are asked mostly the language and OOP questions; experienced developers get the concurrency, JVM and design questions with more follow-ups.
How do I prepare for a Java coding interview?
Practise writing clean Java by hand or in a plain editor, revise collections and concurrency, and be ready to explain your trade-offs out loud. Build or review a small Spring service so you can talk about real code.
Which Java version should I know for interviews?
Know the features of the version your target employer uses, and be aware of recent additions such as records, switch expressions, pattern matching and virtual threads, which were finalised in JDK 21.
Do Java developer interviews always cover Spring?
Not always, but Spring is common for back-end roles. If the job uses another framework, the interview will focus on that. Understanding dependency injection and transactions transfers across frameworks.
What are common Java interview mistakes?
Reciting definitions without examples, ignoring thread safety, not writing tests, not asking clarifying questions in coding exercises, and overclaiming experience with tools you have only read about.
What should I ask at the end of a Java developer interview?
Ask which Java version and frameworks they use, how code review and deployments work, how on-call is handled, and what the biggest technical challenge is for the team this year.
Save these questions for the Java Developer candidates who can do the work
Cohesyve takes your Java Developer job description, finds candidates, reaches out to them and runs an AI job simulation of the real work, then returns a ranked shortlist.
1,500+
assessments completed
50%
faster time-to-hire
5 min
from JD to assessment
14-day free trial · 10 candidates · Not charged until the trial ends
Preparing for a Java Developer interview yourself? Practise on an AI job simulation of the role. 3-day free trial, cancel anytime.
From the blog