Wednesday 29 April 2015

Java Source World: Spring Interview Questions




Spring Interview Questions:


Popular Spring interview questions:


Q : What is Spring ?

A: Spring is an open source development framework for enterprise Java. T he core features of the Spring Framework can be used in developing any Java application, but there are extensions for building web applications on top of the Java EE platform. Spring framework targ ets to make J2EE development easier to use and promote good prog ramming practice by enabling a POJO-based prog ramming model.

Q : what are benefits of using spring ?

A: Following is the list of few of the great benefits of using Spring Framework:
Lightweight: Spring is lightweight when it comes to size and transparency. T he basic version of spring framework is around 2MB.

Inversion of control (IO C): Loose coupling is achieved in spring using the technique Inversion of Control. The objects g ive 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 log ic from system services.
Container: Spring contains and manages the life cycle and configuration of application objects.

MVC Framework: Spring 's web framework is a well-designed web MVC framework, which provides a great alternative to web frameworks such as Struts or other over eng ineered or less popular web frameworks.

Transaction Management: Spring provides a consistent transaction management interface that can scale down to a local transaction (using a sing le database, for example) and scale up to g lobal transactions (using JT A, for example).

Exception Handling : Spring provides a convenient API to translate technology-specific exceptions (thrown by JDBC, Hibernate, or JDO, for example) into consistent, unchecked exceptions.

Q : What are the different modules in Spring framework?

A: Following are the modules of the Spring framework:
  1. Core module
  2. Bean module
  3. Context module
  4. Expression Lang uag e module
  5. JDBC module
  6. ORM module
  7. OXM module
  8. Java Messaging Service(JMS) module
  9. Transaction module
  10. Web module
  11. Web-Servlet module
  12. Web-Struts module
  13. Web-Portlet module

Q : What is Spring configuration file?

A: Spring configuration file is an XML file. T his file contains the classes information and describes how these classes are config ured and introduced to each other.

Q : What is Dependency Injection?
A: Inversion of Control (IoC) is a general concept, and it can be expressed in many different ways and Dependency Injection is merely one concrete example of Inversion of Control.
This concept says that you do not create your objects but describe how they should be created. You don't directly connect your components and services tog ether in code but describe which services are needed by which components in a configuration file. A container (the IOC container) is then responsible for hooking it all up.

Q : What are the different types of IoC (dependency injection)?
A: Types of IoC are:

Construc tor-based dependenc y injec tion: Constructor-based DI is accomplished when the container invokes a class constructor with a number of arg uments, each representing a dependency on other class. Read more: Constructor Injection

Setter-based dependenc y injec tion: Setter-based DI is accomplished by the container calling setter methods on your beans after invoking a no-argument constructor or no-arg ument static factory method to instantiate your bean.
Read more: Setter Injection

Q : Which DI would you suggest Construc tor-based or setter-based DI?
A: Since you can mix both, Constructor- and Setter-based DI, it is a g ood rule of thumb to use constructor arg uments for mandatory dependencies and setters for optional dependencies. Note that the use of a @Required annotation on a setter can be used to make setters required dependencies.

Q : What are the benefits of IOC?
A: The main benefits of IOC or dependency injection are:
It minimizes the amount of code in your application.
It makes your application easy to test as it doesn't require any singletons or JNDI lookup mechanisms in your unit test cases.
Loose coupling is promoted with minimal effort and least intrusive mechanism.
IOC containers support eag er instantiation and lazy loading of services.

No comments:

Post a Comment