AI
prepair.app
Start interview →
EnglishРусскийУкраїнська

Junior Java BackendJava backend interview questions

Junior · no experience / under 1 year

Java backend interviews cover core language semantics, collections, concurrency, Spring, and how you reason about the JVM. Below are the questions asked most often, each with a model answer. Junior: core theory, definitions, and simple practical cases.

Topics to prepare

Core Java and OOP
Collections Framework
Concurrency and threads
Spring Boot and Spring Data
JVM, GC and memory
SQL and Hibernate

9 Junior-level questions with answers

1

How does HashMap work internally, and how does ConcurrentHashMap differ?

Answer

HashMap stores entries in an array of buckets indexed by the key's hash; collisions form a linked list that converts to a red-black tree past eight nodes. It is not thread-safe — concurrent resizing can corrupt the structure. ConcurrentHashMap achieves thread safety by locking only the bucket being written (CAS plus synchronized on the node) instead of the whole map, so reads are lock-free and writes contend only on the same bucket.

2

Explain the equals() and hashCode() contract. What breaks if you violate it?

Answer

If two objects are equal by equals(), they must return the same hashCode; unequal objects may share a hash but ideally do not. Violating it breaks every hash-based collection: an object stored in a HashMap lands in one bucket, and a later lookup computes a different hash, searches another bucket, and reports the entry as missing. The classic bug is mutating a field used in hashCode after inserting the object into a set.

3

What is garbage collection and which collectors does the JVM offer?

Answer

GC reclaims heap memory for objects no longer reachable from GC roots. The heap is generational — most objects die young, so minor collections in the young generation are cheap. Collectors include Serial and Parallel for throughput, G1 as the modern default balancing pause time and throughput, and ZGC or Shenandoah for very large heaps with sub-millisecond pauses.

4

What is the difference between checked and unchecked exceptions?

Answer

Checked exceptions extend Exception and must be declared or handled — they represent recoverable conditions the caller should plan for, like IOException. Unchecked exceptions extend RuntimeException and signal programming errors such as NullPointerException or IllegalArgumentException. The practical guidance is to use unchecked for bugs and checked sparingly, because forcing every caller to handle an exception often produces empty catch blocks.

5

What is Dependency Injection in Spring and which injection types exist?

Answer

DI means an object receives its dependencies from the container instead of constructing them, which decouples classes and makes them testable. Spring supports constructor, setter, and field injection. Constructor injection is preferred: dependencies become final, the object is never in a half-built state, and the class cannot hide an ever-growing dependency list the way field injection can.

6

What is the difference between @Component, @Service, @Repository and @Controller?

Answer

All four register the class as a Spring bean and are technically interchangeable for scanning. They differ in intent and in the extras Spring attaches: @Repository translates persistence exceptions into Spring's DataAccessException hierarchy, @Controller and @RestController take part in request mapping, and @Service is a semantic marker for business logic. Using the specific annotation documents the layer and enables the right behaviour.

7

What is a transaction? Explain isolation levels.

Answer

A transaction is a unit of work that satisfies ACID: it either commits entirely or rolls back. Isolation levels trade consistency against concurrency — Read Uncommitted allows dirty reads, Read Committed prevents them, Repeatable Read also prevents non-repeatable reads, and Serializable prevents phantom reads at the cost of throughput. Most systems run Read Committed and handle the remaining anomalies with optimistic locking.

8

What is the difference between ArrayList and LinkedList? When do you use each?

Answer

ArrayList is backed by a resizable array: indexed access is O(1), but inserting or removing in the middle shifts elements. LinkedList is a doubly linked list: insertion and removal at a known node is O(1), but indexed access is O(n) and every element carries node overhead. In practice ArrayList wins almost always because CPU cache locality beats theoretical complexity; LinkedList is mainly useful as a Deque.

9

What are volatile and synchronized? When do you use each?

Answer

volatile guarantees visibility — a write is immediately visible to other threads and reads are never cached — but it does not provide atomicity, so volatile counters still lose increments. synchronized provides both visibility and mutual exclusion, so only one thread executes the block at a time. Use volatile for a simple flag read by many threads, synchronized or an Atomic class when the operation is read-modify-write.

🦎

Reading answers is not enough

In a real interview you speak under pressure. Cam asks these same questions, scores every answer, and shows exactly what to fix.

Practice a Junior Java Backend interview →
Free · 3 interviews per month

Other levels — Java Backend

Middle Java BackendSenior Java BackendAll Java Backend questions

Other specializations

🔍Junior Manual QA🤖Junior QA Automation🐍Junior Python Backend🐘Junior PHP Backend🦫Junior Go Backend🟢Junior Node.js Backend⚛️Junior React Frontend💚Junior Vue Frontend🅰️Junior Angular FrontendJunior Next.js