October 12, 2018

Sreekanth B

Asus Most Frequently Asked Spring MVC Latest Interview Questions Answers

How do you call the multiple life cycle mechanisms configured for the same bean?

Multiple lifecycle mechanisms which are configured for the same bean, with different initialization methods, are called by the following ways :

1. Methods annotated with use of @PostConstruct.

2. afterPropertiesSet() as stated by the InitializingBean callback interface.

3. Custom configuration init() method

Destroy methods are called in the same order as follows :

1. Methods annotated with the use of @PreDestroy.

2. destroy() as stated by the DisposableBean callback interface.

3. destroy() method with custom configuration.
Asus Most Frequently Asked Spring MVC Latest Interview Questions Answers
Asus Most Frequently Asked Spring MVC Latest Interview Questions Answers

What are the methods associated with the FactoryBean interface?

Following are the methods associated with factory bean interface:

1. Object getObject() : This returns an instance of the object which the factory creates. This instance can possibly be shared, depending on the factory returns singletons or prototypes.

2. Boolean isSingleton() : This returns true if this FactoryBean returns singletons, otherwise false.

3. Class getObjectType() : This returns the object type returned by the getObject() method or null if the type is unknown in advance.

What are the functionalities provided by the context package to enhance the BeanFactory functionality?

The functionalities provided by context package are as follows:

1. Message access in i18n-style, through the MessageSource interface.

2. Resource access such as URLs and files, through which, the ResourceLoader interface, can be accessed and used.

3. Publication of events, through the beans that allow, implementing the ApplicationListener interface. It is done through the use, of the ApplicationEventPublisher interface.

4. Multiple loading contexts, allowing each to be focused on one particular layer, such as the web layer of an application, through the HierarchicalBeanFactory interface.

How can you achieve Internationalization using MessageSource?

Internationnalization using message source can be achieved by the following :

1. String get Mesage(String code, Objct[] args, String default, Local loc) :
The basic method used for retrieving a message from the MessageSource. When no message is to be found for the specified locale, the default message is used.

2. String getMessage(String code, Objct[] args, Locale loc) :
Essentially the same as the last method, but with a difference, no default message is specified; if the message cannot be found, a NoSuchMessageException is shown.

3. String getMessage(MessageSourceResolvable resolvable, Local locale) :
Properties used for the preceding methods are also wrapped in a class named MessageSourceResolvable, which you can use with this method.

Enlist and explain the main methods associated with the Resource interface.

Methods associated with resource interface are as follows:

1. getInputStream() : It locates and opens the resource, returning an InputStream to read from the resource.

2. exists() : Returns a boolean which indicates whether this resource actually exists in physical form.

3. isOpen() : Returns a boolean which indicates whether this resource represents a handle with an open stream.

4. getDescription() : Returns a description for this resource, which is used for error output when working with the resource.

Give some examples where property editing is used in spring.

Following are the examples for property editing in spring :

1. Setting of properties on beans is done by using PropertyEditors. To mention java.lang.string as the value for a property of some bean you're declaring in XML file, Spring will use the ClassEditor to try resolving the parameter to a Class object.

2. Passing HTTP request parameters in Spring's MVC framework can be done using all kinds of PropertyEditors that can be manually bind in all subclasses of the CommandController.
Explain the main AOP concepts and terminology.

The main AOP concepts are as follows:

1. Aspect : A modularization of a concern that cuts through multiple classes.

2. Join point : It is a point during which the execution of a programming, such as the execution of method or handling of an exception.

3. Advice : An action taken by an aspect for a particular join point.

4. Point cut : A predicate that is matched to join points.

5. Introduction : Declaration of additional methods or fields on behalf of a type.

6. Target object : Object which is advised by one or more aspects.

7. AOP proxy : An object which is created by AOP framework for implementing the aspect contracts.

8. Weaving : Linking of aspects with other application types or objects to create an advised object.

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.

What is dependency Injection?

Dependency Injection is one of the design pattern, which allows injecting dependency on Object, instead of object resolving the dependency.

What is the front controller class of Spring MVC?

A front controller is defined as “a controller which handles all requests for a Web Application.” DispatcherServlet (actually a servlet) is the front controller in Spring MVC that intercepts every request and then dispatches/forwards requests to an appropriate controller.

When a web request is sent to a Spring MVC application, dispatcher servlet first receives the request. Then it organizes the different components configured in Spring’s web application context (e.g. actual request handler controller and view resolvers) or annotations present in the controller itself, all needed to handle the request.

Difference between <context:annotation-config> vs <context:component-scan>?

1) First big difference between both tags is that <context:annotation-config> is used to activate applied annotations in already registered beans in application context. Note that it simply does not matter whether bean was registered by which mechanism e.g. using <context:component-scan> or it was defined in application-context.xml file itself.

2) Second difference is driven from first difference itself. It registers the beans defined in config file into context + it also scans the annotations inside beans and activate them. So <context:component-scan> does what <context:annotation-config> does, but additionally it scan the packages and register the beans in application context.

Difference between @Component, @Controller, @Repository & @Service annotations?

1) The @Component annotation marks a java class as a bean so the component-scanning mechanism of spring can pick it up and pull it into the application context. To use this annotation, apply it over class as below:

@Component
public class EmployeeDAOImpl implements EmployeeDAO {
    ...
}
2) The @Repository annotation is a specialization of the @Component annotation with similar use and functionality. In addition to importing the DAOs into the DI container, it also makes the unchecked exceptions (thrown from DAO methods) eligible for translation into Spring DataAccessException.

3) The @Service annotation is also a specialization of the component annotation. It doesn’t currently provide any additional behavior over the @Component annotation, but it’s a good idea to use @Service over @Component in service-layer classes because it specifies intent better.

4) @Controller annotation marks a class as a Spring Web MVC controller. It too is a @Component specialization, so beans marked with it are automatically imported into the DI container. When you add the @Controller annotation to a class, you can use another annotation i.e. @RequestMapping; to map URLs to instance methods of a class.

What is view Resolver pattern ? how it work in Spring MVC?

Spring Framework Interview Question Answers | Spring MVC FAQView Resolver pattern is a J2EE pattern which allows a web application to dynamically choose it's view technology e.g. HTML, JSP, Tapestry, JSF, XSLT or any other view technology. In this pattern, View resolver holds mapping of different views, controller return name of the view, which is then passed to View Resolver for selecting an appropriate view. Spring MVC framework supplies inbuilt view resolver for selecting views.

Subscribe to get more Posts :