Looking to ace your Spring interview? You have come to the right place. This article will help you to become fluent in Spring framework. Here I will discuss the common Spring interview questions and their corresponding answers.
Following are the top 20 solved Spring questions that can aid in your preparation for technical interviews and selection tests. Through this Q&A freshers can revise their Spring course and experienced professionals can increase their fluency in core Spring questions.
- What is Spring?
Spring is a Java platform that gives comprehensive infrastructure support for developing Java Apps. In simple terms, Spring handles the infrastructure so that its users can focus on application.
- What are the various ways of using Spring framework?
Spring can be used as:
- A third- party web framework using Spring frameworks middle- tier
- A full-fledged Spring web app
- For remote usage
- Enterprise Java Bean which can wrap existing Plain Old Java Objects(POJOs)
- What are the modules of Spring framework?
- Core Container
- Data Access/Integration
- AOP (Aspect Oriented Programming)
- Instrumentation and Test
- What are the advantages of using Spring?
- Easy to test
- Open source and has no vendor lock-in
- JDBC is simplified due to Dependency injection and Inversion of control
- Its layered architecture enables users to use what they need and leave when they don’t
- What are the important features of Spring framework?
- Lightweight framework
- Dependency Injection or Inversion of Control
- MVC framework
- Transaction management
- Aspect- Oriented Programming
- What is Aspect- Oriented Programming/ AOC?
Aspect- Oriented Programming is a programming paradigm like Procedural- Oriented Programming and Object- Oriented Programming. It functions by breaking down program logic into distinct parts called so-called concerns.
- What is IOC?
Inversion of Control is a principle in software engineering by which the portions of the control of a program is transferred to a container or framework. It’s most often used in the context of object-oriented programming.
- What is Dependency Injection?
Dependency injection is a way of implementing IoC, where the control being inverted is the setting of object’s dependencies.
- Difference between Dependency Injection & Inversion of Controller?
The aim of Inversion of control and Dependency Injection is to make the system more decoupled and maintainable by removing dependencies of an application. IOC (Inversion of control) is a generic term while DI (Dependency injection) is a subset of IOC. IOC is a concept where the flow of the application is inverted.
- What is the role of IOC container in Spring?
IOC container is responsible to: create the instance, configure the instance, and assemble the dependencies
- Name the types of IOC container in Spring?
The types of IOC containers in Spring framework are BeanFactory & ApplicationContext
- What are the different components of a Spring application?
The different components of a Spring App are:
- Interface: It defines the functions.
- Bean class: It contains properties, its setter and getter methods, functions etc.
- Spring Aspect Oriented Programming (AOP): Provides the functionality of cross-cutting concerns.
- Bean Configuration File: Contains the information of classes and how to configure them.
- User program: It uses the function.
- What is a Spring configuration file?
It is an XML file. This file mainly contains the classes information. It describes how those classes are configured as well as introduced to each other.
- List out the versions of Spring framework
Spring 2.5, Spring 3.0 & Spring 4.0
- What are the major features in different versions of Spring?
- Spring 2.5: Released in 2007, it was the first version which supported annotations.
- Spring 3.0: Released in 2009, this version made full-fledged use of improvements in Java5 and also provided support to JEE6.
- Spring 4.0: Released in 2013, this was the first version to provide full support to Java 8.
- How many ways can Dependency Injection be done?
Dependency injection can be done in three ways: Constructor Injection, Setter Injection
& Interface Injection
- List out the benefits of IoC
- Reduces the amount of code used in applications
- Will make the testing of the application easier as neither singletons nor JNDI lookup is required in unit test cases.
- Encourages loose coupling with less effort
- Promotes lazy loading and eager instantiation of the services.
- What is BeanFactory in Spring?
The holder that instantiates, deals and arranges various beans is called BeanFactory. The beans have dependencies between themselves which are reflected in BeanFactory’s configuration data
- How many bean scopes are supported by Spring?
The Spring Framework supports five bean scopes: Singleton, Prototype, Session, Global session & Request.
- Differentiate between Beanfactory & ApplicationContext?
- More than one config files are possible with ApplicationContext while only one config file or .xml file is possible with BeanFactory.
- ApplicationContext publishes events to beans that are registered as listeners while BeanFactory doesn’t support this
- ApplicationContext support internationalization messages, application life-cycle events, validation and many enterprise services like JNDI access, EJB integration, remoting etc. while BeanFactory doesn’t support any of these.
- What are Spring Beans?
Spring Beans are the objects that form the backbone of your application and that are managed by the Spring IoC container
- Differentiate between singleton and prototype scope?
Singleton means the single bean definition to a single object instance per Spring IOC container whereas Prototype means a single bean definition to any number of object instances.
- What is auto wiring in Spring?
Autowiring is the process of injecting dependencies wherever required. It cannot be used to inject primitive and string values. It works with only with reference.
- What are the auto wiring modes?
- Define Bean Wiring.
Bean wiring is the combination of beans with Spring container. While wiring the Spring container should know what kind of beans are needed and how the container should tie the beans together using Dependency Injection.
Equipped with these Q&A, you are sure to crack Spring Interview. If you are still unsure of your proficiency, check out SpringPeople courses in Spring.
Latest posts by Vibhuthi Viswanathan
- 5 A’s of Artificial Intelligence - May 25, 2018
- 5 Java Annotations Every Developer Should Know - May 22, 2018
- 10 Latest Technology Used in Artificial Intelligence - May 9, 2018