Spring Boot | Dependency Injection | Transactions | REST | SQL | Programming
Duration: 20 Minutes
Experience: 4–8 Years
This assessment evaluates Spring Boot fundamentals and production-ready backend concepts frequently used in enterprise applications.
Section A – Spring Boot MCQs (5 Questions)
Question 1 – Dependency Injection
Consider the following code:
interface NotificationService {
void send();
}
@Service
class EmailService implements NotificationService {
public void send() {}
}
@Service
class SmsService implements NotificationService {
public void send() {}
}
@Service
class AlertService {
@Autowired
private NotificationService notificationService;
}
What happens when the application starts?
A. EmailService is injected automatically
B. SmsService is injected automatically
C. Spring throws NoUniqueBeanDefinitionException
D. Compilation Error
Question 2 – @Qualifier
Assume the same classes as above.
Which annotation resolves the ambiguity?
A.
@Qualifier("emailService")
B.
@Order(1)
C.
@PrimaryBean
D.
@BeanName
Question 3 – Bean Scope
What is the default scope of a Spring Bean?
A. prototype
B. singleton
C. request
D. session
Question 4 – @Transactional
Which statement is TRUE?
A. It always starts a new transaction.
B. It rolls back only checked exceptions by default.
C. It rolls back on unchecked (RuntimeException) exceptions by default.
D. It cannot be used on service methods.
Question 5 – REST API
Which HTTP method is most appropriate for updating an existing resource completely?
A. GET
B. POST
C. PUT
D. DELETE
Section B – SQL Challenge
Question 6
Tables
CUSTOMER
| ID | NAME |
|---|---|
| 1 | Alice |
| 2 | Bob |
| 3 | Charlie |
ORDERS
| ORDER_ID | CUSTOMER_ID | AMOUNT |
|---|---|---|
| 101 | 1 | 500 |
| 102 | 1 | 200 |
| 103 | 2 | 1000 |
Query
SELECT C.NAME,
SUM(O.AMOUNT)
FROM CUSTOMER C
LEFT JOIN ORDERS O
ON C.ID = O.CUSTOMER_ID
GROUP BY C.NAME;
Which statement is correct?
A. Charlie is excluded
B. Charlie appears with NULL total amount
C. Query throws an error
D. Only Alice and Bob appear
Section C – Programming Questions
Question 7 – Group Employees by Department
Given
class Employee {
String name;
String department;
}
Using Java 8 Streams, group employees by department.
Expected Output
IT -> [John, Steve]
HR -> [Mary]
Finance -> [David]
Question 8 – Highest Salary Per Department
Given
class Employee {
String department;
int salary;
}
Using Java 8 Streams, print the highest salary for each department.
Expected Output
IT -> 90000
HR -> 70000
Finance -> 85000
Question 9 – Longest Word
Write a Java program to find the longest word in a sentence.
Example
Java Spring Boot Microservices
Expected Output
Microservices
Bonus
Solve using Java 8 Streams.
Answer Key & Detailed Explanations
Question 1
Correct Answer: C
Explanation
Spring finds two beans implementing NotificationService:
EmailServiceSmsService
Since no bean is marked as preferred and no qualifier is provided, dependency injection becomes ambiguous.
Spring throws:
NoUniqueBeanDefinitionException
Interview Follow-up
- How can this be resolved?
- Difference between
@Primaryand@Qualifier.
Question 2
Correct Answer: A
Explanation
@Qualifier("emailService") explicitly tells Spring which bean to inject.
Example:
@Autowired
@Qualifier("emailService")
private NotificationService notificationService;
Alternative solution:
Annotate one implementation with:
@Primary
Question 3
Correct Answer: B
Explanation
Unless specified otherwise, Spring creates a single shared instance of each bean.
Default scope:
singleton
Other common scopes include:
- prototype
- request
- session
- application
Question 4
Correct Answer: C
Explanation
By default, Spring rolls back transactions only for unchecked exceptions (RuntimeException and Error).
Checked exceptions require explicit configuration:
@Transactional(rollbackFor = Exception.class)
Question 5
Correct Answer: C
Explanation
REST guidelines:
| Method | Purpose |
|---|---|
| GET | Read |
| POST | Create |
| PUT | Replace entire resource |
| PATCH | Partial update |
| DELETE | Remove resource |
Question 6
Correct Answer: B
Explanation
LEFT JOIN returns every customer.
Charlie has no matching orders.
SUM(O.AMOUNT) therefore evaluates to NULL for Charlie.
Result
Alice 700
Bob 1000
Charlie NULL
Interview Follow-up
How would you return 0 instead of NULL?
Expected Answer:
COALESCE(SUM(O.AMOUNT),0)
Question 7 – Sample Solution
employees.stream()
.collect(Collectors.groupingBy(
Employee::getDepartment,
Collectors.mapping(
Employee::getName,
Collectors.toList())))
.forEach((k,v)->
System.out.println(k+" -> "+v));
Concepts Tested
groupingBymapping- Method References
Question 8 – Sample Solution
employees.stream()
.collect(Collectors.groupingBy(
Employee::getDepartment,
Collectors.maxBy(
Comparator.comparingInt(
Employee::getSalary))))
.forEach((k,v)->
System.out.println(k+" -> "+v.get().getSalary()));
Alternative:
Use Collectors.collectingAndThen() to avoid calling get() on the Optional.
Question 9 – Sample Solution
Traditional
String longest = "";
for(String word : sentence.split(" ")){
if(word.length() > longest.length()){
longest = word;
}
}
System.out.println(longest);
Java 8
Arrays.stream(sentence.split(" "))
.max(Comparator.comparingInt(String::length))
.ifPresent(System.out::println);
Complexity
Time: O(n)
Space: O(1) (excluding the array created by split())
Evaluation Guide
| Score | Recommendation |
|---|---|
| 9/9 | Excellent – Strong Spring Boot Developer |
| 7–8 | Good – Recommended for Technical Round |
| 5–6 | Average – Needs Further Evaluation |
| Below 5 | Not Recommended |
Interviewer’s Notes
This set evaluates practical Spring Boot knowledge expected from backend developers.
A strong candidate should be able to explain:
- Why Spring fails when multiple beans implement the same interface.
- When to use
@Qualifierversus@Primary. - Why singleton is the default bean scope.
- How
@Transactionalbehaves with checked and unchecked exceptions. - Appropriate HTTP methods for REST APIs.
- How
LEFT JOINinteracts with aggregate functions such asSUM(). - How Java 8 collectors (
groupingBy,mapping,maxBy) simplify business logic.
Candidates who answer the follow-up questions confidently are typically ready for deeper discussions on Spring Boot architecture, transactions, and microservices.