Spring Interview Questions and Answers
Q1. What is a spring?
Ans: Spring is about to be a framework which facilitates Java programmer for improvement of code and it gives IOC box, Dependency Injector, MVC glide and many different APIs for the java programmer.
Q2. What are Advices in Spring?
Ans: It is the execution of an thing. Advice is like making your application research a new trick. They are generally delivered at joinpoints.
Q3. What is the default scope of bean in Spring framework?
Ans: The default scope of bean is Singleton for Spring framework.
Q4. Name the forms of transaction control which can be supported by way of Spring?
Ans: Transaction management supported by Spring are :
Declarative transaction management.
Programmatic transaction control.
Q5. Is Singleton beans are thread safe in Spring Framework?
Ans: No, singleton beans are not thread-secure in Spring framework.
Q6. What are the blessings of Spring Framework?
Ans: Following are the benefits of Spring framework:
Extensive utilization of Components
Reduces coding effort by using the usage of sample implementations such as singleton, manufacturing unit, carrier locator and so on.
Removal of leaking connections
Declarative transaction control
Easy to combine with 0.33 birthday celebration tools and technologies.
Q7. What is Bean Factory?
Ans: Bean Factory is core of the spring framework and, it's miles a Lightweight box which masses bean definitions and manages your beans. Beans are configured the use of XML report and manage singleton defined bean. It is also accountable for lifestyles cycle methods and injects dependencies. It additionally gets rid of adhoc singletons and factories.
Q8. Define Bean Wiring?
Ans: Bean wiring is the advent of associations between application additives which can be between the beans in a selected spring container.
Q9. What is called Spring MVC?
Ans: A Spring MVC is a unmarried shared controller example and it is used to deal with request kind controllers, interceptors which run in the IoC box. It additionally permits multiple Dispatcher Servlets that may share software context interface but not magnificence based totally interface.
Q10. Why Spring framework is needed?
Ans: Spring framework is wanted because it is –
Very Light Weight Container
Q11. Name the diverse modules used in spring framework?
AOP module (Aspect Oriented Programming)
JDBC abstraction and DAO module
The Core container module
MVC framework module
Application context module
O/R mapping integration module (Object/Relational)
Q12. Explain the RowCallbackHandler in Spring?
Ans: The RowCallbackHandler is called for every row in ResultSet and is used to examine values from the ResultSet.
Q13. Define Application context module?
Ans: This is a totally critical module and elements diverse necessary services like EJB integration, remoting, JNDI get entry to and scheduling. It transforms spring right into a framework. It additionally broadens the idea of BeanFactory by way of application of lifecycle events, imparting help for internationalization messages and validation.
Q14 .Write approximately AOP module?
Ans: AOP module is utilized for developing components for Spring applications. It additionally enables support for metadata programming in Spring.
Q15. What is a BeanFactory Interface?
Ans: Bean manufacturing unit interface is used to offer configuration framework for object advent and primary functionality around item control.
Q16. State the variations between ApplicationContext and BeanFactory in spring?
ApplicationContext permits a couple of config documents to exist while BeanFactory most effective permits one.
ApplicationContext can print events to beans registered as listeners. This function is not supported by means of BeanFactory.
ApplicationContext additionally offers aid for application of lifecycle activities, internationalization messages and validation and additionally provides offerings like EJB integration, remoting, JNDI get admission to and scheduling. These features too aren't supported by using Bean Factory.
Q17. What is Auto Wiring?
Ans: Autowiring is used to build relationships between the taking part beans. Spring box can routinely solve collaborators for beans.
Q18. What are the exceptional Modes of Autowiring?
Ans: Autowiring has five extraordinary modes:
no: no autowire
byName : Autowiring that may be performed by means of belongings call
byType : assets kind as autowired
constructor: It is much like byType and it is belongings is in constructor
autodetect : Spring is allowed to pick autowiring from byType or constructor
Q19. How to start the usage of spring?
Ans: Following steps desires to be finished to begin with the Spring:
Download Spring and its dependent document from spring’s website.
Create application context xml to define beans and its dependencies
Integrate software context xml with internet.Xml
Deploy and Run the utility
Q20. What are the methods of bean existence cycle?
Ans: There are crucial strategies of Bean lifestyles cycle:
Setup – called whilst bean is loaded into container
Teardown – known as when bean is unloaded into field
Q21 .What are the different sorts of occasions of Listeners?
Ans: Following are the exceptional sorts of events of listeners:
ContextClosedEvent – This occasion is known as while the context is closed.
ContextRefreshedEvent – This event is known as while context is initialized or refreshed
RequestHandledEvent – This occasion is called whilst the web context handles request
Q22. Differentiate among singleton and prototype bean?
Ans: Singleton means best one bean is defined per object instance at the same time as Prototype means one definition to multiple item times in Spring.
Q23. What are the kinds of Dependency Injection?
Ans: Two kinds of dependency injection are supported by means of spring framework:
Q24. Write about Core field module?
Ans: Core container module is chargeable for the simple functionality of the spring framework. The complete Spring framework is built with this module as a base.
Q25. What is AOP module?
Ans: This AOP module is used for spring enabled utility. Support has been supplied AOP alliance to make sure the interoperability between spring and different AOP frameworks.
It instructs spring to add annotations to the supply code and inform a way to practice elements.
Q26. What is AOP Alliance?
Ans: AOP alliance is an open-source project which is aimed at selling adoption of AOP. The AOP alliance’s goal is to define a common set of components and interfaces so as to enhance interoperability among one of a kind AOP implementations.
Q27. What is referred to as spring configuration file?
Ans: Spring configuration document is an XML report and it consists of class records. It additionally describes how those lessons are configured and engage with each other.
Q28. What are exclusive kinds of Autowire?
Ans: There are 4 different types of Auto twine:
Q29. What are the sorts of the transaction control that is supported through spring?
Ans: Following are the two forms of transaction management that has been supported through spring:
Q30. When are declarative and programmatic transaction management used?
Ans: When best a small quantity of transactional operations is there, it is suggested to apply Programmatic transaction control. But if there's a large quantity of transactional operations to be sorted, declarative transaction control is desired.
Q31. What is IOC?
Ans: IOC (Inversion of Control sample) is likewise known as dependency injection. IOC directs the programmers to depict the way to create items instead of truly creating them. But in this design sample, this manipulate has been given to assembler and assembler will instantiate required elegance if wanted.
Q32.Write approximately the one-of-a-kind kinds of Listener related events?
Ans: The special types of occasions related to listeners are:
ContextRefreshedEvent – This gets called whilst the context is refreshed or initialized.
RequestHandledEvent – This gets known as when the net context is coping with a request.
ContextClosedEvent – This receives known as while the context receives closed.
Q33. What is an Aspect?
Ans: Aspect is also referred to as as logging which is required during the utility. Logging or thing is a move slicing capability in an utility the usage of AOP.
Q34. What is a Joinpoint?
Ans: The point where an component may be introduced within the software is called a joinpoint. This factor can be a discipline being modified, a technique being referred to as or maybe an exception being thrown. At those factors, the brand new element’s code may be delivered to introduce a new behavior to the software.
Aspect code can be inserted at this point into everyday go with the flow of software to trade the contemporary behavior.
Q35. What is known as an Advice?
Ans: Advice will inform software on new behavior and it's miles the implementation of an factor. It is inserted into an application on the joinpoint.
Advice is the implementation of an issue. It is some thing like telling your utility of a brand new behavior. Generally, the advice is inserted into an software at joinpoints.
Q36. What is a Pointcut?
Ans: Pointcut is used to permit where the recommendation can be implemented.
Q37. What is weaving?
Ans: Weaving is used to create new proxy object via making use of elements to target item.
Q38. What is distinction among singleton and prototype bean?
Ans: Singleton Bean – Single bean definition to a single item example in step with Spring IOC container
Prototype Bean – Single bean definition to any range of object instances consistent with Spring IOC Container
Q39. In what factors, can weaving be implemented?
Ans: Following are the factors in which weaving may be implemented:
Class load Time
Q40 .What are the special styles of AutoProxying?
Ans: Following are the exclusive kinds of AutoProxying:
Q41. How can beans be made singleton or prototype?
Ans: The bean tag has an characteristic referred to as ‘singleton’. The bean is singleton if its value is ‘TRUE’, otherwise the bean is a prototype.
Q42 .What classes are used to Control the database connection?
Ans: Following are the instructions which can be used to control database connection:
Data Source Utils
Q43. Describe about DAO in Spring framework?
Ans: DAO is used to offer integration of Java database connectivity and Object relational mapping items. DAO is spring framework gives connection for JDBC, hibernate, JDO, JPA, Common customer interface and Oracle.
Q44 .What is Autoproxying?
Ans: Autoproxying is used to create proxy automatically for the spring customers. It gives following two training to aid this computerized proxy introduction:
Q45. What is Metadata Autoproxying?
Ans: Metadata Autoproxying can be achieved inspiring which can be driven by way of metadata. This is determined by source level attributes and maintains metadata inside the supply code.
This maintains metadata in a single vicinity and specifically used for declarative transaction help.
Q46 .What is ‘Throws advice’ in Spring?
Ans: ‘Throws Advice’ define the conduct whilst an exception happens. It is an interface and it has no strategies which want to be applied.
A class that implements this interface have to have technique with this signature:
Void samplethrow (Throw table t)
Void samplethrow(Method m, Object o, Object goal, Throw pill)
Q47. What are the diverse editors utilized in spring paintings?
Ans: The various custom editors provided via the Spring Framework are:
Q48. What are the blessings of spring framework?
Ans: Following are the advantages of spring framework:
Enables Plain Old Java Object (POJO) Programming and it permits continuous integration and testability
Dependency Injection and Inversion of Control that simplifies JDBC
Open supply framework which may be used for commercial purpose
Q49. How is Hibernate accessed the use of the Spring framework?
Ans: Hibernate can be accessed within the following two ways:
By IOC with a Callback and HibernateTemplate.
By making use of an AOP Interceptor and broadening the HibernateDaoSupport.
Q50. What are the diverse Channels supported by using Spring 2.Zero?
Ans: Following are the channels supported through spring version 2.0:
Q51. Why is declarative transaction management preferred in Spring?
Ans: Declarative transaction control has minimum effect on the software code and, consequently, is an idealistic lightweight container.
Q52. Explain the idea of a BeanFactory?
Ans: BeanFactory applies the idea of a factory pattern that utilizes IOC to split the utility’s dependencies and configuration from the real code.
Q53. What are the one-of-a-kind scopes of spring bean?
Ans: Scopes of spring bean are Singleton, prototype, request, session and worldwide consultation.
Q54 .What are all of the methods to access Hibernate by means of the usage of Spring?
Ans: There are approaches to get admission to hibernate the usage of spring:
Inversion of Control with a Hibernate Template and Callback
Extending HibernateDAOSupport and Applying an AOP Interceptor node.
Q55. How struts utility may be integrated with spring?
Ans: There are two options for struts utility that can be integrated with spring:
Configuration of Spring to manipulate beans using ContextLoader plugin and set their dependencies in a spring context file
Grab spring managed beans explicitly using agetwebapplicationcontext()
Q56.What is Inversion of manage (IOC)?
Ans: Inversion of Control (IOC) is likewise known as as dependency Injection which is nothingbut a layout sample that gives control to the assembler of classes. In fashionable, elegance will instantiate every other elegance if required.
But in this design pattern, this control has been to given to assembler and assembler will instantiate required elegance if needed.
Q57. Write the advantages of the use of IOC?
Ans: The essential blessings of dependency injection or IOC are that it reduces the quantity of coding required for the application. This permits the checking out of the software to be accomplished fast and without difficulty as no JNDI lookup mechanism or singletons are required. IOC packing containers also assist lazy loading and eager installation of services.
Q58. What is Inner bean? What is the drawback of internal bean?
Ans: If a bean element is directly embedded in a property tag at the same time as wiring beans, then the bean is referred to as Inner Bean. Its disadvantage is that it can't be reprocessed.
Q59.What are the exceptional styles of Injection in spring?
Ans: There are three sorts of Injection in spring:
Getter or Method Injection
Q60. What are the blessings of spring framework?
Ans: Following are the benefits of spring framework:
Light weight field whilst in comparison to j2EE packing containers
Built in Web MVC framework
Creates loosely coupled programs
Supports thing oriented programming like logging, transaction and safety
Configuration performed in XML layout which is straightforward to jot down and apprehend
Q61 .What are the styles of Advice?
Ans: There are five varieties of Advice:
After returning advice
After throwing recommendation
Q62. What is known as PreparedStatementCreator?
Ans: PreparedStatementCreator is one of the maximum commonly used interfaces for writing information to the database. CreatePreparedStatement() is a method that may be used to create and go back PreparedStatement from the Connection argument, and exception coping with is robotically taken care of. When this interface is carried out, a exclusive interface SqlProvider can also be implemented which has a method called getSql(). This approach is beneficial for providing square strings to the JdbcTemplate. It does not manage SQLExceptions.
Q63. What is SQLProvider?
Ans: SQLProvider has most effective one method known as getSql()and it is implemented using PreparedStatementCreator implementers. It is specifically used for debugging.
Q64. Write about BatchPreparedStatementSetter?
Ans: BatchPreparedStatementSetter is used to update greater than a unmarried row in one go, they are able to use BatchPreparedStatementSetter. This interface affords two techniques they're
setValues( PreparedStatement playstation , int i) throws SOL exception
Q65. What is the better method of using JDBC in Spring?
Ans: If JDBC is used with the template class referred to as JdbcTemplate, it offers a higher overall performance.
Q66. What exceptions do the DAO lessons, use in Spring throw?
Ans: In spring DAO training best throws SQLException.
Q67. Explain the benefits of using DAO module?
Ans: The database code may be kept easy and simple by using using the DAO module. This allows in stopping issues that upward thrust due to poor handling of closures of database assets. Also, the DAO module utilizes the AOP module to permit objects within the Spring software to apply transaction management services.
Q68. Name the tremendous ApplicationContext implementations used in the spring framework?
Ans: They are:
sixty nine How is a bean delivered to a Spring software?
<?Xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN">
The bean tag has an ID characteristic which shops the bean name and a class attributes which specifies the overall elegance name.
Q70. What are ORM integration modules?
Ans: Object/relational mapping (ORM) device is supported via Spring over directly JDBC by way of implementing the ORM module. Spring can be part of numerous essential ORM frameworks, together with JDO, iBATIS SQL Maps and Hibernate.
Q71. Mention and provide an explanation for the types of Advice in Spring?
Ans: Types of recommendation are:
Before advice: Advice this is finished previous to a joinpoint is called the ‘before advice’.
After returning recommendation: Advice that is accomplished after the ordinary of entirety of a joinpoint is known as the ‘after returning recommendation’.
After throwing recommendation: Advice this is executed simplest if a way exits abnormally by using throwing an exception, is referred to as the ‘after throwing recommendation’.
After (sooner or later) advice: Advice that is carried out irrespective of how a joinpoint exits is called ‘after eventually recommendation’.
Around recommendation: Advice that borders a joinpoint, for instance, a way invocation, is called an ‘around advice’. This may be used to carry out special activities before and after the invocation of approach.
Q72. What is the internet module?
Ans: The internet module allows the advent of a web software without XML. The web.Xml document desires to be configured for the usage of the internet module.
Q73. What is DataAccessException?
Ans: DataAccessException is a RuntimeException. It is an Unchecked Exception. The person can't be forced to address these forms of exceptions.
Q74 .What is XMLBeanFactory?
Ans: Spring includes numerous applications of Bean manufacturing facility. Out of those, org.Springframework.Beans.Manufacturing unit.Xml.XmlBeanFactory is a completely critical one. It loads the beans on the premise of the definitions saved in an XML file. For the introduction of an XmlBeanFactory, a java.Io.InputStream is exceeded to the constructor. The InputStream presents the XML to the factory. For example, for retrieval of the bean, the getBean() approach is referred to as via passing the call of the favored bean.
1 MyBean helloBean = (MyBean) manufacturing facility.GetBean("helloBean");
Q75. Name the Exception elegance that's related to the exceptions thrown by the programs?
Ans: It is the DataAccessException given by org.Springframework.Dao.DataAccessException
Q76. Mention the styles of lOC (dependency injection)?
Ans: The distinctive sorts of loC are: –
Setter Injection: With the assist of JavaBeans residences.
Constructor Injection: Dependencies are given in the form of constructor parameters.
Interface Injection: With the help of an interface, an Injection is performed.
Out of these three, most effective construction and setter are being utilized in Spring.
Q77. What are the crucial beans lifecycle techniques?
Ans: All in all, two bean lifecycle strategies are there. The first approach is the setup technique that is known as at some point of the loading of the bean into the container. The 2d is when the bean is unloaded from the field, and this technique is known as the teardown.
Q78. How can the default lifecycle techniques of beans be nullified?
Ans: The tag, bean, has useful attributes which can be used to define unique initialization and destruction methods.
For Example, two new methods forSetup and forTeardown may be delivered to the Foo class in the following way:
<bean id="bar" init-method=”forSetup” destroy=”forTeardown”/>
Q79. What is a Target?
Ans: A target is the magnificence that is suggested. This magnificence can both be a class to which we want to feature a unique conduct to or a third birthday party class. The target elegance is free to center on its main problem the usage of the AOP ideas, irrespective of any advice that is being implemented.
Q80.Explain the time period Proxy?
Ans: The term proxy refers to an item that is produced the utility of an recommendation to the goal item.
Q81. What is move cutting subject and subject in spring AOP?
Ans: Cross reducing concern: It is a challenge that is relevant all through the utility and it impacts the complete software. E.G Security, logging and facts transfer are the worries which are wished in almost each module of an software.