Explanation for Important Interview Questions

Answer-

Spring does following things:

  1. Opens connection

  2. Prepare and execute statement.

  3. Iterate the results

  4. Process exception if any

  5. Handle transaction

  6. Close connection


Answer-

Following template is provided.

  • JdbcTemplate

  • NamedParameterJdbcTemplate

  • SimpleJdbcTemplate


Answer-

Write @Repository at class level. Entity manager can be configured by @PersistenceContext at property level.


Answer-

For using servlet container configured JNDI DataSource, we need to configure it in the spring bean configuration file and then inject it to spring beans as dependencies. Then we can use it with JdbcTemplate to perform database operations.

Sample configuration would be:


Answer-

Spring DAO support is provided to work with data access technologies like JDBC, Hibernate in a consistent and easy way. For example we have JdbcDaoSupport, HibernateDaoSupport, JdoDaoSupport and JpaDaoSupport for respective technologies.

Spring DAO also provides consistency in exception hierarchy and we don’t need to catch specific exceptions.


Answer-

Spring Framework is using a lot of design patterns, some of the common ones are:

  1. Singleton Pattern : Creating beans with default scope.

  2. Factory Pattern : Bean Factory classes

  3. Prototype Pattern : Bean scopes

  4. Adapter Pattern : Spring Web and Spring MVC

  5. Proxy Pattern : Spring Aspect Oriented Programming support

  6. Template Method Pattern : JdbcTemplate, HibernateTemplate etc

  7. Front Controller : Spring MVC DispatcherServlet

  8. Data Access Object : Spring DAO support

  9. Dependency Injection and Aspect Oriented Programming