YouTube Icon

Interview Questions.

Top 50 Core-spring Interview Questions - Jul 25, 2022

fluid

Top 50 Core-spring Interview Questions

Q1. What Are The Different Points Where Weaving Can Be Applied?

Weaving can be performed at collect time, load time, or at runtime.

Q2. What Is Target Object?

The item being recommended with the aid of one or greater elements, this item will constantly be a proxy object. Also called the advised object.

Q3. What Is Bean Auto Wiring?

The Spring field is able to autowire relationships between collaborating be. This me that it is possible to automatically let Spring solve collaborators (other be) on your bean by using examining the contents of the BeanFactory with out the usage of <constructor-arg> and <property> factors.

Q4. How Do You Provide Configuration Metadata To The Spring Container?

There are following three important strategies to offer configuration metadata to the Spring Container:

XML primarily based configuration report.

Annotation-based totally configuration

Java-based totally configuration

Q5. What Is The Difference Between Concern And Cross-slicing Concern In Spring Aop?

Concern: Concern is conduct which we want to have in a module of an application. Concern may be defined as a functionality we need to implement. Issues wherein we're interested define our worries.

Cross-reducing difficulty: It's a problem that's applicable throughout the utility and it influences the complete utility. E.G. Logging , security and information trfer are the worries which can be needed in almost every module of an application, subsequently are go-slicing worries.

Q6. How Is Event Handling Done In Spring?

Event managing inside the ApplicationContext is supplied thru the ApplicationEvent elegance and ApplicationListener interface. So if a bean implements the ApplicationListener, then every time an ApplicationEvent gets posted to the ApplicationContext, that bean is notified.

Q7. What Bean Scopes Does Spring Support? Explain Them.?

The Spring Framework helps following 5 scopes, three of that are to be had most effective in case you use an internet-aware ApplicationContext.

Singleton: This scopes the bean definition to a single instance in line with Spring IoC box.

Prototype: This scopes a unmarried bean definition to have any number of object instances.

Request: This scopes a bean definition to an HTTP request. Only legitimate inside the context of a web-conscious Spring ApplicationContext.

Session: This scopes a bean definition to an HTTP consultation. Only valid in the context of an internet-conscious Spring ApplicationContext.

Worldwide-session: This scopes a bean definition to a worldwide HTTP consultation. Only legitimate inside the context of a web-aware Spring ApplicationContext.

Q8. What Is Spring Java Based Configuration? Give Some Annotation Example.?

Java primarily based configuration option enables you to put in writing most of your Spring configuration with out XML however with the help of few Java-based annotations.

For example: Annotation @Configuration suggests that the elegance can be used by the Spring IoC box as a supply of bean definitions. The @Bean annotation tells Spring that a way annotated with @Bean will return an object that need to be registered as a bean inside the Spring application context.

Q9. How Can You Inject Java Collection In Spring?

Spring gives four forms of collection configuration factors which are as follows:

<list>: This enables in wiring i.E. Injecting a list of values, allowing duplicates.

<set>: This allows in wiring a set of values however without any duplicates.

<map>: This may be used to inject a collection of call-cost pairs in which call and price can be of any kind.

<props>: This can be used to inject a set of call-value pairs wherein the call and cost are each Strings.

Q10. Explain Bean Life Cycle In Spring Framework?

Following is sequence of a bean lifecycle in Spring:

Instantiate - First the spring field reveals the bean's definition from the XML report and instantiates the bean..

Populate residences - Using the dependency injection, spring populates all the residences as detailed inside the bean definition..

Set Bean Name - If the bean implements BeanNameAware interface, spring passes the bean's id to setBeanName() technique.

Set Bean factory - If Bean implements BeanFactoryAware interface, spring passes the beanfactory to setBeanFactory() method.

Pre Initialization - Also called postprocess of bean. If there are any bean BeanPostProcessors associated with the bean, Spring calls postProcesserBeforeInitialization() method.

Initialize be - If the bean implements IntializingBean,its afterPropertySet() technique is known as. If the bean has init method announcement, the required initialization technique is known as.

Post Initialization - If there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() techniques might be called.

Ready to use - Now the bean is ready to use via the application.

Destroy - If the bean implements DisposableBean , it'll name the spoil() technique .

Q11. What Are The Benefits Of Ioc?

The main blessings of IOC or dependency injection are:

It minimizes the quantity of code on your software.

It makes your software smooth to check because it does not require any singletons or JNDI research mechanisms for your unit check cases.

Loose coupling is promoted with minimal attempt and least intrusive mechanism.

IOC packing containers guide keen instantiation and lazy loading of offerings.

Q12. What Are The Common Implementations Of The Applicationcontext?

The 3 usually used implementation of 'Application Context' are:

FileSystemXmlApplicationContext: This field hundreds the definitions of the be from an XML document. Here you need to provide the overall route of the XML bean configuration file to the constructor.

ClassPathXmlApplicationContext: This box loads the definitions of the be from an XML record. Here you do not need to offer the total direction of the XML file but you want to set CLASSPATH nicely because this field will appearance bean configuration XML record in CLASSPATH.

WebXmlApplicationContext: This box masses the XML document with definitions of all be from inside an internet utility.

Q13. What Is Aop?

Aspect-orientated programming, or AOP, is a programming technique that lets in programmers to modularize crosscutting concerns, or behavior that cuts throughout the everyday divisions of duty, inclusive of logging and traction control. The center assemble of AOP is the issue, which encapsulates behaviors affecting multiple classes into reusable modules.

Q14. Describe Some Of The Standard Spring Events.?

Spring offers the subsequent fashionable occasions:

ContextRefreshedEvent: This occasion is posted when the ApplicationContext is both initialized or refreshed. This can also be raised the usage of the refresh() technique on the ConfigurableApplicationContext interface.

ContextStartedEvent: This event is posted while the ApplicationContext is began using the start() approach at the ConfigurableApplicationContext interface. You can ballot  your database or you can re/start any stopped utility after receiving this occasion.

ContextStoppedEvent: This occasion is published whilst the ApplicationContext is stopped the usage of the prevent() approach on the ConfigurableApplicationContext interface. You can do required housekeep work after receiving this event.

ContextClosedEvent: This event is published when the ApplicationContext is closed the usage of the close() approach at the ConfigurableApplicationContext interface. A closed context reaches its give up of lifestyles; it can not be refreshed or restarted.

RequestHandledEvent: This is a web-particular event telling all be that an HTTP request has been serviced.

Q15. What Is Dependency Injection?

Inversion of Control (IoC) is a general idea, and it may be expressed in many extraordinary approaches and Dependency Injection is simply one concrete instance of Inversion of Control.

This concept says that you do now not create your items but describe how they should be created. You don't immediately join your components and offerings together in code but describe which offerings are wanted by which components in a configuration document. A box (the IOC box) is then accountable for hooking it all up.

Q16. What Is Join Point?

This represents a factor to your software wherein you can plug-in AOP component. You also can say, it is the real region in the utility where an motion could be taken the usage of Spring AOP framework.

Q17. What Are Benefits Of Using Spring?

Following is the list of few of the first rate benefits of the use of Spring Framework:

Lightweight: Spring is light-weight in relation to length and trparency. The basic model of spring framework is around 2MB.

Inversion of manage (IOC): Loose coupling is carried out in spring the use of the approach Inversion of Control. The objects supply their dependencies instead of developing or searching out established objects.

Aspect oriented (AOP): Spring helps Aspect oriented programming and allows cohesive development with the aid of isolating utility commercial enterprise logic from device services.

Container: Spring incorporates and manages the existence cycle and configuration of application gadgets.

MVC Framework: Spring's internet framework is a properly-designed net MVC framework, which gives a brilliant opportunity to internet frameworks which includes Struts or other over engineered or much less popular internet frameworks.

Traction Management: Spring gives a steady traction management interface that may reduce to a local traction (the use of a unmarried database, as an example) and scale as much as global tractions (using JTA, for instance).

Exception Handling: Spring offers a convenient API to trlate technology-precise exceptions (thrown through JDBC, Hibernate, or JDO, as an example) into regular, unchecked exceptions.

Q18. What Are Types Of Ioc Containers? Explain Them.

There are two forms of IoC containers:

Bean Factory field: This is the simplest container providing primary help for DI .The BeanFactory is typically desired wherein the sources are restricted like cell gadgets or applet based applications

Spring ApplicationContext Container: This box adds extra business enterprise-particular capability inclusive of the capability to remedy textual messages from a houses record and the potential to put up application events to fascinated occasion listeners.

Q19. What Is Webapplicationcontext ?

The WebApplicationContext is an extension of the plain ApplicationContext that has some greater functions important for internet packages. It differs from a regular ApplicationContext in that it's far capable of resolving issues, and that it is aware of which servlet it is associated with.

Q20. Explain Requestmapping Annotation.?

RequestMapping annotation is used to map a URL to either an entire elegance or a specific handler method.

Q21. What Is Default Scope Of Bean In Spring Framework?

The default scope of bean is Singleton for Spring framework.

Q22. What Is Introduction?

An introduction lets in you to add new methods or attributes to existing lessons.

Q23. What Does

This annotation truly indicates that the affected bean assets should be populated at configuration time, thru an specific belongings cost in a bean definition or through autowiring. The field throws BeanInitializationException if the affected bean assets has not been populated.

Q24. What Is Spring Ioc Container?

The Spring IoC creates the gadgets, twine them collectively, configure them, and control their entire lifecycle from creation until destruction. The Spring field makes use of dependency injection (DI) to manage the additives that make up an application.

Q25. What Are The Types Of Advice?

Spring aspects can work with 5 forms of advice stated underneath:

before: Run recommendation before the a method execution.

After: Run recommendation after the a way execution regardless of its final results.

After-returning: Run advice after the a way execution handiest if technique completes effectively.

After-throwing: Run advice after the a technique execution best if method exits through throwing an exception.

Round: Run recommendation earlier than and after the advised method is invoked.

Q26. What Is Spring Mvc Framework?

The Spring internet MVC framework provides version-view-controller architecture and equipped components that can be used to expand bendy and loosely coupled web applications.

The MVC pattern results in setting apart the extraordinary elements of the application (enter good judgment, enterprise common sense, and UI good judgment), while supplying a free coupling between these elements.

Q27. What Are Inner Be In Spring?

A <bean/> element within the <property/> or <constructor-arg/> factors defines a so-referred to as inner bean. An internal bean definition does now not require a described identification or call; the container ignores these values. It also ignores the scope flag. Inner be are continually nameless and they are always scoped as prototypes.

Q28. Give An Example Of Beanfactory Implementation.?

The maximum normally used BeanFactory implementation is the XmlBeanFactory class. This field reads the configuration metadata from an XML report and uses it to create a completely configured machine or software.

Q29. What Is Annotation-based totally Container Configuration?

An opportunity to XML setups is supplied by way of annotation-based configuration which is based on the bytecode metadata for wiring up additives in place of attitude-bracket declarations. Instead of using XML to describe a bean wiring, the developer moves the configuration into the thing elegance itself via using annotations on the applicable magnificence, method, or subject announcement.

Q30. What Are The Jsr-250 Annotations? Explain Them.?

Spring has JSR-250 primarily based annotations which include @PostConstruct, @PreDestroy and @Resource annotations.

@PostConstruct: This annotation can be used as an change of initialization callback.

@PreDestroy: This annotation can be used as an exchange of destruction callback.

@Resource : This annotation can be used on fields or setter methods. The @Resource annotation takes a 'name' attribute so one can be interpreted because the bean call to be injected. You can say, it follows by way of-name autowiring semantics.

Q31. Are Singleton Be Thread Safe In Spring Framework?

No, singleton be are not thread-secure in Spring framework.

Q32. What Is Spring Configuration File?

Spring configuration report is an XML document. This document carries the lessons statistics and describes how those instructions are configured and delivered to each other.

Q33. What Does A Bean Definition Contain?

The bean definition contains the facts called configuration metadata which is needed for the field to realize the followings:

How to create a bean

Bean's lifecycle info

Bean's dependencies

Q34. How Jdbctemplate Can Be Used?

With use of Spring JDBC framework the weight of aid control and mistakes dealing with is reduced lots. So it leaves builders to write down the statements and queries to get the information to and from the database.

JdbcTemplate provides many comfort techniques for doing things which includes changing database records into primitives or objects, executing organized and callable statements, and imparting custom database errors managing.

Q35. What Is Weaving?

Weaving is the manner of linking components with different utility kinds or objects to create an cautioned item.

Q36. How Jdbc Can Be Used More Efficiently In Spring Framework?

JDBC can be used more efficiently with the help of a template class provided via spring framework referred to as as JdbcTemplate.

Q37. How Do You Turn On Annotation Wiring?

Annotation wiring is not grew to become on within the Spring container by default. So, earlier than we can use annotation-based totally wiring, we can need to enable it in our Spring configuration record by using configuring <context:annotation-config/>.

Q38. What Are The Types Of The Traction Management Spring Supports?

Spring helps  forms of traction management:

Programmatic traction control: This me which you have controlled the traction with the assist of programming. That offers you intense flexibility, but it is tough to preserve.

Declarative traction control: This me you separate traction management from the commercial enterprise code. You best use annotations or XML primarily based configuration to manage the tractions.

Q39. What Are Spring Be?

The gadgets that shape the spine of your application and which are managed through the Spring IoC container are referred to as be. A bean is an object this is instantiated, assembled, and otherwise managed by means of a Spring IoC box. These be are created with the configuration metadata which you deliver to the field, for instance, inside the form of XML <bean/> definitions.

Q40. What Are The Ways To Access Hibernate By Using Spring?

There are two approaches to access hibernate the use of spring:

Inversion of Control with a Hibernate Template and Callback.

Extending HibernateDAOSupport and Applying an AOP Interceptor node.

Q41. What Is A Dispatcherservlet?

The Spring Web MVC framework is designed round a DispatcherServlet that handles all of the HTTP requests and responses.

Q42. What Are The Different Modules In Spring Framework?

Following are the modules of the Spring framework:

Core module

Bean module

Context module

Expression Language module

JDBC module

ORM module

OXM module

Java Messaging Service(JMS) module

Traction module

Web module

Web-Servlet module

Web-Struts module

Web-Portlet module

Q43. Explain The

The @Controller annotation suggests that a selected magnificence serves the function of a controller. Spring does no longer require you to increase any controller base magnificence or reference the Servlet API.

Q44. Which Di Would You Suggest Constructor-based Or Setter-based totally Di?

Since you may blend each, Constructor- and Setter-primarily based DI, it is a great rule of thumb to use constructor arguments for mandatory dependencies and setters for non-obligatory dependencies. Note that the use of a @Required annotation on a setter can be used to make setters required dependencies.

Q45. What Are Different Modes Of Auto Wiring?

The autowiring capability has 5 modes which may be used to teach Spring box to use autowiring for dependency injection:

no: This is default putting which me no autowiring and also you ought to use specific bean reference for wiring. You don't have anything to do special for this wiring. This is what you have already got seen in Dependency Injection bankruptcy.

ByName: Autowiring through property name. Spring box appears on the homes of the be on which autowire attribute is set to byName in the XML configuration document. It then tries to in shape and wire its properties with the be defined by the identical names in the configuration document.

ByType: Autowiring by way of property datatype. Spring field seems at the houses of the be on which autowire attribute is ready to byType inside the XML configuration document. It then tries to fit and twine a property if its type matches with exactly one of the be call in configuration file. If a couple of such be exist, a deadly exception is thrown.

Constructor: Similar to byType, however type applies to constructor arguments. If there isn't always precisely one bean of the constructor argument kind within the box, a deadly error is raised.

Autodetect: Spring first tries to wire the usage of autowire through constructor, if it does no longer work, Spring tries to autowire via byType.

Q46. What Are Orm's Spring Supports ?

Spring helps the subsequent ORM's :

Hibernate

iBatis

JPA (Java Persistence API)

TopLink

JDO (Java Data Objects)

OJB

Q47. How Do Add A Bean In Spring Application?

Check the following instance:

<?Xml version="1.0" encoding="UTF-8"?>

<be xmlns="http://www.Springframework.Org/schema/be"

    xmlns:xsi="http://www.W3.Org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.Springframework.Org/schema/be

    http://www.Springframework.Org/schema/be/spring-be.Xsd">

   <bean id="helloWorld" class="com.Tutorialspoint.HelloWorld">

       <property name="message" value="Hello World!"/>

   </bean>

</be>

Q48. What Is Spring?

Spring is an open source improvement framework for corporation Java. The middle features of the Spring Framework can be used in developing any Java application, however there are extensions for constructing web programs on pinnacle of the Java EE platform. Spring framework goals to make J2EE development less complicated to apply and promote proper programming exercise through permitting a POJO-based totally programming model.

Q49. What Are The Limitations With Autowiring?

Limitations of autowiring are:

Overriding opportunity: You can still specify dependencies using <constructor-arg> and <property> settings on the way to always override autowiring.

Primitive information types: You can not autowire so-called simple properties consisting of primitives, Strings, and Classes.

Confusing nature: Autowiring is much less genuine than specific wiring, so if viable opt for using express wiring.

Q50. What Is Pointcut?

This is a hard and fast of 1 or more joinpoints where an advice have to be done. You can specify pointcuts the usage of expressions or patterns as we are able to see in our AOP examples.




CFG