Question: What are the advantages of Spring MVC over Struts MVC ?
Ans: 1. There is clear separation between models, views and controllers in Spring.
2. Spring’s MVC is very versatile and flexible based on interfaces but Struts forces Actions and Form object into concrete inheritance.
3. Spring provides both interceptors and controllers.. Read More
To see Spring MVC hello world example click here
2. Spring’s MVC is very versatile and flexible based on interfaces but Struts forces Actions and Form object into concrete inheritance.
3. Spring provides both interceptors and controllers.. Read More
To see Spring MVC hello world example click here
Question: Difference between FileSystemResource and ClassPathResource ?
Ans: In FileSystemResource you need to give path of spring-config.xml (Spring Configuration) file relative to your project or the absolute location of the file.
You can get this by right-clicking the spring-config.xml … Read More
Ans: In FileSystemResource you need to give path of spring-config.xml (Spring Configuration) file relative to your project or the absolute location of the file.
You can get this by right-clicking the spring-config.xml … Read More
Question: Difference between BeanFactory and ApplicationContext ?
Ans: BeanFactory instantiates beans lazily i.e. Beans are instantiated when you get them from BeanFactory not on loading BeanFactory.
Ans: BeanFactory instantiates beans lazily i.e. Beans are instantiated when you get them from BeanFactory not on loading BeanFactory.
1
2
| BeanFactory beanFactory = new XMLBeanFactory(new ClassPathResource("spring-beans.xml")); // factory is loaded,Emp emp = beanFactory.getBean(''empBean''); // bean is instantiated |
Question: How to customize bean destruction process ?
Ans: The Spring offers several callback interfaces to modify the behaviour of your bean. By implementing DisposableBean interface Spring Container will call destroy() method … Read More
Ans: The Spring offers several callback interfaces to modify the behaviour of your bean. By implementing DisposableBean interface Spring Container will call destroy() method … Read More
Question: How to customize bean initialization process ?
Ans: The Spring offers several callback interfaces to modify the behaviour of your bean. By implementing InitializingBean interface Spring Container will call afterPropertiesSet() method … Read More
Ans: The Spring offers several callback interfaces to modify the behaviour of your bean. By implementing InitializingBean interface Spring Container will call afterPropertiesSet() method … Read More
Question: How to implement inheritance in Bean definition ?
Ans: Inheritance can be implemented by specifying the ‘parent’ attribute in bean tag and passing id of (parent) the bean that you want to inherit .
In the example below … Read More
Ans: Inheritance can be implemented by specifying the ‘parent’ attribute in bean tag and passing id of (parent) the bean that you want to inherit .
In the example below … Read More
Question: Explain inner bean in Spring ?
Ans: A bean which is defined (embedded) inside the property tag of other bean is called an inner bean. Inner beans can not be used (referred) by other beans except the enclosing one …. Read More
Ans: A bean which is defined (embedded) inside the property tag of other bean is called an inner bean. Inner beans can not be used (referred) by other beans except the enclosing one …. Read More
Question: What is Dependency Injection in Spring ?
Ans: In spring objects define their associations (dependencies) and do not worry about how to get those dependencies ; now it is the responsibility of Spring to provide the required dependencies for creating objects … Read More
Ans: In spring objects define their associations (dependencies) and do not worry about how to get those dependencies ; now it is the responsibility of Spring to provide the required dependencies for creating objects … Read More
Question: What is Inversion of Control in spring ?
Ans: IOC means inverting the control of creating the object from our own using new operator to Spring container …Read More
Ans: IOC means inverting the control of creating the object from our own using new operator to Spring container …Read More
Question: What are different types of injection in Spring ?
Ans: Three types of injection in Spring3 Framework
(1) Setter Injection
(2) Constructor Injection
(3) Getter or Method Injection
Ans: Three types of injection in Spring3 Framework
(1) Setter Injection
(2) Constructor Injection
(3) Getter or Method Injection
Question: Benefits of using Spring Framework ?
Ans: Spring is relatively light weight container in comparison to other J2EE containers. It does not use much memory and CPU cycles for loading beans, providing services like transaction control , AOP management, JDBC interaction. …Read More
Ans: Spring is relatively light weight container in comparison to other J2EE containers. It does not use much memory and CPU cycles for loading beans, providing services like transaction control , AOP management, JDBC interaction. …Read More
Question: Describe different modules of Spring Framework ?
Ans: Spring comprises of the following modules.
Core container : Basic functionality of Spring is provided by the core container. BeanFactory is the primary component of core container, an implementation of the Factory design pattern. …Read More
Ans: Spring comprises of the following modules.
Core container : Basic functionality of Spring is provided by the core container. BeanFactory is the primary component of core container, an implementation of the Factory design pattern. …Read More
Question: What is BeanFactory ?
Ans: BeanFactory ( org.springframework.beans.factory.BeanFactory an interface) acts as Spring IoC container that is responsible for containing, configuring and managing the application beans. …Read More
Ans: BeanFactory ( org.springframework.beans.factory.BeanFactory an interface) acts as Spring IoC container that is responsible for containing, configuring and managing the application beans. …Read More
Question: What is XmlBeanFactory ?
Ans: There are a many implementations of the BeanFactory interface. XmlBeanFactory class is most common implementation of BeanFactory. …Read More
Ans: There are a many implementations of the BeanFactory interface. XmlBeanFactory class is most common implementation of BeanFactory. …Read More
Question: What is ApplicationContext ?
Ans: ApplicationContext ( org.springframework.context.ApplicationContext ) is an interface which makes Spring a framework. It is derivd from BeanFactory, so has all the functionality of BeanFactory and adds lots more. …Read More
Ans: ApplicationContext ( org.springframework.context.ApplicationContext ) is an interface which makes Spring a framework. It is derivd from BeanFactory, so has all the functionality of BeanFactory and adds lots more. …Read More
Question: What are the common implementations of the Application Context ?
Ans: ClassPathXmlApplicationContext : It loads the context definition from an XML file present in the classpath, treating context definitions as classpath resources. …Read More
Ans: ClassPathXmlApplicationContext : It loads the context definition from an XML file present in the classpath, treating context definitions as classpath resources. …Read More
Question: What is Bean wiring ?
Ans: The process of linking (associating) beans with each other within a Spring container is called bean wiring. All the Spring managed beans of the application needs to be defined in an xml file …Read More
Ans: The process of linking (associating) beans with each other within a Spring container is called bean wiring. All the Spring managed beans of the application needs to be defined in an xml file …Read More
Question: What is auto wiring ?
Ans: The Spring container provides the functionality of connecting beans with each other automatically called autowiring . Rather we inject one bean into the other using ref attribute, Spring can look into the BeanFactory and decide how to inject one bean into the other …Read More
Ans: The Spring container provides the functionality of connecting beans with each other automatically called autowiring . Rather we inject one bean into the other using ref attribute, Spring can look into the BeanFactory and decide how to inject one bean into the other …Read More
Question: What are the different bean scopes in Spring ? Explain with an example ?
Ans: In Spring, creation of beans can be controlled by defining the scope of bean. To define scope attribute ‘scope’ of <bean> tag is used. There are five types of bean scopes in Spring …Read More
Ans: In Spring, creation of beans can be controlled by defining the scope of bean. To define scope attribute ‘scope’ of <bean> tag is used. There are five types of bean scopes in Spring …Read More
Question: What is Aspect Oriented programming (AOP) ? Explain with an example ?
Ans: AOP is a programming technique used to manage cross-cutting concerns like logging, security and transaction management. To implement AOP we need to create aspects (classes) which contains cross-cutting functionality …Read More
To see AOP implementation examples click here
Ans: AOP is a programming technique used to manage cross-cutting concerns like logging, security and transaction management. To implement AOP we need to create aspects (classes) which contains cross-cutting functionality …Read More
To see AOP implementation examples click here
Question: What is the difference between concerns and cross-cutting concerns ?
Ans: Concern is behavior which we want to have in a module of an application. Concern may be defined as a functionality we want to implement. Issues in which we are interested defines our concerns …Read More
To see AOP implementation examples click here
Ans: Concern is behavior which we want to have in a module of an application. Concern may be defined as a functionality we want to implement. Issues in which we are interested defines our concerns …Read More
To see AOP implementation examples click here
Question: What is Aspect in Spring AOP? Explain with an example ?
Ans: Aspect defines the implementation of cross-cutting concern. We implement a cross-cutting functionality by creating an aspect. Aspect encapsulates our cross-cutting concern …Read More
To see AOP implementation examples click here
Ans: Aspect defines the implementation of cross-cutting concern. We implement a cross-cutting functionality by creating an aspect. Aspect encapsulates our cross-cutting concern …Read More
To see AOP implementation examples click here
Question: What is Advice in Spring AOP ? Explain with an example ?
Ans: Action performed by an aspect at a particular join point is called an Advice. Different types of advice are “around,” “before” ,”after”, “afterreturning” and “afterthrowing” …Read More
To see AOP implementation examples click here
Ans: Action performed by an aspect at a particular join point is called an Advice. Different types of advice are “around,” “before” ,”after”, “afterreturning” and “afterthrowing” …Read More
To see AOP implementation examples click here
Question: What is Pointcut in Spring AOP ? Explain with an example ?
Ans: A pointcut is an expression/predicate which points to a join point. Pointcut defines where to hook the advice …Read More
To see AOP implementation examples click here
Ans: A pointcut is an expression/predicate which points to a join point. Pointcut defines where to hook the advice …Read More
To see AOP implementation examples click here
Question: What is join point ? Explain with an example ?
Ans: Join point represents execution of a method where we want to hook the advice into.
Consider execution of a program and during this some methods are called say meth1(), meth2(), meth3() …Read More
To see AOP implementation examples click here
Ans: Join point represents execution of a method where we want to hook the advice into.
Consider execution of a program and during this some methods are called say meth1(), meth2(), meth3() …Read More
To see AOP implementation examples click here
Question: What is Around advice ? Explain with an example ?
Ans: This advice is combination of before and after advices. It lets you do something before target method (join point) and some other things after the target method (join point) …Read More
To see AOP implementation examples click here
Ans: This advice is combination of before and after advices. It lets you do something before target method (join point) and some other things after the target method (join point) …Read More
To see AOP implementation examples click here
Question: Explain Spring MVC framework with an example ?
Ans: Explain Spring MVC architecture with an example ? The MVC is a standard software architecture that aims to separate business logic from presentation logic, enabling the development, testing and maintenance of both isolated . (1) The user triggers an event through the UI (click a button on the page or something).
(2) The controller receives the event and coordinates how things will happen on the server side, i.e. the flow goes to the objects required to perform the business rule.. Read More
To see Spring MVC hello world example click here
Ans: Explain Spring MVC architecture with an example ? The MVC is a standard software architecture that aims to separate business logic from presentation logic, enabling the development, testing and maintenance of both isolated . (1) The user triggers an event through the UI (click a button on the page or something).
(2) The controller receives the event and coordinates how things will happen on the server side, i.e. the flow goes to the objects required to perform the business rule.. Read More
To see Spring MVC hello world example click here
Spring Security Interview questions Answer
Some of the reader requested to provide Spring Security interview questions and answer, So i though to update this article with few of Spring security question I came across. Here are those:
How do you setup LDAP Authentication using Spring Security?
This is a very popular Spring Security interview question as Spring provides out of the box support to connect Windows Active directory for LDAP authentication and with few configuration in Spring config file you can have this feature enable. See How to perform LDAP authentication in Java using Spring Security for detailed code explanation and sample.
How do you control concurrent Active session using Spring Security?
Another Spring interview question which is based upon Out of box feature provided by Spring framework. You can easily control How many active session a user can have with a Java application by using Spring Security. See this spring security example of how to control concurrent session in Java and Spring for exact details.
Some of the reader requested to provide Spring Security interview questions and answer, So i though to update this article with few of Spring security question I came across. Here are those:
How do you setup LDAP Authentication using Spring Security?
This is a very popular Spring Security interview question as Spring provides out of the box support to connect Windows Active directory for LDAP authentication and with few configuration in Spring config file you can have this feature enable. See How to perform LDAP authentication in Java using Spring Security for detailed code explanation and sample.
How do you control concurrent Active session using Spring Security?
Another Spring interview question which is based upon Out of box feature provided by Spring framework. You can easily control How many active session a user can have with a Java application by using Spring Security. See this spring security example of how to control concurrent session in Java and Spring for exact details.
Question1: What is IOC or inversion of control?
Answer: This Spring interview question is first step towards Spring framework and many interviewer starts Spring interview from this question. As the name implies Inversion of control means now we have inverted the control of creating the object from our own using new operator to container or framework. Now it’s the responsibility of container to create object as required. We maintain one xml file where we configure our components, services, all the classes and their property. We just need to mention which service is needed by which component and container will create the object for us. This concept is known as dependency injection because all object dependency (resources) is injected into it by framework.
Example:
<bean id="createNewStock" class="springexample.stockMarket.CreateNewStockAccont">
<property name="newBid"/>
<property name="newBid"/>
</bean>
In this example CreateNewStockAccont class contain getter and setter for newBid and container will instantiate newBid and set the value automatically when it is used. This whole process is also called wiring in Spring and by using annotation it can be done automatically by Spring, refereed as auto-wiring of bean in Spring.
Question 2: Explain Bean-LifeCycle.
Following steps explain their life cycle inside container.
1. Container will look the bean definition inside configuration file (e.g. bean.xml).
2 using reflection container will create the object and if any property is defined inside the bean definition then it will also be set.
3. If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean’s ID.
4. If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself.
5. If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization() methods will be called before the properties for the Bean are set.
4. If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself.
5. If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization() methods will be called before the properties for the Bean are set.
6. If an init() method is specified for the bean, it will be called.
7. If the Bean class implements the DisposableBean interface, then the method destroy() will be called when the Application no longer needs the bean reference.
7. If the Bean class implements the DisposableBean interface, then the method destroy() will be called when the Application no longer needs the bean reference.
8. If the Bean definition in the Configuration file contains a 'destroy-method' attribute, then the corresponding method definition in the Bean class will be called.
Question 3: what is Bean Factory, have you used XMLBeanFactory?
Ans: BeanFactory is factory Pattern which is based on IOC design principles.it is used to make a clear separation between application configuration and dependency from actual code.
XmlBeanFactory is one of the implementation of bean Factory which we have used in our project.
org.springframework.beans.factory.xml.XmlBeanFactory is used to create bean instance defined in our xml file.
BeanFactory factory = new XmlBeanFactory(new FileInputStream("beans.xml"));
Or
ClassPathResource resorce = new ClassPathResource("beans.xml");
XmlBeanFactory factory = new XmlBeanFactory(resorce);
XmlBeanFactory factory = new XmlBeanFactory(resorce);
Question 4: What are the difference between BeanFactory and ApplicationContext in spring?
Answer : This one is very popular spring interview question and often asks in entry level interview. ApplicationContext is preferred way of using spring because of functionality provided by it and interviewer wanted to check whether you are familiar with it or not.
ApplicationContext.
|
BeanFactory
|
Here we can have more than one config files possible
|
In this only one config file or .xml file
|
Application contexts can publish events to beans that are registered as listeners
|
Doesn’t support.
|
Support internationalization (I18N) messages
|
It’s not
|
Support application life-cycle events, and validation.
|
Doesn’t support.
|
Support many enterprise services such JNDI access, EJB integration, remoting
|
Doesn’t support.
|
Question 5: What are different modules in spring?
Answer : spring have seven core modules
1. The Core container module
2. Application context module
3. AOP module (Aspect Oriented Programming)
4. JDBC abstraction and DAO module
5. O/R mapping integration module (Object/Relational)
6. Web module
7. MVC framework module
Question 6: What is difference between singleton and prototype bean?
Ans: This is another popular spring interview questions and an important concept to understand. Basically a bean has scopes which defines their existence on the application
Singleton: means single bean definition to a single object instance per Spring IOC container.
Prototype: means a single bean definition to any number of object instances.
Prototype: means a single bean definition to any number of object instances.
Whatever beans we defined in spring framework are singleton beans. There is an attribute in bean tag named ‘singleton’ if specified true then bean becomes singleton and if set to false then the bean becomes a prototype bean. By default it is set to true. So, all the beans in spring framework are by default singleton beans.
<bean id="createNewStock" class="springexample.stockMarket.CreateNewStockAccont" singleton=”false”>
<property name="newBid"/>
</bean>
<property name="newBid"/>
</bean>
Question 7: What type of transaction Management Spring support?
Ans: This spring interview questions is little difficult as compared to previous questions just because transaction management is a complex concept and not every developer familiar with it. Transaction management is critical in any applications that will interact with the database. The application has to ensure that the data is consistent and the integrity of the data is maintained. Two type of transaction management is supported by spring
1. Programmatic transaction management
2. Declarative transaction management.
Question 8: What is AOP?
Answer : The core construct of AOP is the aspect, which encapsulates behaviors affecting multiple classes into reusable modules. AOP is a programming technique that allows developer to modularize crosscutting concerns, that cuts across the typical divisions of responsibility, such as logging and transaction management. Spring AOP, aspects are implemented using regular classes or regular classes annotated with the@Aspect annotation
Question 9: Explain Advice?
Answer: It’s an implementation of aspect; advice is inserted into an application at join points. Different types of advice include “around,” “before” and “after” advice
Question 10: What is joint Point and point cut?
Ans: This is not really a spring interview questions I would say an AOP one. Similar to Object oriented programming, AOP is another popular programming concept which complements OOPS. Join point is an opportunity within code for which we can apply an aspect. In Spring AOP, a join point always represents a method execution.
Pointcut: a predicate that matches join points. A point cut is something that defines at what join-points an advice should be applied
These spring interview Questions and answers are not very difficult and focused on spring fundamentals rather than focusing on advanced feature of session management, spring security, authentication etc. we will cover of those question on some other interview article. I would also suggest that share some spring questions asked to you guys during interview and than I can put together those with there answers for quick reference of everybody.

No comments:
Post a Comment