Java & Spring Boot Interview Q&A
Random Values
Example: 47, 83, 15, 62, 98, 21, 5, 74, 39, 56
Page 1
Java & Spring Boot Interview Q&A
Find Max of Sum of Two Values Using Streams
Java Streams can be used to compute max sum of two elements:
int maxSum = [Link]()
.flatMap(a -> [Link]().map(b -> a + b))
.max(Integer::compare)
.get();
Page 2
Java & Spring Boot Interview Q&A
Validation Annotations
@NotNull, @Size, @Email, @Pattern etc. Used in Spring Boot with Hibernate Validator.
Page 3
Java & Spring Boot Interview Q&A
Only String Values Validation
Use @Pattern(regexp="^[A-Za-z]+$") to accept only alphabets in a String field.
Page 4
Java & Spring Boot Interview Q&A
Actuator
Spring Boot Actuator provides production-ready endpoints for monitoring and managing apps.
Page 5
Java & Spring Boot Interview Q&A
Access Tokens
A credential issued after authentication, used to access protected resources without re-authenticating.
Page 6
Java & Spring Boot Interview Q&A
Spring Security Based on Roles
Configure method-level security using @PreAuthorize, @Secured, or HTTP security role mappings.
Page 7
Java & Spring Boot Interview Q&A
@Secured
Example: @Secured({"ROLE_ADMIN"}) on a method ensures only admin role can call it.
Page 8
Java & Spring Boot Interview Q&A
Two Databases in Spring Boot
Define two DataSources, two EntityManagerFactory beans, and configure @EnableJpaRepositories
separately.
Page 9
Java & Spring Boot Interview Q&A
One-to-Many Mapping
Example: In JPA, @OneToMany(mappedBy="parent") with List<Child> children; in Parent entity.
Page 10
Java & Spring Boot Interview Q&A
Application Deployment
Can deploy via Docker, Kubernetes, AWS ECS, EC2, etc.
Page 11
Java & Spring Boot Interview Q&A
Microservices
Architecture with multiple small, independent services communicating via REST, Kafka, gRPC, etc.
Page 12
Java & Spring Boot Interview Q&A
Kubernetes Secrets & ConfigMaps
Secrets store sensitive data (passwords, tokens). ConfigMaps store non-sensitive configs.
Page 13
Java & Spring Boot Interview Q&A
Rolling Updates
K8s gradually replaces old pods with new ones without downtime.
Page 14
Java & Spring Boot Interview Q&A
Security Questions
Covered topics like JWT, mTLS, hiding passwords, role-based security, etc.
Page 15
Java & Spring Boot Interview Q&A
mTLS
Mutual TLS ensures both client and server authenticate each other using certificates.
Page 16
Java & Spring Boot Interview Q&A
Use of JWT
JWT stores claims in a signed token for stateless authentication.
Page 17
Java & Spring Boot Interview Q&A
Client Credentials Flow
OAuth 2.0 flow for server-to-server authentication.
Page 18
Java & Spring Boot Interview Q&A
Future in Multithreading
Java's CompletableFuture supports async programming in multi-threaded environments.
Page 19
Java & Spring Boot Interview Q&A
Global Exception Handling
Use @ControllerAdvice with @ExceptionHandler to handle exceptions globally.
Page 20
Java & Spring Boot Interview Q&A
API Performance
Improve via caching, async processing, indexing, pagination, load balancing.
Page 21
Java & Spring Boot Interview Q&A
Rate Limit Implementation
Use libraries like Bucket4j or Resilience4j RateLimiter.
Page 22
Java & Spring Boot Interview Q&A
Fallback Mechanism
Resilience4j's @CircuitBreaker with fallback method for failures.
Page 23
Java & Spring Boot Interview Q&A
One-to-One Mapping
@OneToOne annotation in JPA links two entities directly.
Page 24
Java & Spring Boot Interview Q&A
Exception Order
Catch specific exceptions first, then generic ones.
Page 25
Java & Spring Boot Interview Q&A
Deadlocks
Avoid nested locks, use lock ordering, tryLock with timeout.
Page 26
Java & Spring Boot Interview Q&A
Code Review / PR Review
Check readability, performance, security, and test coverage.
Page 27
Java & Spring Boot Interview Q&A
SOLID Principles
Single Responsibility, Open/Closed, Liskov, Interface Segregation, Dependency Inversion.
Page 28
Java & Spring Boot Interview Q&A
ClassLoaders
Bootstrap, Extension, and Application classloaders load Java classes.
Page 29
Java & Spring Boot Interview Q&A
ClassNotFoundException
Thrown when class is missing from classpath at runtime.
Page 30
Java & Spring Boot Interview Q&A
SocketReadTimeout vs ConnectionTimeout
ConnectionTimeout -> time to establish connection.
SocketReadTimeout -> time waiting for data after connection.
Page 31
Java & Spring Boot Interview Q&A
OutOfMemoryError Reasons
Memory leaks, large objects, high concurrency, improper JVM settings.
Page 32
Java & Spring Boot Interview Q&A
Hide Password in Communication
Mask logs, use HTTPS, encrypt sensitive data before sending.
Page 33
Java & Spring Boot Interview Q&A
Hide Password in REST APIs
Do not expose in response, mask in logs, hash in DB.
Page 34
Java & Spring Boot Interview Q&A
JDK vs JVM vs JRE
JDK -> Development Kit, JVM -> Virtual Machine, JRE -> Runtime Environment.
Page 35
Java & Spring Boot Interview Q&A
Identify OutOfMemory in Grafana
Monitor heap usage, GC logs, and alert when memory is consistently high.
Page 36
Java & Spring Boot Interview Q&A
File Download in Spring Boot & AWS
Read file from S3 via AWS SDK and stream to HTTP response.
Page 37
Java & Spring Boot Interview Q&A
Data Structure for Millions of Ordered Unique Objects
Use LinkedHashSet for order + uniqueness.
Page 38
Java & Spring Boot Interview Q&A
PUT vs POST
PUT -> Idempotent updates, POST -> Create new resource.
Page 39
Java & Spring Boot Interview Q&A
Handling 8 New and 2 Existing Records via PUT
PUT should ideally update only existing resources; POST for new ones.
Page 40
Java & Spring Boot Interview Q&A
== vs === in JavaScript
== -> Loose equality with type coercion; === -> Strict equality without type coercion.
Page 41
Java & Spring Boot Interview Q&A
Tomcat Port 0
Assigns a random free port at runtime.
Page 42