• +91 9723535972
  • info@interviewmaterial.com

Spring Interview Questions and Answers

Spring Interview Questions and Answers

Question - 81 : - What is Spring AOP?

Answer - 81 : -

  • Spring AOP (Aspect Oriented Programming) is similar to OOPs (Object Oriented Programming) as it also provides modularity.
  • In AOP key unit is aspects or concerns which are nothing but stand-alone modules in the application. Some aspects have centralized code but other aspects may be scattered or tangled code like in the case of logging or transactions. These scattered aspects are called cross-cutting concern.
  • A cross-cutting concern such as transaction management, authentication, logging, security etc is a concern that could affect the whole application and should be centralized in one location in code as much as possible for security and modularity purposes.
  • AOP provides platform to dynamically add these cross-cutting concerns before, after or around the actual logic by using simple pluggable configurations.
  • This results in easy maintainenance of code. Concerns can be added or removed simply by modifying configuration files and therefore without the need for recompiling complete sourcecode.
  • There are 2 types of implementing Spring AOP:
  1. Using XML configuration files
  2. Using AspectJ annotation style

Question - 82 : - What is an advice? Explain its types in spring.

Answer - 82 : -

An advice is the implementation of cross-cutting concerns can be applied to other modules of the spring application. Advices are of mainly 5 types:

Before:
  • This advice executes before a join point, but it does not have the ability to prevent execution flow from proceeding to the join point (unless it throws an exception).
  • To use this, use @Before annotation.
AfterReturning:
  • This advice is to be executed after a join point completes normally i.e if a method returns without throwing an exception.
  • To use this, use @AfterReturning annotation.
AfterThrowing:
  • This advice is to be executed if a method exits by throwing an exception.
  • To use this, use @AfterThrowing annotation.
After:
  • This advice is to be executed regardless of the means by which a join point exits (normal return or exception encounter).
  • To use this, use @After annotation.
Around:
  • This is the most powerful advice surrounds a join point such as a method invocation.
  • To use this, use @Around annotation.

Question - 83 : - What is Spring AOP Proxy pattern?

Answer - 83 : -

  • A proxy pattern is a well-used design pattern where a proxy is an object that looks like another object but adds special functionality to it behind the scenes.
  • Spring AOP follows proxy-based pattern and this is created by the AOP framework to implement the aspect contracts in runtime.
  • The standard JDK dynamic proxies are default AOP proxies that enables any interface(s) to be proxied. Spring AOP can also use CGLIB proxies that are required to proxy classes, rather than interfaces. In case a business object does not implement an interface, then CGLIB proxies are used by default.

Question - 84 : - What are some of the classes for Spring JDBC API?

Answer - 84 : -

  • Following are the classes
  1. JdbcTemplate
  2. SimpleJdbcTemplate
  3. NamedParameterJdbcTemplate
  4. SimpleJdbcInsert
  5. SimpleJdbcCall
  • The most commonly used one is JdbcTemplate. This internally uses the JDBC API and has the advantage that we don’t need to create connection, statement, start transaction, commit transaction, and close connection to execute different queries. All these are handled by JdbcTemplate itself. The developer can focus on executing the query directly.

Question - 85 : - What is Hibernate ORM Framework?

Answer - 85 : -

  • Object-relational mapping (ORM) is the phenomenon of mapping application domain model objects to the relational database tables and vice versa.
  • Hibernate is the most commonly used java based ORM framework.

Question - 86 : - What are the two ways of accessing Hibernate by using Spring.

Answer - 86 : -

  • Inversion of Control approach by using Hibernate Template and Callback.
  • Extending HibernateDAOSupport and Applying an AOP Interceptor node.

Question - 87 : - What is Hibernate Validator Framework?

Answer - 87 : -

  • Data validation is a crucial part of any application. We can find data validation in:
  1. UI layer before sending objects to the server
  2. At the server-side before processing it
  3. Before persisting data into the database
  • Validation is a cross-cutting concern/task, so as good practice, we should try to keep it apart from our business logic. JSR303 and JSR349 provide specifications for bean validation by using annotations.
  • This framework provides the reference implementation for JSR303 and JSR349 specifications.

Question - 88 : - What is the Spring MVC framework?

Answer - 88 : -

  • Spring MVC is a request driven framework and one of the core components of the Spring framework.
  • It comes with ready to use loosely coupled components and elements that greatly aid developers in building flexible and robust web applications.
  • The MVC (Model - View - Controller) architecture separates and provides loose coupling between the different aspects of the application – input logic (Model), business logic (Controller), and UI logic (View).

Question - 89 : - What are the benefits of Spring MVC framework over other MVC frameworks?

Answer - 89 : -

  • Clear separation of roles – There is a specialised dedicated object for every role.
  • Reusable business code logic – With Spring MVC, there is no need for duplicating the code. Existing objects can be used as commands instead of replicating them in order to extend a particular framework base class.
  • Spring MVC framework provides customizable binding and validation.
  • Also provides customizable locale and theme resolution.
  • Spring MVC supports customizable handler mapping and view resolution too.

Question - 90 : -
What is a View Resolver pattern and explain its significance in Spring MVC?

Answer - 90 : -

  • It is a J2EE pattern that allows the applications to dynamically choose technology for rendering the data on the browser (View).
  • Any technology like HTML, JSP, XSLT, JSF, or any other such technology can be used as View.
  • The View Resolver has the information of different views. The Controller returns the name of the View which is then passed to View Resolver by the DispatcherServlet for selecting the appropriate View technology and then the data is displayed.
  • The default ViewResolver used in Spring MVC is InternalResourceViewResolver.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners