Monday, September 7, 2009

SPRING interview Questions

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.

What do you mean by Aspect ?
 
A modularization of a concern that cuts across multiple objects. Transaction management is a good example of a crosscutting concern in J2EE applications. In Spring AOP, aspects are implemented using regular classes (the schema-based approach) or regular classes annotated with the @Aspect annotation (@AspectJ style).

 What do you mean by JointPoint?
 
A point during the execution of a program, such as the execution of a method or the handling of an exception. In Spring AOP, a join point always represents a method execution.

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?

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

What are the advantages of Spring framework?

The advantages of Spring are as follows: 

  • 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 IOC container in Spring Framework ?

The bean factory concept is foundation of Spring as an IOC container. IOC takes the responsibility for making things happen into the framework away from application code. Programmer needs to just configure which dependencies should be set.

BeanFactory interface, an implementation of the Factory design pattern enables objects to be created and retrieved by name. Relationships between objects can also be managed.

BeanFactory supports two object modes:

  1. Singleton mode provides a shared instance of the object with a particular name, which will be retrieved on lookup. Singleton is the default and most often used object mode. It is ideal for stateless service objects.
  2. Prototype mode ensures that each retrieval will result in the creation of an independent object. Prototype mode would be best used in a case where each user needed to have his own object.

The most commonly used BeanFactory definition is the XmlBeanFactory, which loads beans based on definitions in an XML file.

The most commonly used BeanFactory definition is the XmlBeanFactory, which loads beans based on definitions in an XML file.

BeanFactory factory = new XMLBeanFactory(new FileInputSteam("mybean.xml"));

Beans defined in XML files are lazily loaded, which means that the beans themselves will not be instantiated until they are needed. To retrieve a bean from BeanFactory you can simply call the getBean() method passing in the name of the bean you want to retrieve.

 

MyBean mybean = (MyBean) factory.getBean("mybean");

 

BeanFactory factory = new XMLBeanFactory(new FileInputSteam("mybean.xml"));

Beans defined in XML files are lazily loaded, which means that the beans themselves will not be instantiated until they are needed. To retrieve a bean from BeanFactory you can simply call the getBean() method passing in the name of the bean you want to retrieve.

 

MyBean mybean = (MyBean) factory.getBean("mybean");

What is Inversion of control concept of Spring Framework ?

The basic concept of the Inversion of Control pattern (dependency injection) is that programmers dont need to create your objects but describe how they should be created. Dont directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container (in the case of the Spring framework, the IOC container) is responsible for all this. In a IOC scenario, the container creates all the objects, connects them together by setting the necessary properties, and determines when methods will be invoked. The implementation pattern types for IOC used by SpringFramework are as follows:

  1. Dependencies can be assigned through JavaBeans properties (setter methods).
  2. Dependencies are provided as constructor parameters and are not exposed as JavaBeans Setter properties.

1

2

3

4

5

6

7

8

9

10

 

No comments:

Post a Comment