Sunday, September 6, 2009

SPRING interview Questions

What is Spring?

Spring is a lightweight inversion of control and aspect-oriented container framework.

Explain spring?

         Lightweight – spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 1MB. And the processing overhead is also very negligible.

         Inversion of control (IOC) – Loose coupling is achieved in spring using the technique Inversion of Control. The objects give their dependencies instead of creating or looking for dependent objects.

         Aspect oriented (AOP) – spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services.

         Container – Spring contains and manages the life cycle and configuration of application objects.

         Framework - Spring provides most of the intra functionality leaving rest of the coding to thedeveloper

What are the different modules in spring framework?

         The Core container module

         Application context module

         AOP module (Aspect Oriented Programming)

         JDBC abstraction and DAO module

         O/R mapping integration module (Object/Relational)

         Web module

         MVC framework module

What is the Core container module?

This module is provides the fundamental functionality of the spring framework. In this module Bean Factory is the heart of any spring-based application. The entire framework was built on the top of this module. This module makes the spring container.

What is Application context module?

The Application context module makes spring a framework. This module extends the concept of Bean Factory, providing support for internationalization (I18N) messages, application lifecycle events, and validation. This module also supplies many enterprise services such JNDI access, EJB integration, remoting, and scheduling. It also provides support to other framework.

What is AOP module?

The AOP module is used for developing aspects for our Spring-enabled application. Much of the support has been provided by the AOP Alliance in order to ensure the interoperability between spring and other AOP frameworks. This module also introduces metadata programming to spring. Using spring’s metadata support, we will be able to add annotations to our source code that instruct spring on where and how to apply aspects.

What is JDBC abstraction and DAO module?

Using this module we can keep up the database code clean and simple, and prevent problems that result from a failure to close database resources. A new layer of meaningful exceptions on top of the error messages given by several database servers is bought in this module. In addition, this module uses spring’s AOP module to provide transaction management services for objects in a spring application.

What are object/relational mapping integration module?

Spring also supports for using of an object/relational mapping (ORM) tool over straight JDBC by providing the ORM module. Spring provide support to tie into several popular ORM frameworks, including Hibernate, JDO, and iBATIS SQL Maps. Spring’s transaction management supports each of these ORM frameworks as well as JDBC.

What is web module?

This module is built on the application context module, providing a context that is appropriate for web-based applications. This module also contains support for several web-oriented tasks such as transparently handling multipart requests for file uploads and programmatic binding of request parameters to your business objects. It also contains integration support with Jakarta Struts.

 What is a Bean Factory?

A Bean Factory is an implementation of the factory pattern that applies Inversion of Control to separate the application’s configuration and dependencies from the actual application code.

 What is AOP Alliance?

AOP Alliance is an open-source project whose goal is to promote adoption of AOP

and interoperability among different AOP implementations by defining a common

set of interfaces and components.

What is spring configuration file?

Spring configuration file is an XML file. This file contains the classes information and describes how these classes are configured and introduced to each other.

What does a simple spring application contain?

These applications are like any Java application. They are made up of several classes, each performing a specific purpose within the application. But these classes are configured and introduced to each other through an XML file. This XML file describes how to configure the classes, known as the Spring configuration file.

What is XMLBeanFactory?

Bean Factory has many implementations in Spring. But one of the most useful one isorg.springframework.beans.factory.xml.XmlBeanFactory, which loads its beans based on the definitions contained in an XML file. To create an XmlBeanFactory, pass a java.io.InputStream to the constructor. The InputStream will provide the XML to the factory. For example, the following code snippet uses a java.io.FileInputStream to provide a bean definition XML file to XmlBeanFactory.

BeanFactory factory = new XmlBeanFactory(newFileInputStream(”beans.xml”));

To retrieve the bean from a BeanFactory, call the getBean() method by passing the name of the bean you want to retrieve.

MyBean myBean = (MyBean) factory.getBean(myBean”);

What are important Application Context implementations in spring framework?

      ClassPathXmlApplicationContext – This context loads a context definition from an XML file located in the class path, treating context definition files as class path resources.

     FileSystemXmlApplicationContext – This context loads a context definition from an XML        file in the file system.

     XmlWebApplicationContext – This context loads the context definitions from an XML file     contained within a web application.

Explain Bean lifecycle in Spring framework?                  

1. The spring container finds the bean’s definition from the XML file and instantiates the bean.

2. Using the dependency injection, spring populates all of the properties as specified in the bean definition.

3. If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean’s ID.

4. If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself.

5. If there are any Bean Postprocessors associated with the bean, their post- ProcessBeforeInitialization() methods will be called.

6. If an init-method is specified for the bean, it will be called.

7. Finally, if there are any Bean Postprocessors associated with the bean, theirpostProcessAfterInitialization() methods will be called.

1

2

3

4

5

6

7

8

9

10

 

No comments:

Post a Comment