<<< Spring Interview Questions and Answers >>>





Spring - Questions & Answers

Here is the list of Spring Interview Questions. The answers are short and to the point.These questions are frequently asked by the recruiters. So we try our best to provide you the Spring interview questions. A list of frequently asked Spring interview questions and answers are given below.

«« | 1 2 3 4 5 | »»

Spring : Java Interview Questions

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 :

  1. Core module
  2. Context module
  3. Bean module
  4. JDBC abstraction and DAO module
  5. ORM module
  6. Transaction module
  7. Expression Language
  8. Web module
  9. AOP module(Aspect Oriented Programming)
  10. JMS module
  11. Data Access / Integration
  12. MVC framework module


3) What are the advantages of spring framework?

Ans :The advantages of spring framework are :

  1. Reusability
  2. Loose Coupling
  3. Removal of leaking connections
  4. Lightweight
  5. Easy to integrate with third party tools and technologies.
  6. Powerful Abstraction
  7. 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. :

  1. Constructor-based dependency injection
  2. 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 :

  1. Bean Factory
  2. ApplicationContext

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 :

ApplicationContext 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.


«« | 1 2 3 4 5 | »»