If you’re interviewing for a mid-to-senior Java backend role, the conversation changes.
At 6–10 years of experience, interviews are rarely about syntax alone. Interviewers care more about how you think through production systems, concurrency, architecture decisions, API design, scalability, and real-world tradeoffs.
You’re expected to go beyond “what” and explain “why”.
Here’s a practical collection of 31 commonly asked Java backend interview questions across Core Java, Spring Boot, REST APIs, concurrency, and microservices, along with the level of depth usually expected during L1 technical discussions.
Core Java Fundamentals
1. Can you override a static method in Java?
No.
Static methods belong to the class, not the object. If a subclass declares a method with the same signature, it results in method hiding, not overriding.
This is resolved at compile time.
Interviewers usually expect you to clearly differentiate:
- Compile-time polymorphism
- Runtime polymorphism
2. What is the purpose of the finally block?
The finally block executes whether an exception is thrown or not.
It’s commonly used for:
- Closing database connections
- Releasing resources
- Closing files or streams
It may not execute only if the JVM exits abruptly, such as with System.exit().
3. What is a marker interface?
A marker interface is an interface with no methods.
It’s used to provide metadata to the JVM or frameworks.
Examples:
SerializableCloneable
It marks a class with special behavior without forcing method implementation.
4. What is the difference between List and Set?
List
- Ordered
- Allows duplicates
- Supports index-based access
Set
- Does not allow duplicates
- May or may not preserve insertion order
- Faster lookups in hash-based implementations
Use Set when uniqueness matters.
5. Can you store null in HashMap and Hashtable?
HashMap
- One null key allowed
- Multiple null values allowed
Hashtable
- Null keys not allowed
- Null values not allowed
6. What happens when two keys collide in a HashMap?
If two keys produce the same hash:
- Both go into the same bucket
- Java uses
equals()to differentiate them - In Java 8+, buckets can convert from linked list to balanced tree when size crosses threshold
Understanding collisions is important because it impacts performance.
7. Is HashMap thread-safe?
No.
HashMap is not thread-safe.
For concurrent use cases:
ConcurrentHashMapCollections.synchronizedMap()
are safer choices.
ConcurrentHashMap is generally preferred because it allows better parallel access.
8. Which methods must you override when using a custom object as a Map key?
You should override:
equals()hashCode()
If not implemented correctly, key lookups will behave unpredictably.
Java 8 & Concurrency
9. Difference between map() and flatMap()?
map()
Transforms one element into another.
flatMap()
Flattens nested structures.
Example:
Stream<List<String>> → Stream<String>
Very common in Stream API transformations.
10. What is Optional used for?
Optional represents a value that may or may not be present.
It helps avoid:
NullPointerException
and makes null handling explicit.
11. Difference between Runnable and Callable?
Runnable
- No return value
- Cannot throw checked exceptions
Callable
- Returns a result
- Can throw checked exceptions
- Works with
Future
12. What does synchronized do?
synchronized provides thread safety by ensuring:
- Mutual exclusion
- Visibility guarantees between threads
Only one thread can execute a synchronized block at a time for a given lock.
13. Difference between sleep() and wait()?
sleep()
- Belongs to
Thread - Does not release lock
wait()
- Belongs to
Object - Releases lock
- Must be inside synchronized context
This is a very common interview question.
14. What is a deadlock?
Deadlock happens when two or more threads wait forever on each other’s locks.
Ways to avoid it:
- Lock ordering
- Timeouts
- Concurrent utilities
- Avoid nested locks where possible
Spring Boot Fundamentals
15. What is the default scope of a Spring bean?
singleton
Spring creates one instance per container by default.
16. How do you read property values in Spring Boot?
Using:
@Value@ConfigurationProperties
Properties are typically stored in:
application.propertiesapplication.yml
17. Which annotation creates a REST endpoint?
@RestController
Usually combined with:
@GetMapping@PostMapping@PutMapping@DeleteMapping
18. Path variable vs request parameter?
Path Variable
Part of URL path.
Example:
/users/{id}
Usually required.
Request Parameter
Passed in query string.
Example:
/users?id=10
Often optional.
HTTP & REST Concepts
19. What does HTTP 201 mean?
201 Created
It means the resource was successfully created.
Most commonly returned after POST operations.
20. Difference between 401 and 403?
401 — Unauthorized
Authentication required.
403 — Forbidden
User is authenticated but doesn’t have permission.
This distinction matters a lot in API security design.
21. Is REST stateless?
Yes.
REST is stateless.
Each request must contain everything needed to process it.
Server does not store client session state between requests.
Design Patterns & Principles
22. What is a DTO?
DTO = Data Transfer Object.
Used to transfer data between layers.
Benefits:
- Avoid exposing entities directly
- Cleaner API contracts
- Better version control for APIs
23. What is Singleton pattern?
Ensures only one instance exists.
Spring’s singleton bean scope is a practical example of this pattern.
24. What is Factory pattern?
Factory pattern creates objects without exposing object creation logic directly.
Benefits:
- Loose coupling
- Better abstraction
- Easier maintenance
25. What does “O” stand for in SOLID?
Open/Closed Principle
Software should be:
- Open for extension
- Closed for modification
You should be able to add behavior without changing existing code.
Microservices & Architecture
26. What is Circuit Breaker pattern?
Circuit breaker prevents cascading failures between services.
If downstream service fails repeatedly:
- Circuit opens
- Requests fail fast temporarily
- System recovers without overwhelming the failing dependency
Common in resilient microservices.
27. Why use an API Gateway?
API Gateway acts as a single entry point.
Responsibilities often include:
- Routing
- Authentication
- Rate limiting
- Logging
- Request aggregation
Very common in distributed systems.
28. What is service discovery?
Service discovery allows services to locate each other dynamically.
Useful because instances may scale up/down or move frequently.
Examples:
- Eureka
- Consul
- Kubernetes DNS
29. What is CAP theorem?
CAP says distributed systems can only guarantee two of:
- Consistency
- Availability
- Partition Tolerance
Tradeoffs are inevitable.
This often leads to architecture-level design discussions.
30. Monolith vs Microservices?
Monolith
- Single deployable application
- Easier to start
- Easier local development
- Harder to scale independently
Microservices
- Independently deployable
- Easier scaling per service
- Better ownership boundaries
- More operational complexity
There’s no universal winner. It depends on business scale and team maturity.
31. Have you worked with frontend frameworks?
Even as a backend engineer, frontend awareness matters.
Interviewers often look for understanding around:
- API contracts
- CORS
- Authentication flow
- Request/response debugging
- Working with frontend teams
You don’t need to be a frontend specialist, but cross-functional awareness is highly valued.
Takeaways
For Java backend interviews at the 6–10 year level, strong answers are rarely about memorization.
Interviewers usually look for:
- Clear reasoning
- Production experience
- Tradeoff thinking
- Debugging mindset
- Scalability awareness
- Communication clarity
Knowing the syntax helps.
Explaining why a design choice was made in production is what usually stands out.
If you’re preparing for interviews, focus less on definitions and more on:
- Why you chose that approach
- What problem it solved
- What tradeoffs you accepted
- What you would improve next time
That’s often the difference between a good answer and a senior-level answer.
If you found this article helpful, please give it a clap 👏, drop a comment and share it with friends who may find it useful, and follow for more updates.
Thanks for reading -see you in the next story! 💗
Comments
Loading comments…