Java Developer interview questions and answers

Java developer interviews test core Java (collections, OOP, exceptions, concurrency), the JVM, Spring Boot, databases and REST APIs. Service companies in India and banks worldwide often include a written or online coding test first.

Skills and knowledge

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

    Sample answer: The JVM is the virtual machine that runs Java bytecode on any platform. The JRE is the JVM plus the standard libraries needed to run Java programs. The JDK is the JRE plus tools for developers such as the compiler (javac) and debugger. You install the JDK to build Java code.

  2. How does HashMap work internally?

    Sample answer: HashMap stores entries in an array of buckets. It uses the key's hashCode to pick a bucket and equals to find the exact key in it. Collisions are stored as a list, which turns into a balanced tree when a bucket gets large. When the map is about 75% full it resizes and redistributes entries. Keys must have consistent equals and hashCode.

  3. What is the difference between an abstract class and an interface?

    Sample answer: An abstract class can have state (fields), constructors and both abstract and concrete methods, and a class can extend only one. An interface defines a contract; since Java 8 it can have default and static methods but no instance state, and a class can implement many. Use interfaces for capabilities and abstract classes for shared base behaviour.

  4. Explain checked and unchecked exceptions.

    Sample answer: Checked exceptions, such as IOException, must be caught or declared, because the caller is expected to handle them. Unchecked exceptions extend RuntimeException, such as NullPointerException, and usually signal programming errors. Use checked exceptions for recoverable conditions and avoid catching exceptions only to ignore them.

  5. What is the difference between String, StringBuilder and StringBuffer?

    Sample answer: String is immutable, so each change creates a new object, which is safe to share but slow in loops. StringBuilder is mutable and fast for building strings, but not thread-safe. StringBuffer is mutable and synchronised, so it is thread-safe but slower. Use StringBuilder in most single-threaded code.

  6. How does garbage collection work in Java?

    Sample answer: The JVM automatically frees objects that are no longer reachable from live references. Memory is split into generations: most objects die young and are collected cheaply, while long-lived ones move to the old generation. Modern collectors such as G1 and ZGC aim for short pauses. Memory leaks still happen when references are kept by mistake, for example in static collections.

  7. What is dependency injection in Spring?

    Sample answer: Instead of a class creating its own dependencies, Spring creates them as beans and passes them in, usually through the constructor. This makes classes loosely coupled and easy to test with mocks. Annotations such as @Component, @Service and @Autowired, or constructor injection, tell Spring what to wire.

  8. How do you make code thread-safe in Java?

    Sample answer: Prefer immutable objects and avoid shared state. When state must be shared, use synchronized blocks or locks, atomic classes such as AtomicInteger, and concurrent collections such as ConcurrentHashMap. Use executors rather than creating threads by hand, and watch for deadlocks by always locking in the same order.

  9. What are Java streams?

    Sample answer: Streams process collections in a declarative way with steps such as filter, map and collect, for example list.stream().filter(x -> x > 10).map(x -> x * 2).toList(). They are lazy, readable and can run in parallel, but simple loops are sometimes clearer and faster for small tasks.

Past experience

  1. Tell me about a Java application you built or maintained.

    Sample answer: Describe what it did, its architecture (for example Spring Boot microservices with PostgreSQL and Kafka), your part in it, one technical problem you solved such as a slow query or memory issue, and a measurable result.

What would you do?

  1. Your Spring Boot service is slow under load. How do you find the cause?

    Sample answer: Check metrics for CPU, memory, garbage collection pauses and thread pool use, then look at slow endpoints with tracing or logs. Common causes are slow database queries, too few connections in the pool, blocking calls to other services and large objects. Profile with a tool such as Java Flight Recorder, fix the biggest cost and load test again.

  2. You get a NullPointerException in production. What do you do?

    Sample answer: Read the stack trace to find the exact line and which reference was null, check the logs for the input that caused it, reproduce it with a test, then fix the root cause, for example validating input or handling a missing record, rather than just adding a null check everywhere.

Open Java Developer jobs

TThomas Greg do Brasil
Remote · Brazil

Desenvolvedor de Software Junior

RemoteEngineeringFull Time
Pay not listedToday · via Himalayas
VVelocix Solutions USA Inc.
Remote · Portugal

Senior Developer

RemoteEngineeringFull Time
Pay not listedToday · via Himalayas
AAlternative Payments
Remote · Worldwide

Lead Software Engineer - Alti (AI)

RemoteData & AIFull Time
USD 100,000–120,000Today · via Himalayas
FFerguson
Remote · United States

Sr. Azure Application Administrator - Enterprise Solutions Services

RemoteOperationsFull Time
USD 6,806–11,921Today · via Himalayas
SSmartsheet
Remote · Bulgaria

Sr. Software Engineer II- Mobile (Remote Eligible in Bulgaria)

RemoteEngineeringFull Time
Pay not listedToday · via Himalayas
VVectara
Remote · Worldwide

Senior/Staff Software Engineer

RemoteEngineeringFull Time
Pay not listedToday · via Vectara careers (Greenhouse)

More interview guides