Q1. What is the Spring Framework?
Spring is a comprehensive, open-source Java framework for building enterprise applications. It provides infrastructure support for developing robust applications, offering features like dependency injection, aspect-oriented programming, transaction management, and MVC framework. Spring simplifies Java development by promoting POJO-based programming and reducing boilerplate code.
Q2. What are the main modules of Spring Framework?
Spring is modular and consists of several modules: Core Container (Beans, Core, Context, SpEL), AOP (Aspect-Oriented Programming), Data Access/Integration (JDBC, ORM, Transaction), Web (Servlet, WebSocket, Portlet), and Test. This modularity allows developers to use only the required parts.
Q3. What is Inversion of Control (IoC) in Spring?
Inversion of Control is a principle where the control of object creation and lifecycle is transferred from the application to the container (Spring IoC container). Instead of creating objects with new, the container instantiates and manages beans, injecting dependencies where needed. This promotes loose coupling and testability.
Q4. What is Dependency Injection (DI)?
Dependency Injection is a design pattern where objects receive their dependencies from an external source rather than creating them internally. In Spring, DI is achieved through constructor injection, setter injection, or field injection. The container wires beans together based on configuration (XML, annotations, or Java config).
Q5. What are the advantages of using Spring Framework?
Advantages include: lightweight and non-intrusive, promotes POJO programming, provides comprehensive infrastructure support, excellent integration with other frameworks, supports declarative transactions, and offers robust testing capabilities. It also simplifies Java EE development and encourages best practices like programming to interfaces.
