September 26, 2018

Srikaanth

Hitachi Spring MVC Recently Asked Interview Questions Answers

What is spring framework? Why Java programmer should use Spring framework?

Very common Spring interview question, Spring is a framework which helps Java programmer in development. Spring provides dependency Injection and IOC container, Spring MVC flow and several useful API for Java programmer.

What is default scope of bean in Spring framework ?

The default scope of a Spring bean is Singleton scope.

Does Spring singleton beans are thread-safe ?

No, Spring singleton beans are not thread-safe. Singleton doesn't mean bean would be thread-safe.
Hitachi Spring MVC Recently Asked Interview Questions Answers
Hitachi Spring MVC Recently Asked Interview Questions Answers

What is Spring Security?


Spring security framework focuses on providing both authentication and authorization in java applications. It also takes care of most of the common security vulnerabilities such as CSRF attack.

It’s very beneficial and easy to use Spring security in web applications, through the use of annotations such as @EnableWebSecurity. You should go through following posts to learn how to use Spring Security framework.

Name some of the design patterns used in Spring Framework?

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.
Can we send an Object as the response of Controller handler method?

Yes we can, using @ResponseBody annotation. This is how we send JSON or XML based response in restful web services.

How to upload file in Spring MVC Application?

Spring provides built-in support for uploading files through MultipartResolver interface implementations. It’s very easy to use and requires only configuration changes to get it working. Obviously we would need to write controller handler method to handle the incoming file and process it.

How to validate form data in Spring Web MVC Framework?

Spring supports JSR-303 annotation based validations as well as provide Validator interface that we can implement to create our own custom validator. For using JSR-303 based validation, we need to annotate bean variables with the required validations.

For custom validator implementation, we need to configure it in the controller class.

What is Spring MVC Interceptor and how to use it?

Spring MVC Interceptors are like Servlet Filters and allow us to intercept client request and process it. We can intercept client request at three places – preHandle, postHandle and afterCompletion.

We can create spring interceptor by implementing HandlerInterceptor interface or by extending abstract class HandlerInterceptorAdapter.

We need to configure interceptors in the spring bean configuration file. We can define an interceptor to intercept all the client requests or we can configure it for specific URI mapping too.

What is Spring JdbcTemplate class and how to use it?

Spring Framework provides excellent integration with JDBC API and provides JdbcTemplate utility class that we can use to avoid bolier-plate code from our database operations logic such as Opening/Closing Connection, ResultSet, PreparedStatement etc.

What is Aspect Oriented Programming (AOP)?

- Basically Aspect oriented programming complements object oriented programming by providing another way of programming model structure.
- In addition to classes, AOP gives you aspect, which enables modularization of concerns such as Transaction management or logging and can be separated out from the application business logic of the code (these kinds of concerns are termed as crosscutting concerns). AOP supports separating application business logic from System services.

What is IOC or Dependency Injection?

The basic concept of IOC (Dependency of Injection) is that you do not create your objects but describe how they should be created.

You don’t directly connect your component and services together in code but describe which services are needed by which component in configuration file.

You just need to describe the dependency, the Spring container is then responsible for hooking it all up.

When to use Dependency Injections?

There are different scenarios where you Dependency Injections are useful.

- You need to inject configuration data into one or more component.
- You need to inject the same dependency into multiple components.
- You need to inject different implementation of the same dependency.
- You need to inject the same implementation in different configuration.
- You need some of the services provided by container.

When you should not use Dependency Injection?

There were scenarios where you don’t need dependency injections e.g.
- You will never need a different implementation.
- You will never need different configurations.

What is Bean Factory in Spring?

- A Bean Factory is like a factory class that contains collections of beans. The Bean Factory holds bean definition of multiple beans within itself and then instantiates the bean when asked by client.
- Bean Factory is actual representation of the Spring IOC container that is responsible for containing and managing the configured beans.

Different Spring Bean Scope.

1. singleton : Return a single bean instance per Spring IOC container.

2. prototype : Return a new bean instance each time when requested.

3. request : Return a single bean instance per HTTP request.

4. session : Return a single bean instance per HTTP session.

5. global session : Return a single bean instance per global HTTP session and only valid when used in portlet context.

Subscribe to get more Posts :