Comprehensive Java Backend Interview Guide: From MySQL Locks to Thread States

This article compiles detailed Java backend interview questions and answers, covering MySQL lock types, thread lifecycle states, garbage collection mechanisms, volatile semantics, RabbitMQ reliability, delayed queues, Zset usage, and practical coding examples.

IT Services Circle
IT Services Circle
IT Services Circle
Comprehensive Java Backend Interview Guide: From MySQL Locks to Thread States

Author Xiao Lin shares a collection of Java backend interview topics gathered from the 26th batch of Jingwei Hengrun recruitment, providing concrete salary data, job role insights, and a thorough technical Q&A.

Salary Overview

The annual pre‑tax salaries range from 22w to 30w, with a 12% housing fund contribution. Positions include Frontend Development, Embedded Development, C++ Software Development, Test Development, and Java Backend roles, with details on base salary, bonuses, and work locations.

Interview Questions and Answers

1. Difference between Overloading and Overriding

Overloading : Multiple methods with the same name in the same class but different parameter lists; the compiler selects the appropriate method based on argument types.

Overriding : Subclass redefines a method from its superclass with identical signature; indicated by @Override.

2. Abstract Class vs Interface

Abstract Class : Can contain fields, constructors, and concrete methods; used when classes share a clear inheritance hierarchy.

Interface : Defines a contract with abstract methods (Java 8+ allows default and static methods); a class can implement multiple interfaces.

Key differences: extends vs implements, single inheritance for abstract classes, multiple inheritance via interfaces, and member variable rules.

3. Purpose of the Parent‑Delegation Model

Ensures class uniqueness by delegating loading requests to the bootstrap class loader.

Improves security by preventing untrusted classes from overriding core Java classes.

Supports hierarchical class loading, simplifying maintenance and enabling sandboxing.

Reduces loading overhead by centralising most class loads.

4. volatile Keyword and Instruction Reordering

Guarantees visibility of writes to all threads by flushing writes to main memory and reading directly from it.

Prevents certain reordering through memory barriers: write‑write, read‑write, and write‑read barriers.

5. RabbitMQ Reliability Guarantees

Three layers must be secured:

Producer : Enable Publisher Confirm, handle network failures, optionally use transactions.

Broker : Persist queues and messages, configure dead‑letter exchanges, use clustering/mirroring for HA.

Consumer : Use manual acknowledgments, implement idempotent processing, control consumption rate.

6. Delayed Queues and Dead‑Letter Mechanism

Delayed queues hold messages until a timestamp expires, typically using an x‑delayed‑message exchange. Dead‑letter queues capture undeliverable or expired messages, allowing separate handling or retries.

7. Java Garbage Collection Algorithms

Mark‑Sweep : Marks reachable objects then frees unmarked memory (may cause fragmentation).

Mark‑Compact : Moves live objects together to eliminate gaps.

Copying : Uses two semi‑spaces; live objects are copied to the other space, leaving the original empty (used in young generation).

Modern JVMs apply generational collection: copying for the young generation, and mark‑compact or mark‑sweep for the old generation. Common collectors include Serial, Parallel, CMS, G1, ZGC, and Shenandoah.

8. MySQL Lock Types

Locks are categorized by scope:

Global Lock : FLUSH TABLES WITH READ LOCK makes the whole database read‑only, used for logical backups.

Table‑Level Locks : LOCK TABLES, metadata locks (MDL), and intention locks for coordinating row‑level locks.

Row‑Level Locks : Record locks (S/X), gap locks, and next‑key locks used by InnoDB to prevent phantom reads.

Examples of usage and practical considerations are provided.

9. MySQL Read vs Write Locks

Read (shared) locks allow concurrent reads but block writes; write (exclusive) locks block both reads and writes. Commands: SELECT ... LOCK IN SHARE MODE for read locks, SELECT ... FOR UPDATE for write locks.

10. Join Types in SQL

Illustrates INNER, LEFT, RIGHT, and FULL joins with example queries and notes that MySQL implements FULL JOIN via UNION.

11. Redis Zset Practical Uses

Leaderboards: ZADD, ZREVRANGE, ZREVRANK, ZSCORE.

Delayed task queues: store task IDs with execution timestamps, poll with ZRANGEBYSCORE, remove with ZREM.

Range queries: retrieve elements within score intervals using ZRANGEBYSCORE or ZREVRANGEBYSCORE.

Weighted message queues: prioritize processing based on score.

12. Thread Lifecycle in Java

Six states defined in java.lang.Thread.State:

NEW : Thread created but not started.

RUNNABLE : Ready to run or currently executing.

BLOCKED : Waiting for a monitor lock.

WAITING : Waiting indefinitely for another thread’s action.

TIMED_WAITING : Waiting for a specified time.

TERMINATED : Execution completed.

Each state’s meaning and typical transitions are described.

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.

JavamysqlRabbitMQbackend interviewRedis ZsetThread Lifecycle
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.