midJava

What is dependency injection in Java?

Updated May 6, 2026

Short answer

Dependency Injection is a design pattern where dependencies are provided externally instead of created inside a class.

Deep explanation

It promotes loose coupling by delegating object creation to frameworks or external configuration. Common in Spring Framework.

Real-world example

Used in Spring Boot applications for service and repository wiring.

Common mistakes

  • Creating dependencies using 'new' inside classes.

Follow-up questions

  • What are types of DI?
  • Why is DI useful?

More Java interview questions

View all →