Labels

.NET Job Questions About Java Absract class Abstract class Abstract Class and Interface Aggregation ajax aop apache ofbiz Apache ofbiz tutrial Association authentication autocad basics batch Binary Tree bootstrap loader in java build Builder design pattern C++ Job Questions caching CallableStatement in java certifications Chain of responsibility Design pattern charts check parentheses in a string Classes classloader in java classloading concept code quality collage level java program Composition concurrency Concurrency Tutorial Converting InputStream to String Core Java core java concept core java interview questions Core Java Interview Questions Core Java Questions core java tutorial CyclicBarrier in Java data structures database Database Job Questions datetime in c# DB Db2 SQL Replication deserialization in java Design Patterns designpatterns Downloads dtd Eclipse ejb example/sample code exception handling in core java file handling injava File I/O vs Memory-Mapped Filter first program in spring flex Garbage Collection Generics concept in java grails groovy and grails Guice Heap hibernate Hibernate Interview Questions how-to IBM DB2 IBM DB2 Tutorial ide immutable Interceptor Interface interview Interview Questions for Advanced JAVA investment bank j2ee java JAVA Code Examples Java 7 java changes java class loading JAVA Classes and Objects Java Classloader concept Java classloading concept java cloning concept java collection Java collection interview questions Java Collections java concurrency Java CountDownLatch java definiton Java design pattern Java EE 5 Java EE 6 Java Exceptions Java file Java Garbage Collection Java generics Java Glossary java hot concept java immutable concept Java Interface Java interview Question java interview question 2012 java interview question answer Java Interview Questions Java Interview Questions and Answers java interview topic java investment bank Java Job Questions java multithreading java multithreading concept java new features Java Packages java proxy object java questions Java Serialization Java serialization concept java serialization interview question java session concept java string Java Swings Questions java synchronization java threading Java Threads Questions java tutorial java util; java collections; java questions java volatile java volatile interview question Java Wrapper Classes java.java1.5 java.lang.ClassCastException JavaNotes javascript JAX-WS jdbc JDBC JDBC Database connection jdk 1.5 features JDK 1.5 new features Concurrent HashMap JMS interview question JMS tutorial job JSESSIONID concept JSESSIONID interview Question JSF jsp JSP Interview Question JSP taglib JSTL with JSP Junit Junit Concept Junit interview question.Best Practices to write JUnit test cases in Java JVM Linux - Unix tutorial Marker Interfaces MD5 encryption and decryption messaging MNC software java interview question musix NCR java interview question Networking Job Questions news Object Serialization Objects ojdbc14.jar OOP Oracle Oracle SQL Query for two timestamp difference orm own JavaScript function call in Apache ofbiz Packages Palm Apps patterns pdf persistence Portal Portlet Spring Integration Prime number test in java programs Rails Reboot remote computers REST Ruby Sample application schema SCJP security Senior java developer interviews servlet3 servlets session tracking singleton design pattern Spring Spring 2.5 Framework spring ebook Spring framework concept spring MVC spring pdf Spring Security Spring Security interview questions SQL SQL performance SQL Query to create xml file Sql Query tuning ssis and ssrs StAX and XML string concept string immutable string in java strings struts Struts2 Struts2 integration synchronization works in java Technical Interview testing tips Tomcat top Tutorial Volatile in deep Volatile working concept web Web Developer Job Questions web services weblogic Weblogic Application Server websphere what is JSESSIONID xml XML parsing in java XML with Java xslt


Wednesday, 3 July 2013

Core Spring interview Questions and Answer


What is Spring?
Spring is an open source enterprise application development framework, which is primarily based on IOC (inversion of control) or DI (dependency injection) design pattern. It provides ready container to create and manage objects and also provides enterprise services to those objects. It provides ready components for different tiers of application e.g. web, middle/business and data access.
What is inversion of control (IOC) or Dependency Injection?
Inversion of control (IOC) or dependency injection (DI) is a design pattern used to give control to the assembler of classes. Generally, if a class wants to use another class, it instantiates desired class. But using this design pattern, the instantiation control is provided to the assembler. Assembler instantiates the required class and injects it in using class.
What are different types of DI?
- Constructor Injection
- Setter Injection
- Interface Injection
What are different modules in Spring?
Following six modules are there in Spring.
- Core: Springs IoC container and core services
- Web: Spring MVC and ability to integrate Spring with other web frameworks like Strusts, Tapestry, JSF etc.
- JEE: Java enterprise services like EJB support, JMX, JMS, JCA etc.
- ORM: Support to integrate with object relation mapping frameworks like hibernate, iBatis, Toplink etc.
- DAO: Helps in implementing Data Access Object design pattern. Provides support for Spring JDBC transaction management.
- AOP: Implementation of cross cutting concerns through Spring AOP and AspectJ.
What is new in Spring 2.5 as compared to 2.0?
Following changes are introduced in Spring 2.5.
- IOC container: New bean scopes, easier xml configuration, extensible xml authoring, annotations
- AOP: Easier xml configuration, support for @AspectJ aspects, support for bean name pointcut element, support for AspectJ load-time waving
- Middle tier: Declarative transactions in xml, full Websphere transaction management support, JPA, Asynchronous JMS, JDBC improvements
- Web tier: Changes in Spring MVC, Portlet framework, Tiles, JSF, JAX-WS support, etc.
What is IoC container of Spring?
Spring IoC container take care of instantiation of objects, injection of objects in each other and providing enterprise services (e.g. AOP, transaction management) to these objects.
What is BeanFactory interface?
BeanFactory provides configuration framework to Spring object creation and basic functionality around object management.
What is ApplicationContext?
ApplicationContext is built around Spring’s BeanFactory and it provides enterprise centric features e.g. AOP features, message resourcing, event propagating, application-layer-specific contexts to applications.
What is difference between BeanFactory and ApplicationContext?
BeanFactory is core configuration and basic functionality centric while ApplicationContext is enterprise-centric functionality support.
What is your preference BeanFactory or ApplicationContext? Why?
ApplicationContext. It provides all features provided by BeanFactory and enterprise centric more features, which may be required by application in future.
How to instantiate IoC container?
ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {“services.xml”, “daos.xml”});
How does a web application use Spring’s configuration xmls?
Spring container/configuration xmls can be integrated with web application through web.xml. Following entries in web.xml can integrate Spring container with web container.
 <context-param>
<description>
Context parameter to integrate Spring and Web containers
</description>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath: services.xml,
classpath: daos.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
How to integrate multiple bean configuration xmls?
Multiple bean configuration xmls are created to separate configurations according to layers so that it becomes easy to manage and maintain them. These configuration xmls can be imported in single xml to combine all of them.
<beans>
<import resource="services.xml"/>
<import resource="daos.xml"/>

<bean id="bean1" class="..."/>
<bean id="bean2" class="..."/>
</beans>
What are Lazily-instantiated beans?
In default behavior Spring instantiates singleton beans at the time of startup, which is called eagerly instantiation. This is good behavior as it exposes any problems in instantiation of beans at start up only. But sometimes this behavior is not expected hence by addition lazy-init=”true” to the bean definition the instantiation can be postponed to first request. Also following configuration will not allow any bean to get instantiated eagerly.
<beans default-lazy-init="true">
<!-- no beans will be pre-instantiated... -->
</beans>
What is autowiring?
By Autowiring, Spring injects dependencies without having to specify those explicitly. Spring inspects bean factory contents and establishes relationships amongst collaborating beans. To implement it, just add autowire property in xml configuration.
What are different modes of autowiring?
Autowiring has following five modes
- no: No autowiring.
- byName: Autowiring by property name, means bean matching property name is autowired.
- byType: Bean having type as that of property type is autowired.
- constructor: Similar to byType just that the property is in constructor.
- autodetect: Spring is allowed to select autowiring from byType and constructor.
What are different bean scopes available to configure?
Following scopes can be assigned to different beans.
- singleton: One bean instance per IoC container
- prototype: Any number of instances of bean
- request: Within HTTPRequest object scope
- session: As long as HttpSession is alive
- globalsession: Within life-cycle of global HttpSession. Applicable in portlet context usually.
What is default scope in Spring?
Singleton.
How can you control bean instantiation process?
Bean instantiation by Spring can be controlled using initialization call backs. There are two ways of doing it. First is having a initialization method (say init()) and specifying it in bean configuration as ‘init-method’ property. Second is implementing InitializingBean interface and implementing afterPropertiesSet() method in it.
How can you control bean destruction process?
There are two ways of doing it. First is add a destroy() method and specify it in bean configuration as ‘destroy-method’ property. Second is implement DisposableBean interface and implement destroy() method of it.
How do you implement inheritance in bean definition?
Bean definition inheritance can be implemented by specifying ‘parent’ property of the bean equal to its parent bean definition id. This bean class must have extended itself from the parent bean class.
What are advantages of Spring usage?
- Spring provides commonly required enterprise services without a need of expensive application server.
- It reduces coupling in code and improves maintainability.
- Readily available component improve productivity and subsequently reduce development cost.
- Pojo based programming enables reuse.
- Dependency Injection can be used to improve testability.
What all you have to do to start using Spring?
- Download Spring (and dependent Jars) from Spring’s site.
- Create application context xml to define beans and dependencies.
- Integrate this xml with web.xml
- Deploy and Run the application

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...