Monday, February 16, 2009

Spring interview questions

<-Pre HomeNext->
Best Spring interview questions

What is Framework?
A framework is a basic conceptual structure used to solve or address complex issues.

A software framework is a re-usable design for a software system (or subsystem). A software framework may include support programs, code libraries, a scripting language, or other software to help develop and glue together the different components of a software project.

What is Spring?
Spring is a lightweight inversion of control and aspect-oriented container framework.
OR
Spring is a lightweight open source framework to develop enterprise applications using POJOs as building blocks and dependency injection.

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.

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

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.

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 the developer.

JDBC Exception Handling: The JDBC abstraction layer of the Spring offers a meaningful exception hierarchy, which simplifies the error handling strategy. Integration with Hibernate, JDO, and iBATIS: Spring provides best Integration services with Hibernate, JDO and iBATIS.

Why is Spring Framework needed anyway?
The main aim of Spring is to make J2EE easier to use and promote good programming practice.It does not reinvent the wheel but makes existing technologies easier to use. The main advantages of Spring framework are enumerated as given below:--No matter whether you use EJBs or Struts Framework or any other framework for writing business objects, Spring organizes your business objects in an effective manner with configuration management services on any runtime environment.You can keep one calling mechanism for your business objects while changing the implementation technology of them altogether.-Spring allows you to get rid of EJBs,if one wants to,no more compulsory to have,with alternative technologies like POJOs for building business objects and AOP provides a way to handle declarative transaction management, making EJB container absolutely not required. -Increased development productivity-Increased runtime performance-Improving test coverage as unit testing of code can easily be done.

What are the different modules in Spring framework?
Core container module, Application context module, AOP module, JDBC abstraction and DAO module, O/R mapping integration module (Object/Relational)
Web module
MVC framework module

What is AOP?
Aspect-oriented programming, or AOP, is a programming technique that allows programmers to modularize crosscutting concerns, or behavior that cuts across the typical divisions of responsibility, such as logging and transaction management. The core construct of AOP is the aspect, which encapsulates behaviors affecting multiple classes into reusable modules.

How the AOP used in Spring?
AOP is used in the Spring Framework:To provide declarative enterprise services, especially as a replacement for EJB declarative services. The most important such service is declarative transaction management, which builds on the Spring Framework’s transaction abstraction.To allow users to implement custom aspects, complementing their use of OOP with AOP.

Explain Bean lifecycle in Spring framework?

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

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

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

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

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

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

> Finally, if there are any Bean Postprocessors associated with the bean, their postProcessAfterInitialization() methods will be called.

How to integrate Spring and Hibernate ?
Spring and Hibernate can integrate using Spring’s SessionFactory called LocalSessionFactory. The integration process is of 3 steps.
> Configure Hibernate mappings.
> Configure Hibernate properties.
> Wire dependant object to SessionFactory.

How Spring relate to MVC framework ?
In Spring's Web MVC framework : a DispatcherServlet that dispatches requests to handlers.The default handler is a very simple Controller interface, just offering a ModelAndView handleRequest(request,response) method.

Explain ApplicationContext in Spring framework.?
A Spring ApplicationContext is a subinterface of BeanFactory.It is somewhat similar to BeanFactory in terms that both define beans,bind them together and make them available on request.In its functioning and ApplicationContext has following advanced features:-Resolving Messages, supporting internationalization-Support for an eventing mechanism, allowing application objects to publish events and they can register to be notified of events optionally.-Supports generic loading and access of file resources like image files.-Supports customization of container behavior through automatic recognition of special application-specific or generic, bean definitions.

What is BeanFactory?
In core packages of Spring org.springframework.beans.factory there is an interface named BeanFactory that can be implemented in various ways.It represents a generic factory that enables objects to be retrieved by name and which can manage relationships between objects.A BeanFactory contains different beans definitions which can be instantiated whenever a client wishes to do so , it is, hence, associated with life cycle of bean instances.Bean factories support two modes of object:-Singleton : a single,uniquely named, shared instance of an object which will be retrieved on lookup. It is the default, and most often used. It's ideal for stateless service objects.-Prototype or non-singleton: each retrieval results in an independent object creation.It could be used in stateful service objects scenarios where each caller has its own independent object.The most commonly used bean factory objects are: -XmlBeanFactory.

What are the different types of bean injections?
There are two types of bean injections.
1. By setter
2. By constructor

What are the advantages of Spring framework?
>Spring has layered architecture. Use what you need and leave you don't need now.
>Spring Enables POJO Programming. There is no behind the scene magic here. POJO programming enables continuous integration and testability.
>Dependency Injection and Inversion of Control Simplifies JDBC
>Open source and no vendor lock-in.

What is Spring's Web package?
This package provides basic web-oriented integration features, like multipart file-upload functionality or initialization of the IoC container using servlet listeners and a web-oriented application context. When using Spring together with Struts or any other web framework, this is the package to integrate with.

What is Spring DAO package?
This Package provides a JDBC-abstraction layer that removes the need to write JDBC coding and parsing database-vendor specific error codes.

What do you mean by Advice?
Action taken by an aspect at a particular join point. Different types of advice include “around,” “before” and “after” advice. Many AOP frameworks, including Spring, model an advice as an interceptor, maintaining a chain of interceptors “around” the join point.

What is Spring ORM package ?
This Package provides integration layers for popular object-relational mapping. APIs, like JDO, Hibernate etc. Using the ORM package you can use all those O/R-mappers in combination with all the other features Spring offers, such as the simple declarative transaction management feature.



Pre->hibernate

Next->javascript


*****Please feel free to give feedback at shrawan.iitg@gmail.com and comments below *****

No comments:

Post a Comment