Saturday, September 6, 2014

Multithreading Interview Questions

Multithreading



Q1. What is Multitasking?
Ans. Executing several task simultaneously is called multitasking.

Q2. What is the difference between process-based and Thread-based Multitasking?
Ans.
Process-based multitasking:- Executing several task simultaneously where each task is a separate independent process such type of multitasking is called process based Multitasking. Example:-While typing a program in the editor we can listen MP3 audio songs. At the same time we download a file from the net.       all these task are executing simultaneously and each task is a separate independent program. hence it is process based multitasking. It is best suitable at operating system level.
Thread-based multitasking:- Executing several task simultaneously where each task is a separate independent part of the same program is called Thread-based multitasking. and every independent part is called a thread. This type of multitasking is best suitable at programmatic level.

Q3. What is Multithreading and explain its application areas? 
Ans. Executing several thread simultaneously where each thread is a separate independent part of the same program is called multithreading. Java language provides inbuilt support for multithreading by defining a reach library, classes and interfaces like Thread, ThreadGroup, Runnable etc. The main important application area of multithreading are video games implementation, animation development, multimedia graphics etc.

Q4.What is advantage of Multithreading?
Ans. The main advantage of multithreading is reduces response time and improves performance of the system.
Q5. When compared with C++ what is the advantage in java with respect to Multithreading?
Ans.Java language provides inbuilt support for multithreading by defining a reach library, classes and interfaces like Thread, ThreadGroup, Runnable etc. But in c++ there is no inbuilt support for multithreading.

Q6. In how many ways we can define a Thread? Among extending Thread and implementing Runnable which is recommended?
Ans. We can define a Thread in the following two ways:
1.      by extending Thread class or
2.      by implementing Runnable interface.
Among the two ways of defining a thread implementing Runnable mechanismis always recommended. In the first approach as our Thread class already extending Thread there is no chance of extending any other. Hence, we missing the key benefit of oops(inheritance properties).

Q7.  What is the difference between t.start() and t.run() method? 
Ans.       In the case of t.start() method, a new thread will be created which is responsible for the execution of run() method.
                But in the case of t.run() method no new thread will be created main thread executes run() method just like a normal method call.   
 

Q8.         Explain about Thread Scheduler?
Ans.    If multiple threads are waiting for getting the chance for executing then which thread will get chance first decided by Thread Scheduler. It is the part of JVM and its behavior is vendor dependent and we can’t expect exact output.Whenever the situation comes to multithreading the guarantee behavior is very- very low.

Q9. If we are not overriding run() method what will happened?
Ans.If we are not overriding run() method then Thread class run() method will executed which has empty implementation and hence we will not get any output.

Q10.Is overloading of run() method is possible?
Ans.Yes, we can overload run() method but Thread class start() method always invokes no-argument run() method only. The other run() method we have to call explicitly then only will be executed.

Q11.Is it possible to override start() method?
Ans. Yes it is possible. But not recommended.

Q12.If we are overriding start() method then what will happen?
Ans.  It we are overriding start() method then our own start() method will be executed just like a normal method call. In this case no new Thread will be created.

Q13. Explain life cycle of a Thread?
Ans.   Once we create a Thread object then the Thread is said to be in New/Born state once we call t.start() method now the Thread will be entered into ready/Runnable state that is Thread is ready to execute. If Thread Scheduler allocates CPU now the Thread will entered into the Running state and start execution of run() method. After completing run() method the Thread entered into Dead State.

Q14. What is the importance of Thread class start() method? 
Ans.    Start() method present in Thread class performing all low level joining formalities for the newly created thread like registering thread with Thread Scheduler etc and then start() method invoking run() method.As the start() method is doing all low level mandatory activities, Programmer has to concentrate only on run() method to define the job. Hence, start() method is a big assistant to the programmer.Without executing Thread class start() method there is no chance of starting a new Thread.

Q15. After starting a Thread if we trying to restart the same thread once again what will happen?
Ans.  After starting a Thread restarting of the same Thread once again is not allowed violation leads to Runtime Exception saying IllegalThreadStateException.
 

Q16. Explain Thread class constructors?
Ans.  There are eight constructors are available in Thread class:
1. Thread t=new Thread();          
 
2. Thread t=new Thread(Runnable r);    
 
3. Thread t=new Thread(String name);  
 
4.Thread t=new Thread(Runnable r, String name);          
 
5.Thread t=new Thread(ThreadGroup g, String name);  
 
6.Thread t=new Thread(ThreadGroup g, Runnable r);    
 
7.Thread t=new Thread(ThreadGroup g, Runnable r, String name);         
 
8.Thread t=new Thread(ThreadGroup g, Runnable r, String name, long stacksize);
Q17.  How to get and set name of a Thread?
Ans.   For every Thread in java there is a name. To set and get the name of a Thread we can use the following methods. All methods are final.
1.Public final void setName(String name); - To set the name of a Thread
2.Public final String getName(); - To get the name of a Thread.

Q18. What is the range of Thread priority in java?
Ans.   The valid range of a Thread priority is 1-10. (1 is least priority and 10 is highest priority)
.
Q19.  Who uses Thread priority?
Ans.   Thread Scheduler uses priorities while allocating CPU. The Thread which is having highest priority will get chance first for execution.

Q20.  What is the default priority of the Thread?
Ans.   The default priority only for the main thread is 5 but for all remaining threads default priority will be inheriting from parent to child. Whatever priority parent thread has the same will be inherited to the child thread.
Q21. Once we created a new Thread what about its priority?
Ans.  Whatever priority parent thread has the same will be inherited to the new child thread.

Q22.  How to get and set priority of a Thread?
Ans.    To get and set priority of a Thread, Thread class defines the following two methods:;
1.         Public final int getPriority();                                                                                                                                   
2.        Public final void setPriority(int priority);

Q23.   If we are trying to set priority of a Thread as 100 what will happen?
Ans.    If we are trying to set priority of a Thread as 100 then we will not get any compile time error but at the runtime we will get Runtime exception IllegalArgumentException. Because the valid range of the Thread priority is (1-10) only.

a Thread from executin by using the following methods:
1.     Yield()
2.     Join()
3.     Sleep()
Q27. What is yield() method? Explain its purpose?
Ans.   yield() method causes the current executing thread to pause execution and give the chance for waiting thread are same priority. If there is no waiting thread or all the remaining waiting thread have low priority then the same thread will get chance once again for execution. The Thread which is yielded when it will get chance once again for execution depends upon mercy of Thread scheduler.Public static native void yield();
                             
 
Q28.What is purpose of join() method?
Ans.  If a Thread wants to wait until some other Thread completion then we should go for join() method.
 
         Example: if a Thread t1 execute t2.join() ; then t1 will entered into waiting state until t2 Thread completion.
Q29. Is join() method is overloaded?
Ans.       Yes join() method is overloaded method.
                Public final void join() throws InterruptedException
                                By using this method thread will wait up to another thread completion .
                Public final void join(long ms) throws InterruptedException
By using this method thread will wail upto sometime what we are passing as a argument in millisecond 
Public final void join(long ms, int ns)throws InterruptedException
By using this method thread will wait up to sometime what we are passing as a argument in millisecond and nanosecond.

Q30 What is the purpose of sleep() method?
Ans.  If a Thread don’t want to perform any operation for a particular amount of time then we should go for sleep() method.Whenever we are using sleep() method compulsory we should handle InterruptedException either by using try-catch or by using throws keyword otherwise we will get compile time error.


Q31. What is synchronized keyword? Explain its advantages and disadvantages.
Ans.       Synchronized keyword is applicable for method and blocks only. We can’t use for variables and classes.
                If a method declared as a synchronized then at a time only one Thread is allow to execute that method on the given object.
                The main advantages of synchronized keyword are, we can prevent data inconsistency problems and we can provide Threadsafty.
                But the main limitation of synchronized keyword is it increases waiting time of Threads and effect performance of the system. Hence if there is no specific requirement it is not recommended to use synchronized keyword.

Q32.Where we can use synchronized keyword?
Ans. Synchronization concept is applicable whenever multiple Threads are operating on the same object simultaneously. But whenever multiple Threads are operating on different objects then there is no impact of synchronization.

Q33. What is object lock? Explain when it is required?
Ans.   Every object in java has a unique lock whenever we are using synchronization concept then only lock concept will coming to the picture.
If a Thread wants to execute a synchronized method first it has to get the lock of the object. Once a Thread got the lock then it is allow to execute any synchronized method on that object. After completing synchronized method execution Thread releases the lock automatically.While a Thread executing synchronized method on the given object the remaining Threads are not allow to execute any synchronized method on that object simultaneously. But remaining Threads are allow to execute any non-synchronized method simultaneously. (Lock concept is implemented based on object but not based on method.)

Q34.What is the class level lock? Explain its purpose.
Ans. Every class in java has a unique lock if a Thread wants to execute static synchronized method that Thread has to get class level lock once a Thread got class level lock then only it is allow to execute static synchronized method.              
 
While a Thread executing any static synchronized method then remaining Threads are not allow to execute any static synchronized method of the same class simultaneously. But the remaining Threads are allow to execute the following method simultaneously:
1.     Any static non-synchronized method.
2.     Synchronized instance methods
3.     Non-synchronized instance method.
                There is no relationship between object lock and class level lock, both are independent.
                               
 
Q35. While a thread executing any synchronized method on the given object is it possible to execute remaining synchronized method of the same object simultaneously by any other thread?
Ans.       No, it is no possible.

Q36. What is the difference between synchronized method and static synchronized method?
Ans.   If a Thread wants to execute a
 synchronized method first it has to get the lock of the object. Once a Thread got the lock then it is allow to execute any synchronized method on that object.If a Thread wants to execute static synchronized method that Thread has to get class level lock once a Thread got class level lock then only it is allow to execute static synchronized method.

Q37. What is the advantage of synchronized block over synchronized method?
Ans.   If very few lines of the code required synchronization then declaring entire method as the synchronized is not recommended. We have to declare those few lines of the code inside synchronized block. This approach reduces waiting time of the Thread and improves performance of the system.

Q38.  What is synchronized statement?
Ans.   The Statement which is inside the synchronized area (synchronized method or synchronized block) is called synchronized statement.

Q39.  How we can declare synchronized block to get class level lock?
Ans.   To get the class level lock we can declare synchronized block as follows:
           synchronized(Display.class)
             {
              }

Q40.   How two thread will communicate with each other?
Ans.    Two Threads will communicate with each other by using wait(), notify(), notifyAll() methods.
Q41.wait(), notify(), notifyAll() method can available in which class?
Ans. These methods are defined in Object class.

Q42.Why wait(), notify(), notifyAll() method defines in object class instead of Thread class?
Ans. These methods are defined in Object class but not in Thread because Threads are calling this method on the shared object.

Q43.If a waiting thread got notification then it will entered into which state?
Ans. It will entered into another waiting state to get lock.

Q44.In which method threads can release the lock?
Ans. Once a Thread calls wait() method it immediately releases the lock of that object and then entered into waiting state similarly after calling notify() method Thread releases the lock but may not immediately. Except these three methods( wait(), notify(), notifyAll() ) method Thread never releases the lock anywhere else.
 
Q45. Explain wait(), notify(), notifyAll() method uses.
Ans.  Two Threads will communicate with each other by using wait(), notify() or notifyAll() methods.
         These methods are defined in Object class but not in Thread because Threads are calling this method.

Q46. What is the difference between notify() and notifyAll()?
Ans.  To give notification to the single waiting Thread. We use notify() method and to give
notification to all waiting thread we use notifyAll() method.
Q47. Once a Thread got the notification then which waiting thread will get chance?
Ans.   It is depends on the Thread Scheduler.

Q48.   How a thread can interrupt another thread?
Ans.  A Thread can interrupt another Thread by using interrupt() method.
Q49. What is DeadLock? Is it possible to resolve DeadLock situation?
Ans.   If two Threads are waiting for each other forever such type of situation is called DeadLock.
          For the DeadLock, there are no resolution techniques but prevention techniques are available.  
                            
Q50. Which keyword causes DeadLock situation?
Ans.  Synchronized keyword is the thing to causes of DeadLock. If we are not using properly synchronized keyword the program will entered into DeadLock situation. 


Q51.  How we can stop a thread explacitly?
Ans.  Thread class defines stop() method by using this method we can stop a Thread. But it is deprecated. And hence not recommended to use.

Q52.   Explain about suspend() and resume() method?
Ans.   A Thread can suspend another Thread by using suspend() method.
A Thread can resume a suspended Thread by using resume() method.

Q53.What is Starvation()? And Explain the difference between Deadlock and Starvation?
Ans. A long waiting Thread is said to be in starvation (because of least priority) but after certain time defiantly it will get the chance for execution. But in the case of Deadlock two Threads will wait for each other forever. It will never get the chance for execution.
Q54. What is race condition?
Ans.  Multiple Threads are accessing simultaneously and causing data inconsistency problem is called race condition, we can resolve this by using synchronized keyword.

Q55. What is Daemon Thread? And give an example?
Ans.  The Threads which are running in the background are called Daemon Thread.
                Example: Garbage collector.
Q56. What is the purpose of a Daemon Thread?
Ans.  The main purpose of Daemon Threads is to provide support for non-daemon Threads.

Q57.  How we can check Daemon nature of a Thread?
Ans.   We can check Daemon nature of a Thread by using isDaemon() method.

Q58.  Is it possible to change a Daemon nature of a Thread?
Ans.  Yes, we can change Daemon nature of a Thread by using setDaemon() method.

Q59. Is main thread is Daemon or non-daemon?
Ans.  By default main thread is always non-daemon nature.

Q60. Once we created a new thread is it daemon or non-daemon.
Ans.   Once we created a new Thread, The Daemon nature will be inheriting from parent to child. If the parent is Daemon the child is also Daemon and if the parent is non-daemon then child is also non-daemon.

Q61. After starting a thread is it possible to change Daemon nature?
Ans.  We can change the Daemon nature before starting the Thread only. Once Thread started we are not allow to change Daemon nature otherwise we will get RuntimeException sying IllegalThreadStateException.

Q62. When the Daemon thread will be terminated?
Ans.  Once last non-daemon Thread terminates automatically every Daemon Thread will be terminated.

Q63. What is green Thread?
Ans.   A green thread refers to a mode of operation for the Java Virtual Machine (JVM) in which all code is executed in a single operating system thread. If the Java program has any concurrent threads, the JVM manages multi-threading internally rather than using other operating system threads.
There is a significant processing overhead for the JVM to keep track of thread states and swap between them, so green thread mode has been deprecated and removed from more recent Java implementations. 

Q64.Explain about Thread group?
Ans. Every Java thread is a member of a thread group. Thread groups provide a mechanism for collecting multiple threads into a single object and manipulating those threads all at once, rather than individually. For example, you can start or suspend all the threads within a group with a single method call. Java thread groups are implemented by the ThreadGroup api class in the java.lang package.

Q65.What is the Thread Local?
Ans.  It's a way for each thread in multi-threaded code to keep its own copy of an instance variable. Generally, instance variable are shared between all threads that use an object; ThreadLocal  is a way for each thread to keep its own copy of such a variable. The purpose might be that each thread keeps different data in that variable, or that the developer wants to avoid the overhead of synchronizing access to it. 
Q66. In your previous project where you used multithreading concept?



Friday, August 22, 2014

How Prepare For An Interview


Points To Remember Before Going To Interview


Point 1 : You need to prepare all the skills mentioned in your resume.
Point 2 : Come up with the priority for all the skills that you need to prepare. If you are not sure, ask us.
Point 3 : Make a time plan based on the skills priority.
Point 4 : Go thru  Mock Interview questions so that you will get some idea what types of questions will be asked in the interview.
Point 5 : Concentrate on – What new things you learnt on that day instead of how much you learnt. Please complete the daily task which assigns to you.
Point 6 : Don’t buy the books and do daily task and complete the work as per assigned to you. If you do like that, then it will take few months for you to ready for the interview.
Point 7 : While you are preparing, keep in mind, that you need to prepare in Interview point of view only.
Point 8 : Concentrate more on basic concepts. Sometimes you will miss answering the basic questions.
Point 9 : When coming to steps, Concentrate on the main steps needed for a product or project.
Point 10 : Ask your friends to do mock interviews for you, so that you will not get tensed in the client interview.
Point 11 : Cover all the responsibilities that you mentioned in your resume. If the clients ask some points in your responsibilities then you need to tell in and out of it.
Point 12 : Take last 2 to 3 projects in your resume, and study those projects well and come up with some design/screen flow for your projects.
I mean you need to IN and OUT of your projects. If the client asks questions like tell about ur project, what is ur role in the project. Then you need to tell like – the project is about so and so. This is the flow for the project. I handled this module. Then you need to cover ur responsibilities whatever you mentioned in the resume.
Point 13 : Make sure that you are updating your skills in their newer versions.
Once you answer these type of questions, the client will get good impression on you and finally he will get the feeling that you are updating your skills.
Point 14 : Never lose confidence on you . Never get tensed. Never lose patience.
Update new skills/Refresh subject day by day without losing PATIENCE and without getting TENSED, finally you will be CONFIDENT on you that you can easily handle the interview

Thursday, August 14, 2014

Spring JDBC Module Questions


Spring-Jdbc

Advantages of spring jdbc?
           
spring internally uses connection parameters
spring opens the connection and closing the connection
spring creates statement logic by using jdbcTemplate class
spring handles the transaction
spring exception handling

DriverManagerDataSource?

The simple implementation of standard jdbc data source interface. Configuring a plain old jdbc driver via bean properties and returns new connection for every get Connection call.

this is not a actual connection pool.it does not contains connection pools. it creates a new connection for every call

it used in outside J2EE container or standard alone apps
in j2ee container, is recommended to use a jndi data source provided by the container such as “JndiObjectFactoryBean”
JndiObjectFactoryBean “it has the actual  connection pools. in real time apps we are using JndiObjectFactoryBean with data source

JdbcTemplate?

This is the central class in the jdbc core pkg.it simplifies the use of jdbc code
This class internally having the statement logic
This class excutes sql queries ,updates,initiating iteration over results and catching jdbc exceptions and translating  them to generic

QueryForMethods?

We are using these methods whenever we perform aggregate functions results and must be one row and one column results
We have  many queryFormethods
                        1. QueryForInt()
            2. queryForString()
            3. queryForObject()
            4. queryForMap()
            5. queryForList()
            6/ queryForFloat() ----etc
In real time most of the cases we use 1
These all methods are used for select operation only but not non select operation

What are the concepts we use curd operations in spring Jdbc?

1.insert/update/delete=====èjdbcTemplate.execute();

2.select with aggregate functions like count(*),max,min ---etc=====èqueryForInt/Object/Map

3.select with tables ex. select sno,sname from student=èRowMapper


 What is RowMaper?

RowMapper is an interface used to map a row with an object. while working with rowmapper interface
spring provides,statement,connection,resultset creation and closeting is done by spring
exception Handling is spring
looping and creating the list is done by spring
the implementation of this interface is available in “ColumnRowMapper”

 What is ResultSetExtracter?

It is interface
It provides similar to RowMapper interface.but it doesn’t create list object
while working with this we need to override the extractData () method
The implementation class is”RowMapperResultSetExtractor”


What is RowCallbackHandler?

It is an interface.It provides the features like RowMapper interface but it doesn’t create list object
while working with this interface we need to override the ProcessRow () method

 What is PreparedStatementCreator?

It is an interface.It is used to create preparedStatement using connection
The implementation class of PreparedStatementCreator is”SimplePreparedStatementCreator”

 What is PreparedStatementSetter?

It is an interface. Used to set the values to prepared Statement
The implementation class of this interface is “ArgPreparedStatement”     

PreparedStatementCallback?

This is an interface. The implementation is used to execute the prepared Statement

CallableStatementCreaterImpl ?

àIt is a class .it creates callable Statement   

CallableStatementCallback?

It executes the callable Statement

What is the use of batch Update?

àWhenever we want to execute multiple queries it take some time to execute so it will decrease the performance of an application.
àIf we use batch Update then to decrease the execution time of an application so it will increase the performance of an application

 ContextLoaderListener?

àIt is used to read the spring configuration file
àIt will identify the config file using”contextConfigLocation” context parameter

15. What is DAO?

The java class that contains only persistent logic and separates that logic from other logics of application is called DAO

15. DataSourceTransactionManager?
It contains the transaction logic like con.setAutoCoomit(false),con.commit()……etc to apply the transaction it excepts the data Source so we are injecting data Source using this it will get con to apply transaction

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.

What is DataAccessException?
DataAccessException is a RuntimeException. This is an Unchecked Exception. The user is not forced to handle these kinds of exceptions.
 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>
  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>
 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.

  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>


 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.

 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.

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.

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);

What is JDBC abstraction and DAO module?
·         Using this module we can keep up the database code clean and simple, and prevent problems that result from a failure to close database resources. A new layer of meaningful exceptions on top of the error messages given by several database servers is bought in this module. In addition, this module uses Spring’s AOP module to provide transaction management services for objects in a Spring application.

How can u integrate spring and hibernate with and without  hibernate configuration file?
·         Without configuration file we can integrate spring and hibernate for this we need to write HiberanteUtil classes’ .from this classes we need to get the connection from database
·         With configuration file we need to configure the LocalSessionFactory bean in spring configuration file using configLocation property
·         We can integrate spring and hibernate with and without hibernate configuration file

How to integrate spring and struts?
·         We need to configure the spring configuration file in struts-config.xml with ContextLoaderPlugIn class with “contextConfiLocation”property
·         <plug-in className=”--.ContextLoaderPlugIn”>
·         <set-property property=”contextConfigLocation”value=”/WEB-INF/action-servlet.xml”/>
·         </plug-in>
What is the default spring configuration file?
·         In struts if are not giving any struts config file name in the web.xml using config init parameter then it takes struts-default.xml
·         In spring, if are not giving any spring configuration file name in the struts-config.xml using contextConfigLocation property. if we are not configuring property  it takes the by default “ActionServletName-servlet.xml”

How to delegate(forward) a struts request to spring?
·         To forward a struts request to spring we need to configure the “DelegateActionProxy” class in struts-config.xml
·         Struts-config.xml
·         <action path=”/StudentAction” type=”--. DelegateActionProxy”/>
·         Action-servlet.xml
·         <bean name=”/StudentAction” type=”--.StudentAction”/>
·         Here <action/> tag path and <bean/> name both must be same            

What is HibernateTransactionManager?
·         It is a simple java class it contains the transaction logic like session.beginTransaction(),tx.commit(),tx.rollback()……….etc

 How would you integrate Spring and Hibernate using HibernateDaoSupport?
·         This can be done through Spring’s SessionFactory called LocalSessionFactory. The steps in integration process are:

a.) Configure the Hibernate SessionFactory 
b.) Extend your DAO Implementation from HibernateDaoSupport 
c.) Wire in Transaction Support with AOP

What are object/relational mapping integration module?
Spring also supports for using of an object/relational mapping (ORM) tool over straight JDBC by providing the ORM module. Spring provide support to tie into several popular ORM frameworks, including Hibernate, JDO, and iBATIS SQL Maps. Spring’s transaction management supports each of these ORM frameworks as well as JDBC.

When to use programmatic and declarative transaction management ?
   Programmatic transaction management is usually a good idea only if you have a small number of transactional operations. 
On the other hand, if your application has numerous transactional operations, declarative transaction management is usually worthwhile. It keeps transaction management out of business logic, and is not difficult to configure.
Explain about the Spring DAO support ? 
The Data Access Object (DAO) support in Spring is aimed at making it easy to work with data access technologies like JDBC, Hibernate or JDO in a consistent way. This allows one to switch between the persistence technologies fairly easily and it also allows one to code without worrying about catching exceptions that are specific to each technology.

What are the exceptions thrown by the Spring DAO classes ? 
Spring DAO classes throw exceptions which are subclasses of DataAccessException(org.springframework.dao.DataAccessException).Spring provides a convenient translation from technology-specific exceptions like SQLException to its own exception class hierarchy with the DataAccessException as the root exception. These exceptions wrap the original exception.

What is SQLExceptionTranslator ? 
SQLExceptionTranslator, is an interface to be implemented by classes that can translate between SQLExceptions and Spring's own data-access-strategy-agnostic org.springframework.dao.DataAccessException.


What is Spring's JdbcTemplate ?
Spring's JdbcTemplate is central class to interact with a database through JDBC. JdbcTemplate provides many convenience methods for doing things such as converting database data into primitives or objects, executing prepared and callable statements, and providing custom database error handling.
JdbcTemplate template = new JdbcTemplate(myDataSource);


What is PreparedStatementCreator ?
   PreparedStatementCreator:
  • Is one of the most common used interfaces for writing data to database.
  • Has one method – createPreparedStatement(Connection)
  • Responsible for creating a PreparedStatement.
  • Does not need to handle SQLExceptions.
What are ORM’s Spring supports ? 
  
 Spring supports the following ORM’s :
  • Hibernate
  • iBatis
  • JPA (Java Persistence API)
  • TopLink
  • JDO (Java Data Objects)
  • OJB
What are the ways to access Hibernate using Spring ?
   
There are two approaches to Spring’s Hibernate integration:
  • Inversion of Control with a HibernateTemplate and Callback
  • Extending HibernateDaoSupport and Applying an AOP Interceptor
24. How to integrate Spring and Hibernate using HibernateDaoSupport?
  
 Spring and Hibernate can integrate using Spring’s SessionFactory called LocalSessionFactory. The integration process is of 3 steps.
  • Configure the Hibernate SessionFactory
  • Extend your DAO Implementation from HibernateDaoSupport
  • Wire in Transaction Support with AOP
What are the various transaction manager implementations in Spring ?
1. DataSourceTransactionManager : PlatformTransactionManager implementation for single JDBC data sources. 

2. HibernateTransactionManager: PlatformTransactionManager implementation for single Hibernate session factories. 

3. JdoTransactionManager : PlatformTransactionManager implementation for single JDO persistence manager factories. 

4. JtaTransactionManager : PlatformTransactionManager implementation for JTA, i.e. J2EE container transactions.