Senior Java & Spring Boot Interview – Questions and Answers
1. Java 8 Streams – Uppercase Strings
Use map() to transform each element.
List result = [Link]().map(String::toUpperCase).toList();
2. First Non-Repeating Character in "swiss"
Use LinkedHashMap to preserve order.
char ch = "swiss".chars()
.mapToObj(c -> (char)c)
.collect([Link](c -> c, LinkedHashMap::new, [Link]()))
.entrySet().stream().filter(e -> [Link]() == 1)
.map([Link]::getKey).findFirst().orElse(null);
3. Departments with More Than 10 Employees
SELECT department, COUNT(*) FROM employee GROUP BY department HAVING COUNT(*) >
10;
4. SOLID Principles
S – Single Responsibility: One class, one responsibility.
O – Open/Closed: Open for extension, closed for modification.
L – Liskov Substitution: Subtypes replace base types.
I – Interface Segregation: Many small interfaces.
D – Dependency Inversion: Depend on abstractions, not concretions.
5. Immutability
An object whose state cannot change after creation.
6. Making a Class Immutable
Declare class final, fields private final, no setters, defensive copies.
7. Responsibility of Garbage Collector
Automatically frees heap memory by removing unreachable objects.
8. Dependency Injection
Providing dependencies externally. Types: Constructor, Setter, Field injection.
9. Application Deployment
CI/CD pipeline → build → test → containerize → deploy to server/cloud.
10. Partial Changes to Production
Use feature branching, cherry-pick commits, or feature toggles.
11. Shallow vs Deep Copy
Shallow: copies references. Deep: copies actual objects (Clone/Serialization).
12. Lambda Expressions
Runnable r = () -> [Link]("Hello");
13. Spring Bean Lifecycle
Instantiate → Populate → Aware → Init → Ready → Destroy.
14. Spring Bean Scopes
Singleton, Prototype, Request, Session, Application.
15. Authentication in Spring Boot
Spring Security with JWT/OAuth2, filters, and authentication providers.
16. Transaction Data Consistency
ACID properties using @Transactional.
Reflection
Runtime inspection/modification of classes, used in frameworks.
Executor Framework
Manages thread pools for async tasks.
ThreadPoolExecutor vs ForkJoin
ThreadPool: independent tasks. ForkJoin: divide-and-conquer tasks.
RestTemplate
Synchronous REST client (now replaced by WebClient).
Reactive WebClient Error Handling
onErrorResume, onErrorMap, retry mechanisms.
Kafka Partition
Unit of parallelism and ordering within a topic.
LinkedHashMap vs TreeMap
LinkedHashMap preserves insertion order; TreeMap sorts keys.
Singleton Pattern
Private constructor, static instance, getInstance().
Testing
JUnit, Mockito, integration tests, test data via SQL/scripts/mocks.
Code Optimization
Profiling, caching, async processing, DB tuning.
Conclusion
These answers reflect real-world senior developer experience and best practices.