Java developer interview questions and answers
Java rounds move from core language basics to collections, concurrency and Spring Boot. These are the questions that come up most, for freshers and experienced developers, with what each one checks.
What to revise before the interview
- OOP: encapsulation, inheritance, polymorphism, abstraction
- Collections: List, Set, Map and when to use each
- HashMap internals, equals() and hashCode()
- Exceptions: checked vs unchecked, try-with-resources
- Multithreading: threads, synchronized, ExecutorService
- Java 8+: lambdas, streams, Optional
- Spring Boot: dependency injection, REST controllers, JPA
- JVM: heap vs stack, garbage collection basics
1.What is the difference between JDK, JRE and JVM?
- What they're checking
- Whether you understand how Java code is compiled and run - a basic every Java developer should know.
- How to answer
- JVM runs bytecode; JRE is the JVM plus the libraries needed to run programs; JDK is the JRE plus tools to develop, like the compiler (javac). Keep it to three sentences.
2.Explain the four pillars of OOP with examples.
- What they're checking
- Whether you can apply OOP, not just recite definitions.
- How to answer
- Give one real example for each: encapsulation (private fields with getters), inheritance (SavingsAccount extends Account), polymorphism (overridden calculateInterest()), abstraction (an interface like PaymentMethod).
3.How does HashMap work internally?
- What they're checking
- A favourite for experienced roles: it checks hashing, collisions and performance thinking.
- How to answer
- Keys are hashed to a bucket index; collisions go into a linked list, which becomes a balanced tree after a threshold (Java 8+). get() uses hashCode() to find the bucket and equals() to find the key. Mention resizing when the load factor (0.75 by default) is exceeded.
4.Why must you override hashCode() when you override equals()?
- What they're checking
- Whether you understand the contract between them.
- How to answer
- Equal objects must have equal hash codes, or hash-based collections like HashMap and HashSet will put them in different buckets and fail to find them.
5.What is the difference between ArrayList and LinkedList?
- What they're checking
- Choosing the right data structure.
- How to answer
- ArrayList is backed by an array: fast random access, slower inserts in the middle. LinkedList is a doubly linked list: fast inserts and removals at known positions, slow random access. Say that ArrayList is the usual default.
6.Checked vs unchecked exceptions - when do you use each?
- What they're checking
- Error-handling judgement.
- How to answer
- Checked exceptions (IOException) must be declared or handled and suit recoverable conditions; unchecked ones (NullPointerException, IllegalArgumentException) signal programming errors. Mention try-with-resources for closing streams.
7.What does the synchronized keyword do, and what are its downsides?
- What they're checking
- Basic concurrency understanding.
- How to answer
- It lets only one thread at a time run a block or method on the same lock, making shared state safe. Downsides: contention and possible deadlocks. Mention alternatives such as ConcurrentHashMap, AtomicInteger and ExecutorService.
8.Explain Java 8 streams with an example.
- What they're checking
- Whether you write modern Java.
- How to answer
- A stream is a pipeline of operations on a collection: filter, map, then a terminal operation like collect.
- Example answer
- “To get the names of active users in upper case, I'd write users.stream().filter(User::isActive).map(u -> u.getName().toUpperCase()).collect(Collectors.toList()).”
9.What is dependency injection in Spring Boot?
- What they're checking
- Every Java backend job uses Spring; this checks you understand its core idea.
- How to answer
- Spring creates objects (beans) and passes them to classes that need them, instead of classes creating their own. Constructor injection is preferred because it makes dependencies explicit and easy to test.
10.Tell me about a Java project you built.
- What they're checking
- Real experience and ownership.
- How to answer
- Describe the problem, your design (layers, database, APIs), one hard bug or decision and the result. Be ready for follow-ups on any technology you mention.
- Example answer
- “I built a library management REST API with Spring Boot and MySQL. The tricky part was preventing double-booking of the same book, which I solved with a database unique constraint and a retry on conflict. It's used by our college library for two departments.”
On a live call, Cuelyte AI hears questions like these and has an answer ready in about a second, built from your resume and notes. Coding interviews: how Cuelyte AI helps
Frequently asked questions
What Java topics should freshers prepare?
OOP, strings, arrays, collections, exceptions and basic multithreading, plus writing simple programs such as reversing a string or finding duplicates. Spring Boot basics are a bonus.
What do experienced Java interviews focus on?
HashMap and concurrency internals, Java 8+ features, Spring Boot, JPA and Hibernate, REST API design, microservices and debugging production issues.
Is Java still in demand in India?
Yes. Java is widely used for backend systems at IT services companies, banks and product companies, so Java developer roles remain common.
Company interview guides for this role
- TCS interview questions
- Infosys interview questions
- Wipro interview questions
- Accenture interview questions
- Cognizant interview questions
- JPMorgan Chase interview questions
Related roles and topics
- Python developer interview questions
- .NET developer interview questions
- Full stack developer interview questions
- SQL developer interview questions
- HR interview questions
- Behavioural interview questions
- Coding interview questions
- System design interview questions
- Interview questions for freshers
- Sales interview questions
- All roles →
Practise these questions for your next interview
Add your resume to Cuelyte AI, type a question and get a clear answer in your own words - in English, Hindi or Hinglish. Free to start.