Ace Java Backend Interviews: Spring Injection, MySQL Engines, Redis & JVM OOM
This article combines salary insights for ZTE offers, practical internship interview tips, a deep dive into Spring bean‑injection annotations, a side‑by‑side comparison of MySQL InnoDB and MyISAM, Redis usage patterns, and JVM OutOfMemoryError diagnostics to help you excel in Java backend interviews.
ZTE SSP offers this year range from 15k–28k per month (12‑month salary), with lower packages in Xi'an and higher in Shenzhen; many candidates with strong academic backgrounds consider other offers.
When discussing internship experience in interviews, introduce your contributions clearly, even if you mainly performed maintenance; you can frame simple feature work as meaningful involvement and, if possible, take on development tasks to boost personal growth.
Which annotations inject Beans?
Spring provides @Autowired, while the JDK provides @Resource and @Inject, all of which can be used for Bean injection. @Autowired – package org.springframework.bean.factory – Spring 2.5+ @Resource – package javax.annotation – Java JSR‑250 @Inject – package javax.inject – Java JSR‑330 @Autowired defaults to byType matching first, then falls back to byName if multiple beans of the same type exist. @Resource defaults to byName matching first, then byType if needed. When multiple implementations exist, both annotations require explicit naming via @Qualifier (for @Autowired) or the name attribute (for @Resource).
In practice, @Resource is preferred for name‑first injection because it is a standard JDK annotation and reduces tight coupling to Spring, while @Autowired shines with constructor injection for immutable dependencies.
MySQL InnoDB vs MyISAM
Key differences:
InnoDB supports row‑level locking; MyISAM only supports table‑level locking.
InnoDB provides transaction support, ACID compliance, and four isolation levels; MyISAM has no transaction support.
InnoDB supports foreign keys; MyISAM does not.
InnoDB supports MVCC and safe crash recovery via redo logs; MyISAM lacks both.
Both use B+Tree indexes, but InnoDB stores data and index together, while MyISAM stores them separately.
InnoDB generally offers better performance, especially under concurrent write workloads.
Why indexes are fast
Indexes are B+ trees that dramatically reduce disk I/O: a typical table needs only 3–4 I/O operations to locate a row, compared with thousands of scans for a full table scan. The leaf nodes are linked, enabling sequential reads that are friendly to disk prefetching.
Analyzing SQL execution plans
Use the EXPLAIN command to view the optimizer's execution plan and determine whether a query uses an index.
mysql> EXPLAIN SELECT `score`,`name` FROM `cus_order` ORDER BY `score` DESC;The output columns (id, select_type, table, type, possible_keys, key, rows, Extra, etc.) reveal the access method and whether an index is applied.
Redis usage in projects
Distributed locks (commonly via Redisson).
Rate limiting (Redis + Lua scripts or Redisson's RRateLimiter).
Message queues (List, Stream).
Delayed queues (Redisson's Sorted Set implementation).
Distributed sessions (String or Hash).
Complex scenarios such as user activity bitmap statistics and ranking with Sorted Set.
Answer these points according to your project's actual usage during interviews.
Cache‑Aside pattern: delete cache vs update cache
Write flow: update the database first, then delete the cache. Read flow: read from cache; if miss, read from DB and repopulate the cache. Deleting the cache avoids costly recomputation and reduces inconsistency risk in concurrent scenarios.
JVM regions that can cause OOM
Java heap (young and old generations).
Metaspace (class metadata).
Direct memory.
Thread stacks.
Native method stacks.
The program counter area never throws OutOfMemoryError.
Diagnosing OOM
Tools like MAT or JVisualVM can analyze heap dumps. MAT’s Leak Suspects report quickly points to the most likely leak, while the Dominator Tree view helps when the leak is not obvious.
Example leak simulation code:
import java.util.ArrayList;
import java.util.List;
public class SimpleLeak {
// static collection lives as long as the application
public static List<byte[]> staticList = new ArrayList<>();
public void leakMethod() {
// add a 1MB byte array each call
staticList.add(new byte[1024 * 1024]);
}
public static void main(String[] args) throws InterruptedException {
SimpleLeak leak = new SimpleLeak();
System.out.println("Starting leak simulation...");
for (int i = 0; i < 200; i++) {
leak.leakMethod();
System.out.println("Added " + (i + 1) + " MB to the list.");
Thread.sleep(200);
}
System.out.println("Leak simulation finished. Keeping process alive for Heap Dump.");
Thread.sleep(Long.MAX_VALUE);
}
}Run with a small heap (e.g.,
-Xmx128m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=simple_leak.hprof) to trigger an OOM and generate a heap dump.
Import the .hprof file into MAT; the Leak Suspects report will highlight the static staticList in SimpleLeak as the root cause, showing that the static collection prevents the large Object[] from being garbage‑collected.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
IT Services Circle
Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
