Skip to content

Java interview questions and answers

Java interviews cover OOP, collections, exceptions, Java 8 features and Spring Boot. Expect to write or read small pieces of code.

12 questions. Read each one, start the timer and answer out loud as if you were in the room, then open the tip. Nothing is recorded.

Question 1 of 12

What are the four pillars of OOP?

What a good answer covers

Encapsulation, inheritance, polymorphism and abstraction. Give a short example of each from a real project.

All 12 questions with answers

1. What are the four pillars of OOP?

Encapsulation, inheritance, polymorphism and abstraction. Give a short example of each from a real project.

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

The JVM runs bytecode. The JRE is the JVM plus libraries to run programs. The JDK adds the compiler and tools to build them.

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

== compares references for objects. equals() compares content when the class overrides it, like String.

4. Why are strings immutable in Java?

Safety when shared, the string pool, thread safety and a cached hash code.

5. ArrayList or LinkedList: when do you use each?

ArrayList for fast access by index and most uses. LinkedList only when you add or remove at the ends a lot.

6. How does HashMap work internally?

The key’s hash picks a bucket; equals() resolves collisions. Busy buckets turn into trees (Java 8+), and the map resizes at a 0.75 load factor.

7. What is the difference between checked and unchecked exceptions?

Checked exceptions must be caught or declared, like IOException. Unchecked ones extend RuntimeException, like NullPointerException.

8. Abstract class or interface: what is the difference?

A class extends one abstract class, which can hold state. It can implement many interfaces, which can have default methods since Java 8.

9. What are streams and lambdas?

Lambdas are short functions. Streams process collections with map, filter and collect in a readable way.

10. What is dependency injection in Spring Boot?

Spring creates objects (beans) and passes them in, so classes don’t build their own dependencies. It makes code easier to test.

11. How do you handle concurrency in Java?

ExecutorService for thread pools, synchronized or locks for shared state, and concurrent collections like ConcurrentHashMap.

12. What is the difference between final, finally and finalize?

final stops changes or overriding, finally always runs after try, finalize was a cleanup hook and is now deprecated.

Before the interview

  • Read the job description twice and match two of your examples to what it asks for.
  • Keep printed copies of your resume, ID proof and certificates ready, even for online rounds.
  • Know your current CTC, expected salary and notice period. Check typical pay in our salary guide, and compare offers with the in-hand salary calculator.
  • Genuine employers never ask you to pay for an interview, training kit or joining. Report anyone who does.

More practice: IT, software and data

All roles