Top 17 Java Backend Interview Questions & Answers (2024) – From Collections to JVM

This article combines a detailed Baidu 2026 campus recruitment salary table with an extensive Java interview guide covering collections, concurrency, thread creation, thread pools, I/O models, Spring bean lifecycle, Redis persistence, MySQL isolation levels, MVCC, storage engines, data structures, TCP/UDP differences, JVM memory layout, garbage collection algorithms, and a quicksort example, providing a comprehensive resource for backend developers preparing for technical interviews.

IT Services Circle
IT Services Circle
IT Services Circle
Top 17 Java Backend Interview Questions & Answers (2024) – From Collections to JVM

Before the interview questions, the author shares a Baidu 2026 campus recruitment salary table, showing annual total compensation (including signing bonuses) for various backend, client, C++, and testing positions, ranging from 38.4w to 60.2w.

Baidu salary table
Baidu salary table

1. Difference between ArrayList and LinkedList

Underlying data structure : ArrayList uses an array for fast random access; LinkedList uses nodes linked by pointers.

Insert/delete efficiency : ArrayList is fast at the end but slow in the middle; LinkedList handles insert/delete anywhere efficiently.

Random access : O(1) for ArrayList, O(n) for LinkedList.

Space usage : ArrayList requires a contiguous block; LinkedList uses less per node.

Use cases : ArrayList for frequent random reads and tail inserts; LinkedList for frequent middle inserts/deletes.

Thread safety : Neither is thread‑safe; Vector provides synchronized access.

2. How ConcurrentHashMap works

In JDK 1.7, ConcurrentHashMap uses a segmented lock (Segment) with an array of HashEntry linked lists. In JDK 1.8 it replaces segments with a finer‑grained lock on each bucket and adds a red‑black tree for high‑collision buckets.

Operations:

Check pool state; if not RUNNING, reject.

If workerCount < corePoolSize, create a new thread.

If the queue isn’t full, enqueue the task.

If workerCount < maximumPoolSize, create a new thread even when the queue is full.

Otherwise apply the rejection policy.

3. What is CAS?

Compare‑And‑Swap (CAS) is an optimistic lock that atomically compares a memory location with an expected value and, if they match, updates it to a new value. It relies on CPU atomic instructions (e.g., cmpxchg) and is used in Java’s Unsafe, AtomicInteger, etc.

4. Ways to create a thread in Java

Extend Thread : Subclass Thread and override run(). Simple but prevents extending another class.

Implement Runnable : Implement Runnable, pass an instance to a Thread constructor. Allows extending another class and sharing the same target object.

Implement Callable + FutureTask : Callable returns a result and can throw exceptions; wrap it in FutureTask and submit to a thread.

Thread pool (ExecutorService) : Use Executors.newFixedThreadPool or other factories to reuse threads efficiently.

5. Thread pool principle

Thread pools limit the number of active threads, reuse idle threads, and queue excess tasks. The execute method decides whether to run a task immediately, enqueue it, or reject it based on pool state, core size, maximum size, and queue capacity.

6. Difference between BIO, NIO, and AIO

BIO : Blocking I/O using streams; simple but low scalability.

NIO : Non‑blocking I/O with channels, selectors, and buffers; supports multiplexing.

AIO : Asynchronous I/O introduced in JDK 1.7; uses callbacks/events for non‑blocking operations.

7. Spring Bean lifecycle

Creation : Bean instantiated and dependencies injected.

Initialization : Aware interfaces called, BeanPostProcessor pre‑process, afterPropertiesSet or custom init‑method, then post‑process.

Usage : Bean is ready for use.

Destruction : DisposableBean destroy method or custom destroy‑method invoked.

8. Redis persistence mechanisms

AOF (Append‑Only File) : Logs every write command; three fsync policies – always, everysec, no.

RDB (Snapshot) : Periodic binary snapshots; generated by SAVE (blocking) or BGSAVE (forked child process).

AOF provides durability but can be slower; RDB is faster for recovery but may lose recent writes.

9. Redis data structures

Core types: String, Hash, List, Set, Sorted Set (Zset) . Extended types: Bitmap, HyperLogLog, GEO, Stream . Each has typical use cases such as caching, leaderboards, messaging, and geolocation.

10. MySQL transaction isolation levels

Read Uncommitted

Read Committed

Repeatable Read (default for InnoDB)

Serializable

11. MySQL MVCC implementation

MVCC uses a Read View containing m_ids, min_trx_id, max_trx_id, and creator_trx_id. Each row stores trx_id and roll_pointer. Visibility rules compare the row’s trx_id with the Read View to decide if the version is visible.

12. Differences among MySQL storage engines

InnoDB : ACID, row‑level locking, foreign keys.

MyISAM : Fast reads, no transactions or foreign keys.

Memory : Stores data in RAM; fast but volatile.

13. Stack vs. Queue

Stack is LIFO (last‑in‑first‑out); Queue is FIFO (first‑in‑first‑out). Stacks are used for function call tracking, queues for task scheduling.

14. Binary tree traversal methods

Depth‑first : Pre‑order (root‑left‑right), In‑order (left‑root‑right), Post‑order (left‑right‑root).

Breadth‑first : Level‑order traversal using a queue.

15. TCP vs. UDP

TCP: Connection‑oriented, reliable, ordered, flow‑control, congestion control, larger header.

UDP: Connectionless, best‑effort, unordered, no flow‑control, smaller header.

16. JVM memory layout

Shared areas: Heap (young + old generations) and Method Area/Metaspace . Thread‑local areas: Java Stack , Native Stack , and Program Counter Register . Additionally, Direct (off‑heap) memory is used by NIO.

17. Garbage collection algorithms

Mark‑Sweep : Marks reachable objects then sweeps dead ones; can cause fragmentation.

Copying : Copies live objects to a new space, eliminating fragmentation but using only half the heap at a time.

Mark‑Compact : Marks then compacts live objects to one end.

Generational : Separates young and old generations; objects promoted based on age.

18. Hand‑written algorithm example

Quick Sort implementation (code omitted for brevity).

QuickSort illustration
QuickSort illustration
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaJVMconcurrencyinterview
IT Services Circle
Written by

IT Services Circle

Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.