Java Developer Interview Questions and Answers

Java interviews test core language understanding first, then collections and concurrency, and for most backend roles, Spring Boot and microservices. These are the questions asked most often, with answers short enough to say in an interview.

Core Java

What is the difference between JDK, JRE and JVM?

The JVM runs Java bytecode. The JRE is the JVM plus the standard libraries needed to run programs. The JDK is the JRE plus development tools such as the compiler (javac).

Why is String immutable in Java?

For security (strings are used for class names, paths and credentials), thread safety, and so the string pool can safely share instances. It also lets a string cache its hash code.

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

== compares references (whether two variables point to the same object). equals() compares logical content, as defined by the class.

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

If two objects are equal according to equals(), they must return the same hashCode(). Breaking this makes HashMap and HashSet behave incorrectly.

Collections and concurrency

ArrayList vs LinkedList?

ArrayList is backed by an array: fast random access and usually the better default. LinkedList supports cheap insertion and removal at known positions but is slow for indexed access and uses more memory.

How does HashMap work internally?

Keys are hashed to a bucket index. Collisions are stored in a list per bucket, which Java 8+ converts to a balanced tree when a bucket grows large. The table resizes when it passes its load factor (0.75 by default).

HashMap vs ConcurrentHashMap?

HashMap is not thread-safe. ConcurrentHashMap allows safe concurrent reads and writes using fine-grained locking and CAS operations, without locking the whole map.

What does the volatile keyword do?

It guarantees visibility: writes to the variable are immediately visible to other threads. It does not make compound operations such as count++ atomic.

Spring Boot and microservices

Frequently asked questions

Which Java version should I know for interviews?

Know Java 8 features well (lambdas, streams, Optional) and be aware of newer ones such as records and var.

Are Java interviews mostly theory?

For freshers, often yes. Experienced roles focus more on Spring Boot, design decisions and real production issues.

Related guides