JavaBeat FAQs
FAVORITES
Download a movie FAQ
JAVABEAT
Home
Articles
Tips
QnA
Forums
FAQs Topics Books Topic
Java Java Books
Struts Struts Books
Spring Spring Books
Hibernate Hibernate Books
JBoss Seam Seam Books
J2EE J2EE Books
EJB EJB Books
JSF JSF Books
Servlets Servlets Books
JDBC JDBC Books
RMI RMI Books
JMS JMS Books
JNI JNI Books
Design Patterns Patterns Books
Exception Exception Books
Apache Ant Ant Books
Groovy
Cobertura
Quartz

Spring Framework Interview Questions

Spring Framework is a lightweight container, with wrappers that make it easy to use many different services and frameworks. Lightweight containers accept any JavaBean, instead of specific types of components."Spring is more than just a 'lightweight container,'" says Justin Gehtland. "It allows Java developers who are building J2EE apps to get to the heart of their real domain problems and stop spending so much time on the minutiae of providing services to their domain." Gehtland and Bruce Tate are coauthors of Spring: A Developer's Notebook, a no-nonsense book that will get you up to speed quickly on the new Spring open source framework. Spring: A Developer's Notebook includes examples and practical applications that demonstrate exactly how to use Spring, in ten chapters of code-intensive labs.

Spring Articles

Introduction to Spring Web Framework

Introduction to Spring's Aspect Oriented Programming(AOP)

Spring Web Flow - Introduction

Introduction to Spring IDE 2.0

Introduction to Spring MVC Web Framework - Web Tier

 
Spring FAQs - 1 | Spring FAQs - 2 | Spring FAQs - 3 | Spring FAQs - 4 | Spring FAQs - 5
  1. What kind of exceptions those spring DAO classes throw?

The spring’s DAO class does not throw any technology related exceptions such as SQLException. They throw exceptions which are subclasses of DataAccessException.


  1. What is DataAccessException?

DataAccessException is a RuntimeException. This is an Unchecked Exception. The user is not forced to handle these kinds of exceptions.


  1. How can you configure a bean to get DataSource from JNDI?

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
     <property name="jndiName">       <value>java:comp/env/jdbc/myDatasource</value>
  </property>
</bean>


  1. How can you create a DataSource connection pool?

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
       <property name="driver">
               <value>${db.driver}</value>
       </property>
       <property name="url">
              <value>${db.url}</value>
       </property>
       <property name="username">
             <value>${db.username}</value>
       </property>
       <property name="password">
            <value>${db.password}</value>
       </property>
</bean>


  1. How JDBC can be used more efficiently in spring framework?

JDBC can be used more efficiently with the help of a template class provided by spring framework called as JdbcTemplate.


  1. How JdbcTemplate can be used?

With use of Spring JDBC framework the burden of resource management and error handling is reduced a lot. So it leaves developers to write the statements and queries to get the data to and from the database.


JdbcTemplate template = new JdbcTemplate(myDataSource);


A simple DAO class looks like this.


public class StudentDaoJdbc implements StudentDao {
          private JdbcTemplate jdbcTemplate;

     public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
          this.jdbcTemplate = jdbcTemplate;
     }
     more..
}


The configuration is shown below.


<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
       <property name="dataSource">
       <ref bean="dataSource"/>
   </property>
</bean>
<bean id="studentDao" class="StudentDaoJdbc">
       <property name="jdbcTemplate">
        <ref bean="jdbcTemplate"/>
   </property>
</bean>
<bean id="courseDao" class="CourseDaoJdbc">
        <property name="jdbcTemplate">
       <ref bean="jdbcTemplate"/>
   </property>
</bean>


  1. How do you write data to backend in spring using JdbcTemplate?

The JdbcTemplate uses several of these callbacks when writing data to the database. The usefulness you will find in each of these interfaces will vary. There are two simple interfaces. One is PreparedStatementCreator and the other interface is BatchPreparedStatementSetter.


  1. Explain about PreparedStatementCreator?

PreparedStatementCreator is one of the most common used interfaces for writing data to database. The interface has one method createPreparedStatement().


PreparedStatement createPreparedStatement(Connection conn)
throws SQLException;


When this interface is implemented, we should create and return a PreparedStatement from the Connection argument, and the exception handling is automatically taken care off. When this interface is implemented, another interface SqlProvider is also implemented which has a method called getSql() which is used to provide sql strings to JdbcTemplate.


  1. Explain about BatchPreparedStatementSetter?

If the user what to update more than one row at a shot then he can go for BatchPreparedStatementSetter. This interface provides two methods


setValues(PreparedStatement ps, int i) throws SQLException;

int getBatchSize();


The getBatchSize() tells the JdbcTemplate class how many statements to create. And this also determines how many times setValues() will be called.


  1. Explain about RowCallbackHandler and why it is used?

In order to navigate through the records we generally go for ResultSet. But spring provides an interface that handles this entire burden and leaves the user to decide what to do with each row. The interface provided by spring is RowCallbackHandler. There is a method processRow() which needs to be implemented so that it is applicable for each and everyrow.


void processRow(java.sql.ResultSet rs);



Related Articles
JAX-WS Web Services in NetBeans 6.1
JPA in NetBeans 6.1
EJB 3.0 and WebServices
Types of Managed Bean scopes in Spring Framework
OpenCms 7 Development
Liferay Portal Enterprise Intranets
ZK Developer’s Guide : Online Media Library
The BIRT Environment and Your First Report
AJAX - The Complete Reference
The Java 6.0 Compiler API
more articles
java6 ejb3 jsf hibernate eclipse ajax groovy spring seam java struts webservice j2me guice java5 jca tapestry soa linux ria books

Favorites
Buy movies
Access Control
Busby seo challenge contest
Sohbet
Chat
Webmaster Hosting Forum
Java Jobs
MyVideoLib
India News
Internet Advances
Sohbet
chat
Latest QnA
SCJD Tips
When we start a thread by applying start() method on it ,how does it knows that to execute run()method?
About Wrapper class in Java
How to configure weblogic 7.0 in MyEclipse?
Static Block and Static Initializer in Java

JavaBeat Website (2004-2008), India
javabeat | about us | planetoss
Copyright (2004 - 2008), JavaBeat