InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What are ORM's Spring supports ? |
|
Answer» Spring supports the following ORM's −
|
|
| 2. |
What are the ways to access Hibernate by using Spring? |
|
Answer» There are two ways to access hibernate using spring −
|
|
| 3. |
Explain RequestMapping annotation. |
|
Answer» RequestMapping annotation is used to map a URL to either an entire class or a particular handler method. |
|
| 4. |
Explain the Controller annotation. |
|
Answer» The Controller annotation indicates that a particular class serves the role of a controller. Spring does not require you to extend any controller base class or reference the Servlet API. |
|
| 5. |
What is Controller in Spring MVC framework? |
|
Answer» Controllers provide access to the application behavior that you typically define through a service interface. Controllers interpret user input and transform it into a model that is represented to the user by the view. Spring implements a controller in a very abstract way, which enables you to create a wide variety of controllers. |
|
| 6. |
What are the advantages of Spring MVC over Struts MVC ? |
|
Answer» Following are some of the advantages of Spring MVC over Struts MVC −
|
|
| 7. |
What is WebApplicationContext ? |
|
Answer» The WebApplicationContext is an extension of the plain ApplicationContext that has some extra features necessary for web applications. It differs from a normal ApplicationContext in that it is capable of resolving themes, and that it knows which servlet it is associated with. |
|
| 8. |
What is a DispatcherServlet? |
|
Answer» The Spring Web MVC framework is designed around a DispatcherServlet that handles all the HTTP requests and responses. |
|
| 9. |
What is Spring MVC framework? |
|
Answer» The Spring web MVC framework provides model-view-controller architecture and ready components that can be used to develop flexible and loosely coupled web applications. The MVC pattern results in separating the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements. |
|
| 10. |
Which of the above transaction management type is preferable? |
|
Answer» Declarative transaction management is preferable over programmatic transaction management though it is less flexible than programmatic transaction management, which allows you to control transactions through your code. |
|
| 11. |
What are the types of the transaction management Spring supports? |
|
Answer» Spring supports two types of transaction management −
|
|
| 12. |
How JdbcTemplate can be used? |
|
Answer» With use of Spring JDBC framework the burden of resource management and error handling is reduced a lot. So it leaves developers to write the statements and queries to get the data to and from the database. JdbcTemplate provides many convenience methods for doing things such as converting database data into primitives or objects, executing prepared and callable statements, and providing custom database error handling. |
|
| 13. |
How JDBC can be used more efficiently in spring framework? |
|
Answer» JDBC can be used more efficiently with the help of a template class provided by spring framework called as JdbcTemplate. |
|
| 14. |
What is AspectJ? based aspect implementation? |
|
Answer» AspectJ refers to a style of declaring aspects as regular Java classes annotated with Java 5 annotations. |
|
| 15. |
What is XML Schema based aspect implementation? |
|
Answer» Aspects are implemented using regular classes along with XML based configuration. |
|
| 16. |
What are the types of advice? |
|
Answer» Spring aspects can work with five kinds of advice mentioned below −
|
|
| 17. |
What are the different points where weaving can be applied? |
|
Answer» Weaving can be done at compile time, load time, or at runtime. |
|
| 18. |
What is Weaving? |
|
Answer» Weaving is the process of linking aspects with other application types or objects to create an advised object. |
|
| 19. |
What is Target object? |
|
Answer» The object being advised by one or more aspects, this object will always be a proxy object. Also referred to as the advised object. |
|
| 20. |
What is Introduction? |
|
Answer» An introduction allows you to add new methods or attributes to existing classes. |
|
| 21. |
What is Pointcut? |
|
Answer» This is a set of one or more joinpoints where an advice should be executed. You can specify pointcuts using expressions or patterns as we will see in our AOP examples. |
|
| 22. |
What is Advice? |
|
Answer» This is the actual action to be taken either before or after the method execution. This is actual piece of code that is invoked during program execution by Spring AOP framework. |
|
| 23. |
What is Join point? |
|
Answer» This represents a point in your application where you can plug-in AOP aspect. You can also say, it is the actual place in the application where an action will be taken using Spring AOP framework. |
|
| 24. |
What is the difference between concern and cross-cutting concern in Spring AOP? |
|
Answer» Concern − 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 define our concerns. Cross-cutting concern − It's a concern which is applicable throughout the application and it affects the entire application. e.g. logging , security and data transfer are the concerns which are needed in almost every module of an application, hence are cross-cutting concerns. |
|
| 25. |
What is Aspect? |
|
Answer» A module which has a set of APIs providing cross-cutting requirements. For example, a logging module would be called AOP aspect for logging. An application can have any number of aspects depending on the requirement. In Spring AOP, aspects are implemented using regular classes (the schema-based approach) or regular classes annotated with the Aspect annotation (AspectJ style). |
|
| 26. |
Describe some of the standard Spring events. |
|
Answer» Spring provides the following standard events −
|
|
| 27. |
How is event handling done in Spring? |
|
Answer» Event handling in the ApplicationContext is provided through the ApplicationEvent class and ApplicationListener interface. So if a bean implements the ApplicationListener, then every time an ApplicationEvent gets published to the ApplicationContext, that bean is notified. |
|
| 28. |
What is Spring Java Based Configuration? Give some annotation example. |
|
Answer» Java based configuration option enables you to write most of your Spring configuration without XML but with the help of few Java-based annotations. For example: Annotation Configuration indicates that the class can be used by the Spring IoC container as a source of bean definitions. The Bean annotation tells Spring that a method annotated with Bean will return an object that should be registered as a bean in the Spring application context. |
|
| 29. |
What are the JSR-250 Annotations? Explain them. |
|
Answer» Spring has JSR-250 based annotations which include PostConstruct, PreDestroy and Resource annotations.
|
|
| 30. |
What does Qualifier annotation mean? |
|
Answer» There may be a situation when you create more than one bean of the same type and want to wire only one of them with a property, in such case you can use Qualifier annotation along with Autowired to remove the confusion by specifying which exact bean will be wired. |
|
| 31. |
What does Autowired annotation mean? |
|
Answer» This annotation provides more fine-grained control over where and how autowiring should be accomplished. The Autowired annotation can be used to autowire bean on the setter method just like Required annotation, constructor, a property or methods with arbitrary names and/or multiple arguments. |
|
| 32. |
What does Required annotation mean? |
|
Answer» This annotation simply indicates that the affected bean property must be populated at configuration time, through an explicit property value in a bean definition or through autowiring. The container throws BeanInitializationException if the affected bean property has not been populated. |
|
| 33. |
How do you turn on annotation wiring? |
|
Answer» Annotation wiring is not turned on in the Spring container by default. So, before we can use annotation-based wiring, we will need to enable it in our Spring configuration file by configuring <context:annotation-config/>. |
|
| 34. |
What is Annotation-based container configuration? |
|
Answer» An alternative to XML setups is provided by annotation-based configuration which relies on the bytecode metadata for wiring up components instead of angle-bracket declarations. Instead of using XML to describe a bean wiring, the developer moves the configuration into the component class itself by using annotations on the relevant class, method, or field declaration. |
|
| 35. |
Can you inject null and empty string values in Spring? |
|
Answer» Yes. |
|
| 36. |
What are the limitations with autowiring? |
|
Answer» Limitations of autowiring are −
|
|
| 37. |
What are different Modes of auto wiring? |
|
Answer» The autowiring functionality has five modes which can be used to instruct Spring container to use autowiring for dependency injection −
|
|
| 38. |
What is bean auto wiring? |
|
Answer» The Spring container is able to autowire relationships between collaborating beans. This means that it is possible to automatically let Spring resolve collaborators (other beans) for your bean by inspecting the contents of the BeanFactory without using <constructor-arg> and <property> elements. |
|
| 39. |
How can you inject Java Collection in Spring? |
|
Answer» Spring offers four types of collection configuration elements which are as follows −
|
|
| 40. |
What are inner beans in Spring? |
|
Answer» A <bean/> element inside the <property/> or <constructor-arg/> elements defines a so-called inner bean. An inner bean definition does not require a defined id or name; the container ignores these values. It also ignores the scope flag. Inner beans are always anonymous and they are always scoped as prototypes. |
|
| 41. |
Explain Bean lifecycle in Spring framework? |
|
Answer» Following is sequence of a bean lifecycle in Spring −
|
|
| 42. |
Are Singleton beans thread safe in Spring Framework? |
|
Answer» No, singleton beans are not thread-safe in Spring framework. |
|
| 43. |
What is default scope of bean in Spring framework? |
|
Answer» The default scope of bean is Singleton for Spring framework. |
|
| 44. |
What bean scopes does Spring support? Explain them. |
|
Answer» The Spring Framework supports following five scopes, three of which are available only if you use a web-aware ApplicationContext.
|
|
| 45. |
How do you define a bean scope? |
|
Answer» When defining a <bean> in Spring, you have the option of declaring a scope for that bean. For example, to force Spring to produce a new bean instance each time one is needed, you should declare the bean's scope attribute to be prototype. Similar way if you want Spring to return the same bean instance each time one is needed, you should declare the bean's scope attribute to be singleton. |
|
| 46. |
How do add a bean in spring application? |
|
Answer» Check the following example − <?xml version = "1.0" encoding = "UTF-8"?><beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id = "helloWorld" class = "com.tutorialspoint.HelloWorld"> <property name = "message" value = "Hello World!"/> </bean></beans> |
|
| 47. |
How do you provide configuration metadata to the Spring Container? |
|
Answer» There are following three important methods to provide configuration metadata to the Spring Container −
|
|
| 48. |
What does a bean definition contain? |
|
Answer» The bean definition contains the information called configuration metadata which is needed for the container to know the followings −
|
|
| 49. |
What is the difference between Bean Factory and ApplicationContext? |
|
Answer» Following are some of the differences −
|
|
| 50. |
What are the common implementations of the ApplicationContext? |
|
Answer» The three commonly used implementation of 'Application Context' are −
|
|