
Spring Interview Questions By Srinivas Short description: ● Spring Interview Questions for the Developers. @2016 Attune World Wide All right reserved. www.attuneww.com Contents Contents 1. Preface 1.1. About This Guide 1.2. Intended Audience 1.3. Revision History 2. Spring Interview Questions Spring Interview Questions Last Updated: November 2016 | Page 2 of 19 1. Preface 1.1. About This Guide In this guide, the readers and the developers of the Spring Framework will find the technical questions and their related answers for their future interviews. 1.2. Intended Audience This document is helpful for the people who are looking for interview questions in Spring framework. 1.3. Revision History This document is the first document in this series Spring interview questions. Spring Interview Questions Last Updated: November 2016 | Page 3 of 19 2. Spring Interview Questions Q.1 What is Spring Framework? Which are its main modules? Ans: The Spring Framework is a Java platform which is providing extensive infrastructure support, where we can develop Java applications. With Spring, infrastructure part is handled so we can focus on application part. Presently, in Spring Framework, we have features which have been organized into 20 modules. These modules have been grouped into Data Access/Integration, Core Container, AOP (Aspect Oriented Programming), Web, Messaging, Instrumentation, and Test, in below diagram can be seen. Spring Interview Questions Last Updated: November 2016 | Page 4 of 19 Q. 2 What are advantages of using Spring Framework? Following are the list of benefits of using Spring Framework – Lightweight: Spring is very lightweight, and when we are considering transparency and size. The basic version of spring framework is very less. Aspect oriented (AOP): Spring also supports Aspect oriented programming and gives us the ability for cohesive development, with the separation of application business logic from the system services. Container: Spring manages and contains the lifecycle and configuration of the application objects. MVC Framework: Spring's MVC framework is a very well-designed web framework, which can provide us a great alternative for web frameworks such as Struts. Inversion of control (IOC): With Spring, we achieve Loose coupling, in spring with the technique of Inversion of Control. The objects give their dependencies instead of looking or creating for the dependent objects. Transaction Management: Spring provides us with consistent transaction management interface which can scale down to a local transaction (using a single database) and scale up to global transactions (using JTA). Exception Handling: Spring provides us a convenient API for translating technology- specific exceptions (thrown by Hibernate, JDBC, or JDO, for example) into consistent, unchecked exceptions. Spring Interview Questions Last Updated: November 2016 | Page 5 of 19 Q.3 What are the different modules in Spring framework? Following are the modules of the Spring framework: ● Context module ● Bean module ● Core module ● JDBC module ● ORM module ● Expression Language module ● OXM module ● Transaction module ● Web module ● Web-Servlet module ● Web-Portlet module ● Java Messaging Service(JMS) module ● Web-Struts module Q.4. What is Spring configuration file? Spring configuration file is a XML file. This file is having the classes information and it also describes how these classes can be introduced and configured to each other. Q.5 What is Dependency Injection? Inversion of Control (IoC) can be said as a very common concept, and it can also be expressed in so many different ways and Dependency Injection can be said as one of the concrete example of Inversion of Control. This concept says, that if we do not create our objects but just describe them, how they have to be created. And also, we don't directly have to connect components and services together in code, but just have to describe which services have to be needed by which components, in configuration file. A container (normally some IOC container) then takes care of hooking it all up. Spring Interview Questions Last Updated: November 2016 | Page 6 of 19 Q.6 Which DI would you suggest setter-based DI or Constructor-based? Since we have the chance of mixing both, Setter-based DI and Constructor-based DI, it is a good rule of thumb for using constructor arguments for the mandatory dependencies and setters can be used for the optional dependencies. See that, the use of a @Required annotation on any setter has to happen for making the setters required dependencies. Q.7. What are the various types of the IoC (dependency injection)? Types of IoC are: ● Setter-based dependency injection: Setter-based DI can be accomplished by container, and that happens when we are calling setter methods on the beans, after we are invoking a no-argument static factory method or no-argument constructor for instantiating the bean. ● Constructor-based dependency injection: Constructor-based DI can be accomplished, when any container is invoking a class constructor with a number of arguments, each is representing a dependency on the other classes. Q.8 What is AOP? AOP or Aspect-oriented programming, is a programming technique that allows programmers in modularizing the behavior or crosscutting concerns, that can cut across typical divisions of responsibility, such as transaction management and logging. The core construct of AOP is an aspect, which is capable of encapsulating the behaviors which are affecting the multiple classes into the reusable modules. Spring Interview Questions Last Updated: November 2016 | Page 7 of 19 Q.9 What are the benefits of IOC? The main advantages of dependency injection or IOC are: ● This makes our application easy for testing, as it doesn't require any singletons or JNDI lookup mechanisms in your unit test cases. ● In our application, amount of code gets minimized. ● IOC containers can support the lazy loading and eager instantiation of services. ● Loose coupling can be promoted with least intrusive mechanism and minimal effort. Q.10 What are types of IoC containers? Explain them. There are two types of IoC containers: ● Spring ApplicationContext Container: This container adds more enterprise-specific functionality such as the ability for resolving textual messages from a properties file and ability for publishing application events to the interested event listeners. ● Bean Factory container: This can be said as simplest container which has been providing the basic support for DI. The BeanFactory can be normally preferred, where resources are limited like applet based or mobile devices applications. Q.11 What is Spring IoC container? The Spring IoC can wire them together, create the objects, configure them, and can also manage their complete lifecycle from creation till destruction. The Spring container uses dependency injection (DI) to manage the components that make up an application. Q.12 Give an example of BeanFactory implementation. XmlBeanFactory class can be said as the most commonly used BeanFactory implementation. This container is capable of reading configuration metadata from an XML file and can use it for creating a application or fully configured system. Spring Interview Questions Last Updated: November 2016 | Page 8 of 19 Q.13 What are the common implementations of the ApplicationContext? The three commonly used implementation of 'Application Context' are: ● ClassPathXmlApplicationContext: This container is capable of loading the definitions of the beans from XML . Here, we do not need to provide the full path of the XML file but we need for setting the CLASSPATH properly because this container can look for XML bean configuration file in the CLASSPATH. ● FileSystemXmlApplicationContext: This container is capable of loading the definitions of beans from an XML file. Here, we have to provide full path of XML bean configuration file to the constructor. ● WebXmlApplicationContext: This container can load with the XML file, with the definitions of all beans from within some web application. Q.14 What is the difference between ApplicationContext and Bean Factory? Following are some of the differences: ● Application contexts can provide us with some means for resolving text messages, including the support for i18n of those messages. ● Application contexts can give us a generic way for loading file resources and with images. ● Application contexts are capable of publishing events to beans that have been registered as listeners. ● Certain operations on the container or beans in the container, which have to be handled in a programmatic fashion with a bean factory, can be handled declaratively in an application context. ● The application context is also capable of implementing MessageSource, an interface which can be used for obtaining localized messages, with actual implementation being pluggable. Spring Interview Questions Last Updated: November 2016 | Page 9 of 19 Q.15 What are Spring beans? The objects which are forming the backbone of application and can also be managed by Spring IoC container are called beans. A bean is an object which has been assembled,instantiated and can otherwise be managed by some Spring IoC container. These beans can be created with configuration metadata which have to be supplied for the container, for example, in the form of XML <bean/> definitions. Q.16 What does a bean definition contain? The bean definition is having the information which can be called as configuration metadata, and it is much needed for container to know the below things:
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages19 Page
-
File Size-