Java Developer Interview Questions and Answers

Java interviews in India follow a familiar shape: an online test or coding screen, one or two technical rounds on core Java and Spring, and an HR round. Service companies lean on fundamentals; product companies add data structures and design.

Below are the questions that come up most, with answers short enough to say out loud. Use them to find gaps, then practise saying each answer in your own words.

Java Developer interview rounds

  1. Online assessment. Aptitude plus 1–2 coding problems on arrays, strings or hash maps, usually 60–90 minutes.
  2. Technical round 1. Core Java: OOP, collections, exceptions, strings, Java 8 features. Expect to write small snippets.
  3. Technical round 2. Spring Boot, REST APIs, JPA/Hibernate, SQL and your project. Experienced candidates get design and multithreading.
  4. HR / managerial. Why this company, notice period, salary expectations and one or two behavioural questions.

Core Java interview questions

What is the difference between JDK, JRE and JVM?

The JVM runs bytecode. The JRE is the JVM plus the standard libraries needed to run programs. The JDK is the JRE plus tools to build them: the compiler (javac), debugger and others.

Why is String immutable in Java?

So strings can be shared safely from the string pool, used as HashMap keys without their hash changing, and passed between threads without locking. It also stops a checked value (like a file path) being changed after a security check.

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

== compares references: whether both point to the same object. equals() compares content, as the class defines it. For strings and wrapper types you almost always want equals().

What is the contract between equals() and hashCode()?

Objects that are equal must return the same hashCode. If you override equals() without hashCode(), HashMap and HashSet will put equal objects in different buckets and lookups fail.

Checked vs unchecked exceptions?

Checked exceptions (IOException, SQLException) must be caught or declared; the compiler enforces it. Unchecked ones extend RuntimeException (NullPointerException, IllegalArgumentException) and usually signal programming errors.

What changed in Java 8 that you use daily?

Lambdas and functional interfaces, the Stream API for filtering and mapping collections, Optional to avoid null checks, default methods in interfaces, and the java.time date API.

Collections interview questions

How does HashMap work internally?

It keeps an array of buckets. A key's hashCode picks the bucket; entries in the same bucket form a linked list, which turns into a balanced tree after 8 entries (Java 8+). When the map passes its load factor (0.75), it doubles the array and rehashes.

ArrayList vs LinkedList?

ArrayList is backed by an array: fast random access, slower inserts in the middle. LinkedList is a doubly linked list: cheap inserts and removals at known positions, slow access by index. ArrayList is the right default.

HashMap vs ConcurrentHashMap vs Hashtable?

HashMap isn't thread-safe and allows one null key. Hashtable is synchronised on every method, so it's slow, and allows no nulls. ConcurrentHashMap allows concurrent reads and fine-grained locking for writes; use it when threads share a map.

What is a fail-fast iterator?

An iterator that throws ConcurrentModificationException if the collection is changed while you iterate, other than through the iterator itself. ArrayList and HashMap iterators are fail-fast; concurrent collections are fail-safe.

Multithreading interview questions

Runnable vs Callable?

Runnable's run() returns nothing and can't throw checked exceptions. Callable's call() returns a value and can throw. You submit a Callable to an ExecutorService and get a Future back.

What does volatile do?

It makes every read of the variable come from main memory, so a write by one thread is visible to others. It doesn't make compound actions like count++ atomic; use AtomicInteger or a lock for that.

synchronized vs ReentrantLock?

synchronized is simpler and releases the lock automatically. ReentrantLock adds tryLock with a timeout, fairness and interruptible waits, but you must unlock in a finally block.

What is a deadlock and how do you avoid it?

Two threads each hold a lock the other needs, so both wait forever. Avoid it by always taking locks in the same order, using tryLock with a timeout, and holding locks for as short a time as possible.

Spring Boot and SQL interview questions

What does @SpringBootApplication do?

It combines @Configuration, @EnableAutoConfiguration and @ComponentScan: it marks the main class as a config source, turns on auto-configuration from the classpath, and scans the package for beans.

What is dependency injection, and why use constructor injection?

Spring creates objects and passes in what they depend on, instead of each class building its own. Constructor injection makes dependencies required and final, and the class easy to test without Spring.

How do you handle exceptions across a REST API?

A @RestControllerAdvice class with @ExceptionHandler methods that map exceptions to status codes and a consistent error body, so controllers stay clean.

What is the N+1 query problem in JPA?

Loading a list of entities, then lazily loading a relation for each one, runs one query plus N more. Fix it with a JOIN FETCH query, an @EntityGraph, or batch fetching.

Find the second-highest salary in SQL.

SELECT MAX(salary) FROM employee WHERE salary < (SELECT MAX(salary) FROM employee); or use DENSE_RANK() OVER (ORDER BY salary DESC) and pick rank 2, which also handles ties.

How Aptivo answers a Java Developer question live

During a real interview, Aptivo hears the question and shows an answer built from your resume and the job, a few seconds after the interviewer finishes. Something like this:

InterviewerCan you explain how HashMap handles collisions?

AptivoTwo keys can land in the same bucket when their hashes map to the same index. HashMap keeps those entries in a linked list in that bucket and uses equals() to find the right one. Since Java 8, once a bucket has more than 8 entries it becomes a red-black tree, so lookups stay O(log n) instead of O(n). In my last project I hit this with a badly written hashCode on a composite key; fixing hashCode brought lookup times back down.

Read it, then say it in your own words. Answers mention your own projects when your resume has them.

Tips for your Java Developer interview

  • Know your own project deeply: the stack, one hard bug, and why you chose Spring Boot or JPA. Most second rounds are built around it.
  • Write code on paper or a plain editor before the interview; IDE autocomplete hides gaps.
  • For experienced roles, prepare one design: a URL shortener or an order service, with the API, tables and where you'd cache.
  • Say the time complexity of every solution you write, without being asked.

Frequently asked questions

What Java topics are asked for freshers?

OOP concepts, strings, collections (especially HashMap and ArrayList), exceptions, basic multithreading and simple SQL. Most fresher rounds also include one or two coding problems.

Is Spring Boot asked in fresher interviews?

Often, if it's on your resume. Be ready to explain annotations you used, dependency injection and how a request reaches your controller.

How should I prepare in one week?

Two days on core Java and collections, two on Spring Boot and SQL, two on coding problems, and one day saying your answers out loud, including the project walk-through.

Interview questions for other roles