Should I Learn Spring Or Hibernate 2018
Are yous thinking of pursuing your career in Spring Framework? Are you searching for an appropriate QnA fix to prepare for your interviews? Here is a web log on Jump Interview Questions which discusses on peak 50 questions with proper explanation and examples. It will definitely help you to ace the interviews. Merely earlier starting with the Spring Interview Questions, let'due south take a quick look on Spring Framework's demand and status in the market.
Since information technology'southward release, the Bound Framework has connected to bloom in the marketplace. Bound community is continuously coming upward with new things and take spread into a vast ecosystem. Today, it holds the top position in the framework market. Bank check out the below graph which shows the frameworks most ofttimes used in the market as on January 2018.
You might inquire why is Spring certification so much in need? Well, the answer is, b ecause information technology provides a comprehensive programming and configuration model for modern Java-based enterprise applications. Information technology is not concerned with the deployment platform used. A key chemical element of Spring Framework is infrastructural support at the awarding level. Information technology's very much unlikely to become out of the market in the near future with more major releases announced.
Get Certified With Manufacture Level Projects & Fast Rails Your Career
Earlier we movement any farther let us accept a wait some of the nigh oftentimes asked Jump Interview Questions,
Q1. What are the major features in unlike versions of Spring Framework?
Q2. What is a Spring Framework?
Q3. List the advantages of Spring Framework
Q4. What are the different features of Spring Framework?
Q5. How many modules are there in Spring Framework and what are they?
Q6. What is a Spring configuration file?
Q7. What are the unlike components of a Bound awarding?
Q8. What are the various ways of using Spring Framework?
Q9. What is Spring IOC Container?
Q10. What do y'all mean past Dependency Injection?
Leap Interview Questions
So, here are the Top 50 Spring Interview Questions which are most probable to be asked past the interviewer. If you lot are seeking a time to come in this field, these questions volition surely help you to ace the interview. For your ease of access, I have categorized the questions nether a few topics, namely:
- Full general Questions
- Dependency Injection/ IoC
- Spring Beans
- Bound Annotations
- Spring Data Access
- Leap AOP
- Bound MVC
You may watch the webinar recording of Spring Interview Questions where our instructor has shared his experience and expertise that will help yous to crack any Spring Interview.
Spring Interview Questions and Answers for 2022 | Edureka
Let's begin with the beginning section of Spring interview questions that is the Full general Questions.
Full general Questions – Spring Interview Questions
ane. What are the major features in different versions of Spring Framework?
Version | Logo | Feature |
Spring 2.5 | ![]() | This version was released in 2007. It was the beginning version which supported annotations. |
Spring 3.0 | ![]() | This version was released in 2009. Information technologymade full-fledged use of improvements in Java5 and besides provided support to JEE6. |
Jump four.0 | ![]() | This version was released in 2013. This was the showtime version to provide full back up to Java viii. |
2. What is a Spring Framework?
-
Spring is a powerful open source, awarding framework created to reduce the complexity of enterprise application development.
- Information technology is calorie-free-weighted and loosely coupled.
- It has layered architecture, which allows you to select the components to utilise, while likewise providing a cohesive framework for J2EE application development.
- Leap framework is also called the framework of frameworks equally it provides support to various other frameworks such equally Struts, Hibernate, Tapestry, EJB, JSF etc.
three. List the advantages of Spring Framework.
- Because of Jump Frameworks layered architecture, you tin use what yous need and leave which you don't.
- Spring Framework enables POJO (Plain One-time Coffee Object) Programming which in turn enables continuous integration and testability.
- JDBC is simplified due to Dependency Injection and Inversion of Control.
- Information technology is open-source and has no vendor lock-in.
4. What are the different features of Jump Framework?
Following are some of the major features of Spring Framework :
- Lightweight: Leap is lightweight when it comes to size and transparency.
- Inversion of command (IOC): The objects give their dependencies instead of creating or looking for dependent objects. This is called Inversion Of Control.
- Aspect oriented Programming (AOP): Aspect oriented programming in Spring supports cohesive development past separating awarding business organisation logic from arrangement services.
- Container:Jump Framework creates and manages the life cycle and configuration of the awarding objects.
- MVC Framework: Spring Framework'south MVC spider web application framework is highly configurable. Other frameworks can also be used easily instead of Spring MVC Framework.
- Transaction Management: Generic brainchild layer for transaction management is provided by the Leap Framework. Jump's transaction support can be too used in container less environments.
- JDBC Exception Handling: The JDBC brainchild layer of the Spring offers an exception bureaucracy, which simplifies the error handling strategy.
5. How many modules are there in Spring Framework and what are they?
There are around 20 modules which are generalized into Core Container, Data Access/Integration, Web, AOP (Attribute Oriented Programming), Instrumentation and Test.
- Spring Core Container – This layer is basically the cadre of Spring Framework. It contains the following modules :
- Spring Core
- Spring Bean
- SpEL (Spring Expression Language)
- Spring Context
- Data Access/Integration – This layer provides back up to interact with the database. It contains the following modules :
- JDBC (Java DataBase Connectivity)
- ORM (Object Relational Mapping)
- OXM (Object XML Mappers)
- JMS (Coffee Messaging Service)
- Transaction
- Web – This layer provides support to create web application. It contains the post-obit modules :
- Web
- Web – MVC
- Web – Socket
- Web – Portlet
- Aspect Oriented Programming (AOP) – In this layer yous can utilise Advices, Pointcuts etc., to decouple the code.
- Instrumentation – This layer provides support to form instrumentation and classloader implementations.
- Test – T his layer provides support to testing with JUnit and TestNG.
Few Miscellaneous modules are given beneath:
- Messaging – This module provides support for STOMP. It also supports an note programming model that is used for routing and processing STOMP messages from WebSocket clients.
- Aspects – This module provides support to integration with AspectJ.
6. What is a Spring configuration file?
A Leap configuration file is an XML file. This file mainly contains the classes information. It describes how those classes are configured also as introduced to each other. The XML configuration files, yet, are verbose and more make clean. If it's not planned and written correctly, it becomes very difficult to manage in large projects.
7. What are the different components of a Spring application?
A Spring application, generally consists of following components:
- Interface: Information technology defines the functions.
- Bean class: Information technology contains properties, its setter and getter methods, functions etc.
- Spring Aspect Oriented Programming (AOP): Provides the functionality of cross-cutting concerns.
- Edible bean Configuration File: Contains the information of classes and how to configure them.
- User program: It uses the function.
8. What are the various ways of using Spring Framework?
Leap Framework can be used in various means. They are listed as follows:
- Equally a Total-fledged Bound spider web awarding.
- As a third-party web framework, using Bound Frameworks middle-tier.
- For remote usage.
- As Enterprise Java Bean which can wrap existing POJOs (Evidently Old Java Objects).
The adjacent section of Spring Interview Questions is on Dependency Injection and IoC container.
Dependency Injection/ IoC Container – Spring Interview Questions
nine. What is Spring IOC Container?
At the core of the Spring Framework, lies the Spring container. The container c reates the object, wires them together, configures them and manages their complete life cycle. The Spring container makes employ of Dependency Injection to manage the components that brand up an application. The container receives instructions for which objects to instantiate, configure, and assemble by reading the configuration metadata provided. This metadata tin can be provided either by XML, Coffee annotations or Java code.
10. What do you mean by Dependency Injection?
In Dependency Injection, you do not have to create your objects but have to describe how they should be created. You don't connect your components and services together in the code straight, but depict which services are needed by which components in the configuration file. The IoC container will wire them up together.
11. In how many means can Dependency Injection be washed?
In full general, dependency injection can be done in three means, namely :
- Constructor Injection
- Setter Injection
- Interface Injection
In Spring Framework, just constructor and setter injections are used.
12. Differentiate betwixt constructor injection and setter injection.
Constructor Injection vs Setter Injection
Constructor Injection | Setter Injection |
---|---|
At that place is no partial injection. | There tin can be partial injection. |
It doesn't override the setter property. | It overrides the constructor holding. |
It will create a new example if any modification is done. | It volition not create new instance if any modification is done. |
It works ameliorate for many properti es. | It works better for few properties. |
13. How many types of IOC containers are there in leap?
- BeanFactory: BeanFactory is like a factory class that contains a collection of beans. It instantiates the bean whenever asked for past clients.
- ApplicationContext: The ApplicationContext interface is built on top of the BeanFactory interface. It provides some actress functionality on top BeanFactory .
14. Differentiate between BeanFactory and ApplicationContext.
BeanFactory vs ApplicationContext
BeanFactory | ApplicationContext |
---|---|
Information technology is an interface defined in org.springframework.beans.manufactory.BeanFactory | It is an interface defined in org.springframework.context.ApplicationContext |
It uses Lazy initialization | Information technology uses Eager/ Ambitious initialization |
It explicitly provides a resource object using the syntax | It creates and manages resource objects on its ain |
It doesn't supports internationalization | It supports internationalization |
It doesn't supports annotation based dependency | Information technology supports annotation based dependency |
15. List some of the benefits of IoC.
Some of the benefits of IoC are:
- It will minimize the amount of code in your application.
- Information technology will brand your application like shooting fish in a barrel to test because it doesn't crave whatsoever singletons or JNDI lookup mechanisms in your unit test cases.
- It promotes loose coupling with minimal effort and to the lowest degree intrusive mechanism.
- It supports eager instantiation and lazy loading of the services.
Let'due south motility on to the next section of Leap Interview Questions, that is Spring Beans Interview Questions.
Spring Beans – Jump Interview Questions
16. Explain Spring Beans?
- They are the objects that class the backbone of the user'due south ap plication.
- Beans are managed by the Spring IoC container.
- They are instantiated, configured, wired and managed by a Spring IoC container
- Beans are created with the configuration metadata that the users supply to the container.
17. How configuration metadata is provided to the Spring container?
Configuration metadata can be provided to Spring container in following ways:
- XML-Based configuration:In Bound Framework, the dependencies and the services needed by beans are specified in configuration files which are in XML format. These configuration files normally contain a lot of edible bean definitions and application specific configuration options. They generally start with a edible bean tag . For example:
<bean id="studentbean" class="org.edureka.firstSpring.StudentBean"> <property proper noun="proper noun" value="Edureka"></property> </edible bean>
- Annotation-Based configuration: Instead of using XML to describe a bean wiring, yous can configure the bean into the component class itself by using annotations on the relevant class, method, or field declaration. By default, note wiring is not turned on in the Leap container. So, you need to enable it in your Spring configuration file before using it. For example:
<beans> <context:annotation-config/> <!-- edible bean definitions go here --> </beans>
- Java-based configuration: The key features in Spring Framework's new Java-configuration support are @Configuration annotated classes and @Bean annotated methods.
1. @Bean annotation plays the same office every bit the <bean/> element.
2.@Configuration classes allows to define inter-bean dependencies by just calling other @Bean methods in the same grade.
For example:
@Configuration public class StudentConfig { @Bean public StudentBean myStudent() { render new StudentBean(); } }
18. How many bean scopes are supported by Spring?
The Spring Framework supports five scopes. They are:
- Singleton:This provides scope for the bean definition to single case per Spring IoC container.
- Paradigm:This provides scope for a unmarried bean definition to have any number of object instances.
- Request:This provides scope for a bean definition to an HTTP-request.
- Session:This provides scope for a bean definition to an HTTP-session.
- Global-session:This provides telescopic for a bean definition to an Global HTTP-session.
The last three are available only if the users use a web-enlightened ApplicationContext .
19. What is the Bean life bike in Spring Bean Mill Container?
Edible bean life cycle in Leap Edible bean Manufacturing plant Container is as follows:
- The Spring container instantiates the bean from the bean's definition in the XML file.
- Spring populates all of the backdrop using the dependency injection, as specified in the bean definition.
- The manufactory calls setBeanName() past passing the edible bean's ID, if the edible bean implements the BeanNameAware interface.
- The manufacturing plant calls setBeanFactory() by passing an example of itself, if the edible bean implements the BeanFactoryAware interface.
- preProcessBeforeInitialization() methods are called if there are whatever BeanPostProcessors associated with the edible bean.
- If an init-method is specified for the bean, then it will be called.
- Finally, postProcessAfterInitialization() methods volition be chosen if there are any BeanPostProcessors associated with the bean.
To sympathize it in improve fashion bank check the below diagram:
20. Explicate inner beans in Spring.
A bean can exist declared as an inner bean only when it is used as a holding of another bean. For defining a bean, the Bound'south XML based configuration metadata provides t he employ of <bean> element inside the <holding> or <constructor-arg>. Inner beans are always anonymous and they are ever scoped as prototypes. For example, let's say we have 1 Student class having reference of Person class. Hither we will be creating but one instance of Person class and use it inside Student.
Here'south a Educatee class followed past bean configuration file:
Pupil.java
public class Student { individual Person person; //Setters and Getters } public course Person { individual String name; individual String accost; //Setters and Getters }
studentbean.xml
<bean id=“StudentBean" class="com.edureka.Educatee"> <belongings proper noun="person"> <!--This is inner bean --> <edible bean class="com.edureka.Person"> <property name="name" value=“Scott"></property> <property name="address" value=“Bangalore"></property> </edible bean> </property> </bean>
21. Define Bean Wiring.
When beans are combined together within the Jump container, it's called wiring or bean wiring. The Spring container needs to know what beans are needed and how the container should use dependency injection to tie the beans together, while wiring beans.
22. What practice you empathise by auto wiring and name the different modes of it?
The Leap container is able to autowire relationships betwixt the collaborating beans. That is, it is possible to let Spring resolve collaborators for your bean automatically past inspecting the contents of the BeanFactory.
Different modes of bean automobile-wiring are:
- no: This is default setting which ways no autowiring. Explicit bean reference should exist used for wiring.
- byName: It injects the object dependency according to proper name of the edible bean. It matches and wires its properties with the beans defined by the same names in the XML file.
- byType: It injects the object dependency according to blazon. It matches and wires a property if its type matches with exactly one of the beans proper noun in XML file.
- constructor: It injects the dependency by calling the constructor of the class. It has a large number of parameters.
- autodetect: First the container tries to wire using autowire by constructor, if it tin can't and then information technology tries to autowire by byType.
23. What are the limitations with auto wiring?
Post-obit are some of the limitations you might face with auto wiring:
- Overriding possibility:You can e'er specify dependencies using <constructor-arg> and <holding> settings which will override autowiring.
- Primitive data type: Simple backdrop such as primitives, Strings and Classes tin't exist autowired.
- Confusing nature: E'er prefer using explicit wiring because autowiring is less precise .
In the next section, nosotros will talk over on Bound Annotations Interview Questions.
Spring Annotations – Spring Interview Questions
24. What do you mean by Annotation-based container configuration?
Instead of using XML to describe a bean wiring, the programmer moves the configuration into the component class itself by using annotations on the relevant class, method, or field declaration. It acts equally an alternative to XML setups. For example:
@Configuration public class AnnotationConfig { @Bean public MyDemo myDemo() { return new MyDemoImpll(); } }
25. How note wiring can be turned on in Spring?
By default, Annotation wiring is not turned on in the Spring container. T hus, to use annotation based wiring we must enable it in our Spring configuration file past configuring< context:annotation-config /> element. For instance:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://world wide web.w3.org/2001/XMLSchema-case" xmlns:context="http://www.springframework.org/schema/context"> <context:annotation-config/> <beans ………… /> </beans>
26. What's the difference between @Component, @Controller, @Repository & @Service annotations in Spring?
@Component: This marks a java class every bit a edible bean. It is a generic stereotype for whatever Leap-managed component. The component-scanning mechanism of spring now can pick information technology up and pull it into the awarding context.
@Controller: This marks a class equally a Spring Web MVC controller. Beans marked with it are automatically imported into the Dependency Injection container.
@Service: This note is a specialization of the component notation. Information technology doesn't provide whatever boosted beliefs over the @Component notation. Y'all can use @Service over @Component in service-layer classes as it specifies intent in a better way.
@Repository: This annotation is a specialization of the @Component annotation with similar apply and functionality. It provides boosted benefits specifically for DAOs. Information technology imports the DAOs into the DI container andmakes the unchecked exceptions eligible for translation into Spring DataAccessException.
27. What exercise you sympathise by @Required annotation?
@Required is applied to edible bean property setter methods. This notation simply indicates that the affected edible bean property must be populated at the configuration time with the assistance of an explicit property value in a bean definition or with autowiring. If the affected edible bean holding has not been populated, the container will throw BeanInitializationException.
For case:
public course Employee { individual Cord name; @Required public void setName(String proper noun) {this.proper noun=proper noun; } public cord getName() { return name; } }
28. What do you understand past @Autowired annotation?
The@ Autowired annotation provides more accurate control over where and how autowiring should be done. This annotation is used to autowire bean on the setter methods, constructor, a belongings or methods with arbitrary names or multiple arguments. By default, it is a type driven injection.
For Example:
public course Employee { private String proper noun; @Autowired public void setName(String name) {this.name=proper noun; } public string getName() { return name; } }
29. What do you lot empathise by @Qualifier note?
When you lot create more than than one bean of the aforementioned blazon and desire to wire only one of them with a holding you can utilize the@Qualifier annotation along with@ Autowired to remove the ambivalence by specifying which verbal bean should exist wired.
For instance, here we accept two classes, Employee and EmpAccount respectively. In EmpAccount, using @Qualifier its specified that edible bean with id emp1 must be wired.
Employee.coffee
public class Employee { private String proper noun; @Autowired public void setName(String name) { this.name=proper noun; } public cord getName() { return name; } }
EmpAccount.java
public class EmpAccount { private Employee emp; @Autowired @Qualifier(emp1) public void showName() { System.out.println(“Employee proper noun : ”+emp.getName); } }
30. What exercise you understand by @RequestMapping annotation?
@RequestMapping annotation is used for mapping a particular HTTP asking method to a specific course/ method in controller that will be handling the respective request. This annotation can exist applied at both levels:
- Grade level : Maps the URL of the request
- Method level : Maps the URL also as HTTP asking method
Next section of Bound Interview Questions is on Data Access.
Data Access – Spring Interview Questions
31. Describe Spring DAO support?
The Data Access Object (DAO) back up in Spring makes it easy to piece of work with information admission technologies like JDBC, Hibernate or JDO in a consistent fashion. This allows one to switch between the persistence technologies hands. It also allows you to code without worrying about catching exceptions that are specific to each of these technology .
32. Name the exceptions thrown past the Leap DAO classes.
Come across the below diagram, information technology depicts all the Bound DAO classes in the hierarchical club.
33. Which classes are nowadays in spring JDBC API?
Classes nowadays in JDBC API are as follows:
- JdbcTemplate
- SimpleJdbcTemplate
- NamedParameterJdbcTemplate
- SimpleJdbcInsert
- SimpleJdbcCall
34. What are the ways by which Hide can be accessed using Spring?
There are tw o means past west hich we tin can access Hide using Spring:
- Inversion of Control with a Hibernate Template and Callback
- Extending HibernateDAOSupport and Applying an AOP Interceptor node
35. Name the types of transaction direction that Spring supports.
Two types of transaction management are supported by Jump. They are:
- Programmatic transaction management: In this, the transaction is managed with the help of programming. Information technology provides you extreme flexibility, but it is very hard to maintain.
- Declarative transaction management: In this, the transaction management is separated from the business code. Simply annotations or XML based configurations are used to manage the transactions.
36. What are the different ORM's supported by Bound?
Different ORM'southward supported past Jump are depicted via the below diagram:
The next section of Bound interview questions discusses on Spring AOP Interview Questions.
Aspect Oriented Programming (AOP) – Bound Interview Questions
37. Draw AOP.
Aspect-oriented programming or AOP is a programming technique which allows programmers to modularize crosscutting concerns or behavior that cuts across the typical divisions of responsibility. Examples of cantankerous-cutting concerns can be logging and transaction management. The core of AOP is an attribute . It encapsulates behaviors that tin affect multiple classes into reusable modules.
38. What practice you mean by Aspect?
Aspect is a modularization of business organization which cuts across multiple objects. Transaction management is a adept instance of a crosscutting concern in J2EE applications. Aspects are implemented using regular classes or regular classes annotated with the @Attribute annotation in Spring Framework.
39. Explain JoinPoint.
A betoken during the execution of a plan is called JoinPoint, such as the execution of a method or the handling of an exception. In Spring AOP, a joinpoint ever represents a method execution.
twoscore. What is an Communication?
An Activity taken by an aspect at a particular joinpoint is known as an Advice. Spring AOP uses an advice as an interceptor, maintaining a chain of interceptors "effectually" the join bespeak.
41. What are the dissimilar types of Advices?
Different types of Advices in Spring AOP are:
- Earlier: These types of advices execute before the joinpoint methods and are configured using@Beforeannotation mark.
- After returning:These types of advices execute afterward the joinpoint methods completes executing normally and are configured using @AfterReturning notation marking.
- After throwing: These types of advices execute merely if joinpoint method exits by throwing an exception and are configured using @AfterThrowing annotation mark.
- Afterwards (finally): These types of advices execute after a joinpoint method, regardless of the method'south get out whether usually or exceptional render and are configured using @Afterward annotation mark.
- Effectually:These types of advices execute before and after a joinpoint a nd are configured using @Effectually annotation mark.
42. Indicate out the difference between concern and cross-cutting business concern in Spring AOP?
The concern is the beliefs nosotros desire to have in a particular module of an application. Information technology can be defined every bit a functionality nosotros want to implement.
The cross-cutting concern is a concern which is applicative throughout the application. This affects the unabridged application. For example, logging, security and data transfer are the concerns needed in almost every module of an application, thus they are the cross-cutting concerns.
43. What are the different AOP implementations?
Dissimilar AOP implementations are depicted by the below diagram:
44. What are the difference between Spring AOP and AspectJ AOP?
Spring AOP vs AspectJ AOP
Jump AOP | AspectJ AOP |
---|---|
Runtime weaving through proxy is washed | Compile time weaving through AspectJ Coffee tools is done |
It supports only method level PointCut | Information technology suports field level Pointcuts |
It is DTD based | It is schema based and Note configuration |
45. What practice you lot mean by Proxy in Spring Framework?
An object which is created after applying advice to a target object is known as a Proxy. In case of customer objects the target object and the proxy object are the same.
46. In Spring, what is Weaving?
The process of linking an aspect with other application types or objects to create an advised object is chosen Weaving. In Leap AOP, weaving is performed at runtime. Refer the below diagram:
The concluding section of Spring interview questions is on Spring MVC Interview Questions.
MVC (Model-View-Controller) – Spring Interview Questions
47. What do you mean by Spring MVC framework?
The Bound web MVC framework provides model-view-controller architecture and gear up to use components that are used to develop flexible and loosely coupled spider web applications. The MVC pattern helps in separating the different aspects of the application like input logic, business logic and UI logic, while providing a loose coupling between all these elements. Get Started with Leap MVC
48. Describe DispatcherServlet.
The DispatcherServlet is the cadre of Spring Web MVC framework. It handles all the HTTP requests and responses. The DispatcherServlet receives the entry of handler mapping from the configuration file and forwards the asking to the controller. The controller then returns an object of Model And View. The DispatcherServlet checks the entry of view resolver in the configuration file and calls the specified view component.
49. Explicate WebApplicationContext.
The WebApplicationContext is an extension of the plain ApplicationContext. Information technology has some extra features that are necessary for web applications. It differs from a normal ApplicationContext in terms of its adequacy of resolving themes and in deciding which servlet information technology is associated with.
50. In Spring MVC framework, what is controller?
Controllers provide access to the application behavior. These behaviors are generally defined through a service interface. Controllers interpret the user input and transform information technology into a model which is represented to the user by the view. In Spring, controller is implemented in a very abstruse way. It also enables yous to create a wide diverseness of controllers.
I promise this set of Bound Interview Questions and Answers volition help you in preparing for your interviews. All the best!
If you want to learn Spring and wish to use it while developing Java applications, then check out the Spring Certification Preparation by Edureka, a trusted online learning company with a network of more 250,000 satisfied learners spread beyond the globe.
Got a question for united states? Please mention it in the comments section and we will get back to you.
Should I Learn Spring Or Hibernate 2018,
Source: https://www.edureka.co/blog/interview-questions/spring-interview-questions/
Posted by: garrettnectur.blogspot.com
0 Response to "Should I Learn Spring Or Hibernate 2018"
Post a Comment