Mastering Java Backend Interview Questions: Concurrency, JVM, Spring, and Distributed Systems

This article compiles typical Java backend interview questions and detailed answers covering self‑introduction, personal growth, concurrency primitives, JVM memory management, GC tuning, cache design, large‑scale data storage, Spring IoC, AOP, distributed session handling, and common design patterns.

ITFLY8 Architecture Home
ITFLY8 Architecture Home
ITFLY8 Architecture Home
Mastering Java Backend Interview Questions: Concurrency, JVM, Spring, and Distributed Systems

First Interview

1. Self‑introduction (under 3 minutes). 2. How much have you improved since undergraduate studies? 3. Biggest progress during graduate studies. 4. Which development direction suits you best? 5. Difference between synchronized and Lock, usage scenarios, and whether you have read the synchronized source code. 6. JVM automatic memory management, trigger mechanisms of Minor GC and Full GC. 7. Have you done JVM tuning? Basic ideas: let each GC reclaim as many objects as possible. 8. For CMS, how to set the sizes of young and old generations? Start with defaults, then adjust based on GC logs and memory‑usage patterns. 9. How to design a storage system for massive data? 10. Cache implementation principles and design considerations (hot data in memory, consistency, cache avalanche, breakdown, penetration). 11. Where does popular product information reside in JVM memory? 12. How does volatile guarantee memory visibility? 13. Happen‑before principle. 14. Principle of Lucene full‑text search. 15. Which development area do you think you are suitable for and why? 16. Desired internship location.

Key JVM tuning points: if CPU usage is high and GC is frequent/slow, consider tuning. Aim to let each GC collect as many objects as possible. For CMS, adjust young/old generation sizes iteratively: increase young generation if Minor GC is frequent and inefficient; increase old generation if Full GC is frequent and does not reduce memory usage (possible memory leak) or if it does reduce usage (not a leak).

For G1 collector, a larger Java heap is acceptable because G1 uses region‑based collection and can keep pause times under control.

Second Interview

1. Self‑introduction (under 3 minutes). 2. Discuss Java lock types and differences:

Fair lock vs. non‑fair lock (implemented in ReentrantLock, not in synchronized).

Reentrant lock – a thread can acquire the same lock multiple times, useful for recursion and avoiding deadlock.

Exclusive lock vs. shared lock (read‑write lock: ReentrantReadWriteLock).

Optimistic lock vs. pessimistic lock (CAS & version number vs. explicit locking).

Segmented lock (used in Java 7 ConcurrentHashMap).

Biased lock, lightweight lock, heavyweight lock (optimizations in JDK 1.6).

Spin lock – busy‑waiting without blocking.

3. How to guarantee memory visibility: volatile uses memory barriers; synchronized flushes changes to main memory on lock release.

4. HTTP request process and principles.

5. TCP three‑handshake and four‑handshake, why three handshakes are required.

6. AOP principle: static weaving, dynamic proxy; differences between JDK dynamic proxy and CGLIB.

7. Proxy implementation steps: create an interface, its implementation class, and a proxy class that delegates to the implementation.

8. Spring IoC container loading process (simplified):

public void refresh() throws BeansException, IllegalStateException {
    synchronized (this.startupShutdownMonitor) {
        prepareRefresh();
        ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();
        prepareBeanFactory(beanFactory);
        try {
            postProcessBeanFactory(beanFactory);
            invokeBeanFactoryPostProcessors(beanFactory);
            registerBeanPostProcessors(beanFactory);
            initMessageSource();
            initApplicationEventMulticaster();
            onRefresh();
            registerListeners();
            finishBeanFactoryInitialization(beanFactory);
            finishRefresh();
        } catch (BeansException ex) {
            if (logger.isWarnEnabled()) {
                logger.warn("Exception encountered during context initialization - cancelling refresh attempt: " + ex);
            }
            destroyBeans();
            cancelRefresh(ex);
            throw ex;
        } finally {
            resetCommonCaches();
        }
    }
}

9. Have you studied bytecode compilation? (Answer: not really).

Third Interview

1. Self‑introduction (about 2 minutes). 2. Which project are you most familiar with? – a database‑centric project. 3. Why did you work on this project? – company‑level refactoring. 4. Architecture and database design – simple MVC. 5. Database tables and their purposes. 6. Core modules and inter‑module communication. 7. Where is the session stored?

8. Session persistence methods and trade‑offs:

Cookie – client‑side, easy to tamper.

Session – server‑side, can pressure the server; in distributed setups can be stored in a database.

Advantages: simple, high performance, supports distributed clusters, survives server restarts, works with Tomcat/Jetty.

Disadvantages: need to manage expiration, cannot handle frequent session reads/writes.

9. Token‑based authentication (JWT) for multi‑terminal or app scenarios. Tokens are stored in Redis or directly validated via JWT without Redis.

JWT token consists of three parts: Header – type (JWT) and algorithm, Base64‑encoded. Payload – user identity and claims (e.g., issuance and expiration time), Base64‑encoded. Signature – generated from Header + Payload + secret key, used to verify integrity.

10. Distributed session management solutions: Redis cache, database storage.

11. Binary search process – requires sorted data, repeatedly compare middle element and narrow the search range.

12. QuickSort process and pseudo‑code:

function quickSort(arr, left, right):
    if left >= right: return
    pivot = arr[left]
    i = left
    j = right
    while i < j:
        while i < j and arr[j] >= pivot: j--
        while i < j and arr[i] <= pivot: i++
        if i < j: swap(arr[i], arr[j])
    swap(arr[left], arr[i])
    quickSort(arr, left, i-1)
    quickSort(arr, i+1, right)

13. Design patterns you know and examples in JDK/Spring source code:

Singleton – Spring IoC container.

Template – Spring MVC, IoC.

Builder – Lombok.

Factory – IoC.

Proxy – AOP.

Publish/Subscribe – Message queues, Redis pub/sub.

Fourth Interview

1. Self‑introduction. 2. Introduce your most familiar project – MVC architecture, uses Lucene and AOP for permission management. 3. Main courses you study – Java, data structures, mathematical modeling. 4. Current research direction (unspecified). 5. Hometown and favorite books. 6. Expected internship start date. 7. Summary of the fourth interview.

Fifth Interview

1. Self‑introduction. 2. Projects you have done. 3. Opinion on Alipay and how you would design storage for massive payment data. 4. Why you want to intern at Alipay. 5. Your tech stack and curiosity about mobile payments. 6. How classmates and teachers evaluate you. 7. How you resolve disagreements with colleagues – ensure mutual understanding, compare impacts, choose the best solution based on pros and cons.

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.

JVMbackend-developmentspringinterview
ITFLY8 Architecture Home
Written by

ITFLY8 Architecture Home

ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, and more.

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.