McDonald's Java Backend Interview Experience: IoC/DI, MyBatis, JVM, Concurrency, Docker/K8s
The article recounts a McDonald's China backend interview, explaining IoC/DI concepts, MyBatis benefits, JVM garbage‑collection and memory layout, MySQL engine differences, concurrency locking strategies, RPC advantages over HTTP, HTTPS basics, essential Docker/Kubernetes commands, and a typical Git workflow.
This article shares a candidate's interview experience for a Java backend position at McDonald's China Technology R&D Center. It covers core Java backend topics frequently asked in interviews.
The interviewee explains Inversion of Control (IoC) and Dependency Injection (DI). IoC shifts object creation and dependency management from the code to an external container. DI is a concrete implementation of IoC, injecting dependencies via constructor, setter, or interface. Example code shows a UserService class that traditionally creates its own UserDao, and the refactored version receiving UserDao through constructor injection:
public class UserService {
private UserDao userDao;
public UserService(UserDao userDao) {
this.userDao = userDao;
}
// other methods
}The article discusses MyBatis advantages over traditional JDBC: flexible SQL programming, reduced code量, good database compatibility, easy Spring integration, and mapping tags for ORM.
JVM garbage collection algorithms are reviewed: mark‑sweep (suffers from fragmentation), copy algorithm (solves fragmentation but halves usable memory), mark‑compact (moves surviving objects to one end), and generational collection (young/old generations based on object lifespan).
The JVM memory layout per JDK 8 is described: program counter, VM stack, native method stack, heap (young/old generations), method area (metaspace), runtime constant pool, and direct memory.
MySQL storage engines are compared: InnoDB (default, supports ACID, row‑level locking, crash recovery), MyISAM (low storage, table‑level locking, no transactions), and Memory (in‑memory, data lost on restart).
Java concurrency thread safety is ensured via atomicity (synchronized/atomic), visibility (synchronized/volatile), and ordering (happens‑before). Optimistic locking assumes rare conflicts and checks before updating; pessimistic locking assumes frequent conflicts and locks upfront.
RPC (Remote Procedure Call) lets a program invoke a method on another machine as if it were local, hiding network details. Advantages include higher development efficiency, better performance via efficient protocols and serialization, and improved scalability through distributed deployment. RPC outperforms HTTP because it uses lightweight custom protocols, avoids bulky headers, and often includes connection pooling, async calls, and load balancing.
HTTPS adds SSL/TLS encryption to HTTP, uses port 443, requires CA certificates, and involves an extra TLS handshake after TCP three‑way handshake.
Common Docker commands: pull, build, rmi, run, ps, exec. Common Kubernetes commands: kubectl apply/get/delete/exec/scale for Pods, Deployments, Services, and nodes.
Git workflow: pull → add . → commit -m → push; undo commit with git reset --soft/--mixed HEAD^; undo push with git reset HEAD^ then force‑push.
Java Tech Enthusiast
Sharing computer programming language knowledge, focusing on Java fundamentals, data structures, related tools, Spring Cloud, IntelliJ IDEA... Book giveaways, red‑packet rewards and other perks await!
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.