A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Java Spring Interview Question for Experienced(1-4years)

Bootstrap Example
Java Spring Interview Question: for Experienced(1-4years)

1. What is Spring Framework?

It’s java j2ee most important framework that is mostly used by the software industry. The core concept of spring framework is dependency injection and aspect-oriented programming.

Spring Framework can be used to achieve loose coupling in normal java application by implementing dependency injection and can perform cross cutting tasks such as logging, transaction and authentication using support for aspect-oriented-programming.

How do we implement DI in Spring Framework?

Using spring xml configuration as well as annotation based configuration to implement DI in spring applications.

2. What Spring Core Container ?
Ans: Core , beans, Context and EL modules are Spring core container.

3. what are contexts in Spring Framework?
Java Spring Framework supports I18N(internationalization), EJB, Basic remoting and JMS.

4. What are core and Beans in Spring Framework?
IOC and DI(Dependency Injection) features are provided by core and beans features.

5. What is IOC Containers?
--> IOC container is responsive to provide object intantiation, configuration and assembling.

Spring provides two containers:-
1. Basic Spring container--known as "BeanFactory"
2. Advanced Spring container--known as "ApplicationContext"

How to create object of "BeanFactory" container ?

//Resource  res_obj = new ClassPathResource("applicationcontext.xml");
//BeanFactory myfactoryobj=new XmlBeanFactory(res_obj);

How to create object of "ApplicationContext" container?
//AppletContext mycontext = new ClassPathXmlApplicationContext("applicationcontext.xml");

6. What is dependency Injection in Spring ?

dependency Injection is a design pattern that removes dependency from programming code.

benefits are in managing the application and in testing.

Dependency lookup:-
Its an approach in which user gets resource after demand.
there are multiple ways to design it.

A obj = new AImpl(); //we get resource directly by new keyword

B obj = B.getB(); //we get the resource by calling a static factory method.
What was the problems in dependency lookup?

tight coupling:-
In the dependency lookup approach, if resource is changed, we have to perform a lots of modification in existing codes, so that this approach provides makes the code tightly coupled.

Not easy to test:-
This approach provides various problems in black box testing.


public class Address {

    String cityName;
    String StateName;
    //other stufffs

public class Student
    Address address;
    public Address getAddress() {
        return address;
    public void setAddress(Address address) {
        this.address = address;
    Student(Address address)

Question: How many ways to perform dependency Injection in Spring Framework?
Ans:  There are two ways to inject dependency.
1. By Constructor
    Student(Address address)
2. By Setter method

    public void setAddress(Address address) {
        this.address = address;

Dependency Injection by Constructor :-
injecting dependency by constructor, we have to add <constructor-arg> tag in <bean> tag.
Here, we can inject primitive, String values and dependent object and collection values.
Dependency Injection by setter method:-
<property> tag in <bean> is used for setter method.
Here, we can inject primitive, String values and dependent object and collection values.