1) What is Spring?
Ans : Spring is an open source development framework for Enterprise Java. It is a lightweight, loosely coupled and integrated framework for developing enterprise applications in java.There are extensions for building web applications on top of the Java EE platform. It helps Java programmer for development of code and it provides IOC container, Dependency Injector,MVC flow and many other APIs for the java programmer.
2) Which are the Spring framework modules?
Ans :The Spring framework modules are :
- Core module
- Context module
- Bean module
- JDBC abstraction and DAO module
- ORM module
- Transaction module
- Expression Language
- Web module
- AOP module(Aspect Oriented Programming)
- JMS module
- Data Access / Integration
- MVC framework module
3) What are the advantages of spring framework?
Ans :The advantages of spring framework are :
- Loose Coupling
- Removal of leaking connections
- Easy to integrate with third party tools and technologies.
- Powerful Abstraction
- Predefined Templates
4) What is IOC or Dependency Injection?
Ans :IOC (Inversion of Control pattern) is also known as dependency injection.IOC a design pattern by which Loose coupling is achieved in Spring, with the Inversion of Control technique.It removes the dependency from the program.The objects give their dependencies instead of creating or looking for dependent objects.
5) What are the different types of IoC?
Ans :There are two types of IOC containers in spring framework. :
- Constructor-based dependency injection
- Setter-based dependency injection
Constructor-based dependency injection :Constructor-based DI is accomplished when the container invokes a class constructor with a number of arguments, each representing a dependency on other class.
Setter-based dependency injectionSetter-based DI is accomplished by the container calling setter methods on your beans after invoking a no-argument constructor or no-argument static factory method to instantiate your bean.
6) What is the difference between constructor injection and setter injection?
Ans : The difference between constructor injection and setter injection:
|Constructor Injection||Setter Injection|
|1. Constructor-based DI is accomplished when the container invokes a class constructor with a number of arguments, each representing a dependency on other class.||1. Setter-based DI is accomplished by the container calling setter methods on your beans after invoking a no-argument constructor or no-argument static factory method to instantiate your bean.|
|2. No Partial Injection.||2. Partial Injection.|
|3. Does not override the setter property.||3. Overrides the constructor property if both are defined.|
|4. Creates new instance if any modification occurs||4. Doesn't create new instance if you change the property value|
|5. Better for too many properties||5. Better for few properties.|
7) What is IOC Container?
Ans : The Spring IoC is responsible for creating the objects,managing them (with dependency injection (DI)), wiring them together, configuring them, as also managing their complete lifecycle.
8) What is the role of IOC container in spring?
Ans : The role of IOC container in spring is to instantiate, configure and assemble the objects.
9) What are the types of IoC containers?
Ans : The types of IoC containers are :
- Bean Factory
BeanFactory Container : This is the simplest container providing basic support for DI .It is a Lightweight container which loads bean definitions and manages your beans.The BeanFactory is usually preferred where the resources are limited like mobile devices or applet based applications. Beans are configured using XML file and manage singleton defined bean.It also removes adhoc singletons and factories.It is also responsible for life cycle methods and injects dependencies.
ApplicationContext Container This container adds more enterprise-specific functionality such as the ability to resolve textual messages from a properties file and the ability to publish application events to interested event listeners.
10) What is the difference between ApplicationContext and BeanFactory?
Ans : The difference between ApplicationContext and BeanFactory :
|1. ApplicationContext is the advanced container.||1. BeanFactory is the basic container.|
|2. ApplicationContext extends the BeanFactory interface||2. BeanFactory does not extends the BeanFactory interface|
|3. ApplicationContext allows more than one config files to exist.||3. BeanFactory only permits one config files to exist.|
|4. ApplicationContext can print events to beans registered as listeners.||4. BeanFactory cannot print events to beans registered as listeners.|