IoC (Inversion of Control) is a design principle in which the responsibility of creating and managing objects is transferred from the application code to a container or framework. DI (Dependency Injection) is the most common technique used to implement IoC by providing required dependencies from outside rather than creating them inside the class.
Consider a UserService class that requires a UserRepository. Instead of creating the UserRepository object using the new keyword, Spring automatically injects it into UserService. This makes the code more flexible and easier to test.
@Service
public class UserService {
private final UserRepository userRepository;
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
}A concise interview answer is
IoC is a design principle where the Spring container manages object creation and lifecycle. DI is a technique used to achieve IoC by injecting required dependencies into a class instead of letting the class create them. This promotes loose coupling and improves maintainability.
Last updated: 11 November 2026
Previous question: What is the difference between Spring and Spring Boot?
Next question: What is the role of the IoC container in Spring?