Java Backend Interview Guide – With Solutions & Take■Home Assignment
1. Core Java & Multithreading – Questions & Solutions
Q1. Difference between synchronized and ReentrantLock?
Synchronized is simpler but blocks entirely; ReentrantLock offers timeout, fairness, interruptible
lock waits.
Q2. What is volatile?
Volatile guarantees visibility of changes across threads but does not ensure atomicity.
Q3. How does ThreadPoolExecutor work?
It manages worker threads, task queue, and rejection policies. Improves throughput by reusing
threads.
2. Spring Boot & REST APIs – Questions & Solutions
Q1. What is Spring Boot auto■configuration?
Spring Boot scans classpath and configures beans automatically unless explicitly overridden.
Q2. How do you design idempotent REST endpoints?
Use same input → same result; e.g., PUT, PATCH or unique request IDs.
Q3. How does @RestController differ from @Controller?
@RestController returns JSON directly; @Controller returns views.
3. Microservices Architecture – Questions & Solutions
Q1. How do services communicate?
Sync via REST; async via queues (Kafka/RabbitMQ). Async reduces coupling.
Q2. What is API gateway?
A single entry point for routing, auth, rate■limiting, and aggregations.
4. Performance Tuning & JVM Optimization – Solutions
Q1. How to diagnose high CPU?
Use top, jstack, async■profiler, identify loops or locks.
Q2. Common JVM flags?
-Xms, -Xmx, G1GC settings for controlled memory and stable GC.
5. CI/CD & Cloud
Q1. What is CI/CD?
Automated build, test, deploy pipeline using GitHub Actions/Jenkins.
Q2. What are readiness & liveness probes?
Readiness: can receive traffic; Liveness: app health for restarts.
Take■Home Coding Assignment
Assignment:
Build a Spring Boot microservice to manage SIM activation. Requirements: 1. Endpoints: POST
/activate, GET /status/{id} 2. Store data in an in■memory DB (H2) 3. Include validation, logging,
and global exception handler 4. Expose Prometheus metrics 5. Write at least 3 unit tests