Question 1. What Is Spring?
Spring is an open source development framework for enterprise Java. The center capabilities of the Spring Framework may be utilized in growing any Java software, however there are extensions for building net packages on top of the Java EE platform. Spring framework objectives to make J2EE development simpler to use and promote appropriate programming practice via permitting a POJO-based totally programming model.
Question 2. What Are Benefits Of Using Spring?
Following is the listing of few of the brilliant blessings of the use of Spring Framework:
Lightweight: Spring is light-weight on the subject of size and transparency. The simple model of spring framework is around 2MB.
Inversion of manipulate (IOC): Loose coupling is finished in spring the use of the approach Inversion of Control. The items give their dependencies in place of growing or looking for established gadgets.
Aspect oriented (AOP): Spring helps Aspect orientated programming and enables cohesive development with the aid of isolating application business common sense from gadget offerings.
Container: Spring contains and manages the life cycle and configuration of utility items.
MVC Framework: Spring's net framework is a nicely-designed internet MVC framework, which presents a amazing alternative to web frameworks which include Struts or other over engineered or much less famous net frameworks.
Transaction Management: Spring offers a consistent transaction control interface which could reduce to a local transaction (the usage of a unmarried database, as an instance) and scale up to global transactions (the usage of JTA, for instance).
Exception Handling: Spring presents a convenient API to translate era-precise exceptions (thrown by means of JDBC, Hibernate, or JDO, for example) into constant, unchecked exceptions.
Adv Java Interview Questions
Question three. What Are The Different Modules In Spring Framework?
Following are the modules of the Spring framework:
Expression Language module
Java Messaging Service(JMS) module
Question 4. What Is Spring Configuration File?
Spring configuration document is an XML document. This report includes the instructions statistics and describes how those classes are configured and brought to every different.
Adv Java Tutorial
Question 5. What Is Dependency Injection?
Inversion of Control (IoC) is a wellknown idea, and it is able to be expressed in many exceptional approaches and Dependency Injection is merely one concrete example of Inversion of Control.
This idea says which you do now not create your objects however describe how they should be created. You do not immediately connect your additives and offerings together in code however describe which offerings are wanted by means of which components in a configuration file. A field (the IOC container) is then accountable for hooking all of it up.
J2EE Interview Questions
Question 6. What Are The Different Types Of Ioc (dependency Injection)?
Types of IoC are:
Constructor-primarily based dependency injection: Constructor-based DI is completed whilst the box invokes a category constructor with a number of arguments, each representing a dependency on other class.
Setter-primarily based dependency injection: Setter-based DI is performed with the aid of the container calling setter strategies on your beans after invoking a no-argument constructor or no-argument static factory approach to instantiate your bean.
Question 7. Which Di Would You Suggest Constructor-based totally Or Setter-based totally Di?
Since you could blend both, Constructor- and Setter-based DI, it is a superb rule of thumb to use constructor arguments for mandatory dependencies and setters for non-compulsory dependencies. Note that the usage of a @Required annotation on a setter can be used to make setters required dependencies.
J2EE Tutorial Core Java Interview Questions
Question eight. What Are The Benefits Of Ioc?
The fundamental advantages of IOC or dependency injection are:
It minimizes the quantity of code on your application.
It makes your utility clean to check as it would not require any singletons or JNDI research mechanisms for your unit check instances.
Loose coupling is promoted with minimum effort and least intrusive mechanism.
IOC bins aid eager instantiation and lazy loading of services.
Question nine. What Is Aop?
Aspect-orientated programming, or AOP, is a programming approach that allows programmers to modularize crosscutting worries, or conduct that cuts across the everyday divisions of responsibility, together with logging and transaction management. The core construct of AOP is the thing, which encapsulates behaviors affecting multiple classes into reusable modules.
JSP Interview Questions
Question 10. What Is Spring Ioc Container?
The Spring IoC creates the gadgets, wire them together, configure them, and manipulate their entire lifecycle from creation till destruction. The Spring box uses dependency injection (DI) to control the components that make up an application.
Core Java Tutorial
Question 11. What Are Types Of Ioc Containers? Explain Them.
There are two varieties of IoC containers:
Bean Factory field: This is the only box supplying basic guide for DI .The BeanFactory is normally preferred in which the assets are restrained like cellular gadgets or applet primarily based programs
Spring ApplicationContext Container: This box adds more company-unique capability such as the ability to clear up textual messages from a houses document and the capability to submit software activities to involved event listeners.
Java-Springs Interview Questions
Question 12. Give An Example Of Beanfactory Implementation.?
The most commonly used BeanFactory implementation is the XmlBeanFactory magnificence. This field reads the configuration metadata from an XML record and uses it to create a completely configured gadget or application.
Adv Java Interview Questions
Question thirteen. What Are The Common Implementations Of The Applicationcontext?
The 3 typically used implementation of 'Application Context' are:
FileSystemXmlApplicationContext: This box loads the definitions of the beans from an XML document. Here you need to offer the entire course of the XML bean configuration document to the constructor.
ClassPathXmlApplicationContext: This field masses the definitions of the beans from an XML record. Here you do no longer need to offer the overall direction of the XML report but you need to set CLASSPATH well because this field will look bean configuration XML file in CLASSPATH.
WebXmlApplicationContext: This container masses the XML document with definitions of all beans from within an internet software.
Question 14. What Is The Difference Between Bean Factory And Applicationcontext?
Following are some of the differences:
Application contexts provide a method for resolving textual content messages, such as help for i18n of these messages.
Application contexts provide a conventional way to load document assets, such as pictures.
Application contexts can publish events to beans which might be registered as listeners.
Certain operations at the box or beans within the box, which should be dealt with in a programmatic style with a bean manufacturing facility, may be handled declaratively in an software context.
The utility context implements MessageSource, an interface used to achieve localized messages, with the real implementation being pluggable.
Question 15. What Are Spring Beans?
The items that shape the spine of your application and which are managed with the aid of the Spring IoC container are called beans. A bean is an object this is instantiated, assembled, and otherwise managed by way of a Spring IoC box. These beans are created with the configuration metadata that you deliver to the box, as an example, within the shape of XML <bean/> definitions.
JMS(Java Message Service) Interview Questions
Question sixteen. What Does A Bean Definition Contain?
The bean definition incorporates the records called configuration metadata which is needed for the box to recognise the followings:
How to create a bean
Bean's lifecycle info
Question 17. How Do You Provide Configuration Metadata To The Spring Container?
There are following 3 essential techniques to provide configuration metadata to the Spring Container:
XML based configuration report.
Java-based totally configuration
Java applet Interview Questions
Question 18. How Do Add A Bean In Spring Application?
Check the subsequent instance:
<?Xml version="1.0" encoding="UTF-8"?>
<bean id="helloWorld" class="com.Tutorialspoint.HelloWorld">
<property name="message" value="Hello World!"/>
J2EE Interview Questions
Question 19. How Do You Define A Bean Scope?
When defining a <bean> in Spring, you have the option of maintaining a scope for that bean. For example, to pressure Spring to provide a new bean example whenever one is needed, you ought to declare the bean's scope attribute to be prototype. Similar manner if you need Spring to go back the identical bean example on every occasion one is needed, you should declare the bean's scope attribute to be singleton.
Question 20. What Bean Scopes Does Spring Support? Explain Them.?
The Spring Framework supports following 5 scopes, 3 of which are available only in case you use an internet-aware ApplicationContext.
Singleton: This scopes the bean definition to a unmarried example consistent with Spring IoC box.
Prototype: This scopes a single bean definition to have any quantity of item instances.
Request: This scopes a bean definition to an HTTP request. Only legitimate within the context of a web-conscious Spring ApplicationContext.
Consultation: This scopes a bean definition to an HTTP session. Only legitimate in the context of a web-conscious Spring ApplicationContext.
Global-session: This scopes a bean definition to a worldwide HTTP consultation. Only valid inside the context of an internet-aware Spring ApplicationContext.
Java Interview Questions
Question 21. What Is Default Scope Of Bean In Spring Framework?
The default scope of bean is Singleton for Spring framework.
Question 22. Are Singleton Beans Thread Safe In Spring Framework?
No, singleton beans are not thread-safe in Spring framework.
Java eight Tutorial
Question 23. Explain Bean Life Cycle In Spring Framework?
Following is collection of a bean lifecycle in Spring:
Instantiate - First the spring box finds the bean's definition from the XML file and instantiates the bean..
Populate residences - Using the dependency injection, spring populates all the residences as particular in the bean definition..
Set Bean Name - If the bean implements BeanNameAware interface, spring passes the bean's identification to setBeanName() method.
Set Bean manufacturing unit - 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 related to the bean, Spring calls postProcesserBeforeInitialization() method.
Initialize beans - If the bean implements IntializingBean,its afterPropertySet() technique is called. If the bean has init technique announcement, the required initialization method is called.
Post Initialization - If there are any BeanPostProcessors related to the bean, their postProcessAfterInitialization() strategies might be called.
Ready to use - Now the bean is prepared to apply via the application.
Destroy - If the bean implements DisposableBean , it'll name the damage() technique .
Java 8 Interview Questions
Question 24. What Are Inner Beans In Spring?
A <bean/> detail in the <property/> or <constructor-arg/> elements defines a so-referred to as inner bean. An inner bean definition does no longer require a defined identity or call; the box ignores those values. It also ignores the scope flag. Inner beans are always anonymous and they may be usually scoped as prototypes.
Core Java Interview Questions
Question 25. How Can You Inject Java Collection In Spring?
Spring offers four varieties of collection configuration factors that are as follows:
<list>: This allows in wiring i.E. Injecting a list of values, allowing duplicates.
<set>: This allows in wiring a fixed of values but with none duplicates.
<map>: This can be used to inject a collection of name-price pairs in which name and price can be of any kind.
<props>: This can be used to inject a set of call-value pairs in which the call and value are each Strings.
Question 26. What Is Bean Auto Wiring?
The Spring field is able to autowire relationships among participating beans. This method that it is possible to routinely allow Spring resolve collaborators (different beans) for your bean by examining the contents of the BeanFactory without using <constructor-arg> and <property> elements.
Java Programmer Interview Questions
Question 27. What Are Different Modes Of Auto Wiring?
The autowiring capability has 5 modes which can be used to train Spring container to use autowiring for dependency injection:
no: This is default putting because of this no autowiring and also you must use express bean reference for wiring. You don't have anything to do unique for this wiring. This is what you have already got visible in Dependency Injection chapter.
ByName: Autowiring with the aid of assets call. Spring box appears on the houses of the beans on which autowire characteristic is set to byName inside the XML configuration report. It then attempts to match and cord its homes with the beans described by means of the same names inside the configuration record.
ByType: Autowiring by means of assets datatype. Spring field seems at the houses of the beans on which autowire characteristic is set to byType inside the XML configuration document. It then attempts to match and cord a assets if its kind suits with precisely one of the beans name in configuration record. If a couple of such beans exist, a deadly exception is thrown.
Constructor: Similar to byType, but kind applies to constructor arguments. If there is not precisely one bean of the constructor argument type within the container, a fatal mistakes is raised.
Autodetect: Spring first attempts to cord the use of autowire through constructor, if it does not work, Spring tries to autowire by way of byType.
JSP Interview Questions
Question 28. What Are The Limitations With Autowiring?
Limitations of autowiring are:
Overriding opportunity: You can still specify dependencies the usage of <constructor-arg> and <property> settings on the way to continually override autowiring.
Primitive records sorts: You can't autowire so-referred to as simple houses which include primitives, Strings, and Classes.
Confusing nature: Autowiring is less precise than explicit wiring, so if viable pick the use of express wiring.
Question 29. Can You Inject Null And Empty String Values In Spring?
Question 30. What Is Annotation-primarily based Container Configuration?
An alternative to XML setups is provided with the aid of annotation-based configuration which relies on the bytecode metadata for wiring up components instead of perspective-bracket declarations. Instead of the use of XML to describe a bean wiring, the developer movements the configuration into the aspect magnificence itself via the usage of annotations at the relevant magnificence, method, or discipline assertion.
Question 31. How Do You Turn On Annotation Wiring?
Annotation wiring isn't grew to become on within the Spring container via default. So, earlier than we are able to use annotation-based totally wiring, we are able to need to enable it in our Spring configuration report via configuring <context:annotation-config/>.
Question 32. What Does @required Annotation Mean?
This annotation sincerely indicates that the affected bean assets ought to be populated at configuration time, via an specific assets fee in a bean definition or thru autowiring. The container throws BeanInitializationException if the affected bean belongings has now not been populated.
Question 33. What Does @autowired Annotation Mean?
This annotation affords more pleasant-grained manipulate over where and how autowiring have to be completed. The @Autowired annotation may be used to autowire bean at the setter technique just like @Required annotation, constructor, a assets or strategies with arbitrary names and/or a couple of arguments.
Java-Springs Interview Questions
Question 34. What Does @qualifier Annotation Mean?
There may be a scenario when you create more than one bean of the identical type and want to wire only considered one of them with a belongings, in such case you may use @Qualifier annotation along side @Autowired to take away the confusion by means of specifying which genuine bean could be wired.
Question 35. What Are The Jsr-250 Annotations? Explain Them.?
Spring has JSR-250 based totally annotations which include @PostConstruct, @PreDestroy and @Resource annotations.
@PostConstruct: This annotation may be used as an trade of initialization callback.
@PreDestroy: This annotation may be used as an trade of destruction callback.
@Resource : This annotation can be used on fields or setter methods. The @Resource annotation takes a 'name' characteristic so one can be interpreted because the bean call to be injected. You can say, it follows by means of-call autowiring semantics.
Question 36. What Is Spring Java Based Configuration? Give Some Annotation Example.?
Java based totally configuration alternative allows you to put in writing most of your Spring configuration without XML however with the help of few Java-based totally annotations.
For example: Annotation @Configuration suggests that the elegance may be utilized by the Spring IoC container as a supply of bean definitions. The @Bean annotation tells Spring that a technique annotated with @Bean will go back an object that must be registered as a bean inside the Spring application context.
JMS(Java Message Service) Interview Questions
Question 37. How Is Event Handling Done In Spring?
Event coping with within the ApplicationContext is furnished via the ApplicationEvent elegance and ApplicationListener interface. So if a bean implements the ApplicationListener, then on every occasion an ApplicationEvent gets posted to the ApplicationContext, that bean is notified.
Question 38. Describe Some Of The Standard Spring Events.?
Spring provides the subsequent preferred occasions:
ContextRefreshedEvent: This occasion is posted when the ApplicationContext is either initialized or refreshed. This also can be raised using the refresh() method at the ConfigurableApplicationContext interface.
ContextStartedEvent: This occasion is published while the ApplicationContext is started out the use of the begin() approach at the ConfigurableApplicationContext interface. You can poll your database or you may re/begin any stopped software after receiving this occasion.
ContextStoppedEvent: This occasion is published while the ApplicationContext is stopped the use of the prevent() technique at the ConfigurableApplicationContext interface. You can do required housekeep paintings after receiving this event.
ContextClosedEvent: This occasion is posted when the ApplicationContext is closed the use of the near() approach on the ConfigurableApplicationContext interface. A closed context reaches its quit of life; it can't be refreshed or restarted.
RequestHandledEvent: This is an internet-precise occasion telling all beans that an HTTP request has been serviced.
Question 39. What Is Aspect?
A module which has a hard and fast of APIs supplying move-reducing necessities. For example, a logging module could be known as AOP component for logging. An software could have any number of elements relying at the requirement. In Spring AOP, components are carried out the use of everyday instructions (the schema-based technique) or ordinary instructions annotated with the @Aspect annotation (@AspectJ style).
Question 40. What Is The Difference Between Concern And Cross-reducing Concern In Spring Aop?
Concern: Concern is conduct which we want to have in a module of an utility. Concern may be defined as a capability we need to enforce. Issues in which we are involved outline our concerns.
Cross-slicing issue: It's a difficulty which is applicable at some point of the utility and it impacts the entire utility. E.G. Logging , safety and statistics switch are the issues which can be wished in nearly each module of an software, therefore are move-slicing worries.
Java applet Interview Questions
Question forty one. What Is Join Point?
This represents a factor on your application in which you may plug-in AOP element. You can also say, it's miles the real area within the utility in which an motion can be taken the usage of Spring AOP framework.
Question 42. What Is Advice?
This is the real movement to be taken both earlier than or after the method execution. This is actual piece of code that is invoked throughout software execution via Spring AOP framework.
Java Interview Questions
Question forty three. What Is Pointcut?
This is a fixed of 1 or extra joinpoints where an recommendation must be achieved. You can specify pointcuts using expressions or styles as we will see in our AOP examples.
Question forty four. What Is Introduction?
An creation lets in you to add new techniques or attributes to existing classes.
Question 45. What Is Target Object?
The object being recommended by way of one or greater elements, this object will always be a proxy object. Also known as the counseled item.
Question forty six. What Is Weaving?
Weaving is the procedure of linking components with different software kinds or gadgets to create an cautioned object.
Question forty seven. What Are The Different Points Where Weaving Can Be Applied?
Weaving may be accomplished at assemble time, load time, or at runtime.
Question 48. What Are The Types Of Advice?
Spring factors can work with 5 types of recommendation stated underneath:
before: Run recommendation before the a method execution.
After: Run advice after the a way execution regardless of its final results.
After-returning: Run advice after the a technique execution most effective if approach completes efficiently.
After-throwing: Run recommendation after the a method execution handiest if technique exits by means of throwing an exception.
Round: Run advice before and after the suggested technique is invoked.
Question 49. What Is Xml Schema Based Aspectj Implementation?
Aspects are applied using ordinary training in conjunction with XML based configuration.
Question 50. What Is @aspectj? Based Aspect Implementation?
@AspectJ refers to a style of declaring components as regular Java instructions annotated with Java 5 annotations.
Question fifty one. How Jdbc Can Be Used More Efficiently In Spring Framework?
JDBC can be used more correctly with the assist of a template class provided by way of spring framework called as JdbcTemplate.
Question fifty two. How Jdbctemplate Can Be Used?
With use of Spring JDBC framework the weight of aid control and mistakes handling is reduced plenty. So it leaves builders to write the statements and queries to get the information to and from the database.
JdbcTemplate provides many convenience strategies for doing matters which include converting database records into primitives or gadgets, executing organized and callable statements, and offering custom database blunders managing.
Question 53. What Are The Types Of The Transaction Management Spring Supports?
Spring helps varieties of transaction control:
Programmatic transaction control: This way that you have managed the transaction with the assist of programming. That gives you excessive flexibility, but it's far difficult to hold.
Declarative transaction management: This way you separate transaction management from the business code. You handiest use annotations or XML primarily based configuration to manage the transactions.
Question 54. Which Of The Above Transaction Management Type Is Preferable?
Declarative transaction management is most well known over programmatic transaction management though it's miles much less bendy than programmatic transaction control, which lets in you to manipulate transactions via your code.
Question 55. What Is Spring Mvc Framework?
The Spring internet MVC framework offers version-view-controller structure and geared up components that may be used to develop flexible and loosely coupled internet programs.
The MVC pattern consequences in isolating the one of a kind components of the application (enter good judgment, business logic, and UI logic), even as presenting a free coupling among these elements.
Question fifty six. What Is A Dispatcherservlet?
The Spring Web MVC framework is designed around a DispatcherServlet that handles all of the HTTP requests and responses.
Question fifty seven. What Is Webapplicationcontext ?
The WebApplicationContext is an extension of the obvious ApplicationContext that has some greater capabilities important for web applications. It differs from a normal ApplicationContext in that it is capable of resolving topics, and that it is aware of which servlet it is associated with.
Question fifty eight. What Are The Advantages Of Spring Mvc Over Struts Mvc ?
Following are a number of the advantages of Spring MVC over Struts MVC:
Spring's MVC may be very versatile and bendy based on interfaces however Struts forces Actions and Form item into concrete inheritance.
Spring presents both interceptors and controllers, for that reason helps to factor out not unusual conduct to the coping with of many requests.
Spring may be configured with specific view technology like Freemarker, JSP, Tiles, Velocity, XLST and so forth. And also you may create your own custom view mechanism by way of implementing Spring View interface.
In Spring MVC Controllers may be configured using DI (IOC) that makes its testing and integration easy.
Web tier of Spring MVC is easy to test than Struts net tier, due to the avoidance of forced concrete inheritance and explicit dependence of controllers at the dispatcher servlet.
Struts pressure your Controllers to increase a Struts class however Spring does not, there are many comfort Controller implementations that you could pick out to increase.
In Struts, Actions are coupled to the view through defining ActionForwards inside a ActionMapping or globally. SpringMVC has HandlerMapping interface to help this functionality.
With Struts, validation is typically completed (implemented) inside the validate approach of an ActionForm. In SpringMVC, validators are commercial enterprise gadgets which can be NOT depending on the Servlet API which makes these validators to be reused for your enterprise good judgment earlier than persisting a domain item to a database.
Question fifty nine. What Is Controller In Spring Mvc Framework?
Controllers provide get entry to to the software behavior that you typically define thru a provider interface. Controllers interpret person input and remodel it into a version that is represented to the consumer by means of the view. Spring implements a controller in a very summary manner, which permits you to create a extensive form of controllers.
Question 60. Explain The @controller Annotation.?
The @Controller annotation suggests that a particular magnificence serves the function of a controller. Spring does not require you to extend any controller base class or reference the Servlet API.
Question 61. Explain Requestmapping Annotation.?
RequestMapping annotation is used to map a URL to both a whole magnificence or a specific handler approach.
Question 62. What Are The Ways To Access Hibernate By Using Spring?
There are methods to get right of entry to hibernate the use of spring:
Inversion of Control with a Hibernate Template and Callback.
Extending HibernateDAOSupport and Applying an AOP Interceptor node.
Question sixty three. What Are Orm's Spring Supports ?
Spring supports the following ORM's :
JPA (Java Persistence API)
JDO (Java Data Objects)