• +91 9971497814
  • info@interviewmaterial.com

Spring Interview Questions Answers

Question 1 : What are the different IOC containers available?

Answer 1 : Spring is an IOC container. Other IOC containers are HiveMind, Avalon, PicoContainer.

Question 2 : What are the advantages of spring framework?

Answer 2 : Spring has layed 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 continous integration and testability. Dependency Injection and Inversion of Control Simplifies JDBC (Read the first question.) Open source and no vendor lock-in.

Question 3 : Can you name a tool which could provide the initial ant files and directory structure for a new spring project.

Answer 3 : Appfuse or equinox.

Question 4 : How does Spring supports DAO in hibernate?

Answer 4 : Spring’s HibernateDaoSupport class is a convenient super class for Hibernate DAOs. It has handy methods you can call to get a Hibernate Session, or a SessionFactory. The most convenient method is getHibernateTemplate(), which returns a HibernateTemplate. This template wraps Hibernate checked exceptions with runtime exceptions, allowing your DAO interfaces to be Hibernate exception-free. Example:  public class UserDAOHibernate extends HibernateDaoSupport {   public User getUser(Long id) { return (User) getHibernateTemplate().get(User.class, id); } public void saveUser(User user) { getHibernateTemplate().saveOrUpdate(user); if (log.isDebugEnabled()) { log.debug(“userId set to: “ + user.getID()); } } public void removeUser(Long id) { Object user = getHibernateTemplate().load(User.class, id); getHibernateTemplate().delete(user); }   }

Question 5 : How is a typical spring implementation look like?

Answer 5 : For a typical Spring Application we need the following files    1. An interface that defines the functions. 2. An Implementation that contains properties, its setter and getter methods, functions etc., 3. A XML file called Spring configuration file. 4. Client program that uses the function.

Question 6 :  How do you define hibernate mapping file in spring?

Answer 6 : Add the hibernate mapping file entry in mapping resource inside Spring’s applicationContext.xml file in the web/WEB-INF directory.    <property name="mappingResources">     <list>         <value>org/appfuse/model/User.hbm.xml</value>     </list> </property>  

Question 7 : How do you configure spring in a web application?

Answer 7 : It is very easy to configure any J2EE-based web application to use Spring. At the very least, you can simply add Spring’s ContextLoaderListener to your web.xml file:   <listener>     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>

Question 8 : What are the key benifits of Hibernate?

Answer 8 : These are the key benifits of Hibernate: Transparent persistence based on POJOs without byte code processing  Powerful object-oriented hibernate query language Descriptive O/R Mapping through mapping file. Automatic primary key generation  Hibernate cache : Session Level, Query and Second level cache. Performance: Lazy initialization, Outer join fetching, Batch fetching

Spring Contributors

krishan

Share your email for latest updates

Name:
Email:

Our partners