Skip to main content

SpringIOC


Spring IOC Container
========================================
-> The Spring container is at the core of the Spring Framework.
-> The container will create the objects, wire them together, configure them and manage their complete lifecycle from creation till destruction.
-> IOC Container that contains beans and their configurations to develop mutiple types of applications. Such as standard applications, web applications,
    and enterprise applications.
-> IOC Container says that you don't bother about object creation or you don't create your objects only describe how they should be created.
-> IOC Container also says you don't directly connect your components and services together in code but only describe which services are needed by which components in a configuration file.

Benefits of IOC Container:
=========================
-> Minimize the amount of code in our application.
-> Provides Loose coupling between components in application.
-> If any modification have to do then it doesn't affect other components.
-> There are two ways of defining IOC Container:
1. BeanFactory Container
2. ApplicationContext Container

BeanFactory Container
-----------------------------------
-> A BeanFactory is like a factory class that contains a collection of beans.
-> The BeanFactory holds Beans definitions of multiple beans within itself and then instantiates the bean whenever asked for by clients.
-> If we are developing small scale applications likes mobile applications, Embedded System applications then we use BeanFactory because few extra KBs are also matters towards application size.
-> There are several implementation of BeanFactory. The most useful one is "XmlBeanFactory".
                           eg:  BeanFactory factory=new XmlBeanFactory(new FileInputStream("mybean.xml"));

ApplicationContext Container
--------------------------------------
-> A BeanFactory is fine to simple applications but to take advantage of the full power of the Spring framework, we may want to move up to Spring's  more advanced container, the ApplicationContext.
-> If we are developing enterprise applications (like web applications, distributed applications) then use ApplicationContext container.
-> Both are same but it has some extra advantage: For example:
     1. Support Internationalization or I18n.
     2. Publish or processing events to beans and event handling.
     3. Ability to work with Properties file.
     4. Pre-instantiation of singleton spring bean.
     5. Supports Automatic registration of bean post processor.
     6. Provides to stop or close the container.

The Three implementation of ApplicationContext are:
    1. ClassPathXmlApplicationContext                eg: ApplicationContext ctx=new ClassPathXmlApplicationContext("bean.xml");
    2. FileSystemXmlApplicationContext          eg: ApplicationContext ctx=new FileSystemXmlApplicationContext("bean.xml");
    3. XmlWebApplicationContext                         

Comments

Popular posts from this blog

Mockito interview Questions

1.       Question 1. What Is Mockito? Answer : Mockito allows creation of mock object for the purpose of Test Driven Development and Behavior Driven development. Unlike creating actual object, Mockito allows creation of fake object (external dependencies) which allows it to give consistent results to a given invocation. 2.       Question 2. Why Do We Need Mockito? What Are The Advantages? Answer : Mockito differentiates itself from the other testing framework by removing the expectation beforehand. So, by doing this, it reduces the coupling. Most of the testing framework works on the "expect-run-verify". Mockito allows it to make it "run-verify" framework. Mockito also provides annotation which allows to reduce the boilerplate code. 3.       Question 3. Can You Explain A Mockito Framework? Answer : In Mockito, you always check a particular class. The dependency in that class is injected using m...

JAVA Expert Interview Questions Answers 2017

Java Basics ::  Interview Questions and Answers Home  »  Interview Questions  »  Technical Interview  »  Java Basics  » Interview Questions 1.     What is the difference between a constructor and a method? A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator. A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator. 2.     What is the purpose of garbage collection in Java, and when is it used? The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used. 3.  ...

Java Collections Interview Questions and Answers

Beginner Level (0-1 yr): Java Collections Interview Questions  and Answers Q1  What is Collection ? What is a Collections Framework ? What are the benefits of Java Collections Framework ? Collection :  A collection (also called as container) is an object  that groups multiple elements into a single unit. Collections Framework :  Collections framework provides unified architecture for manipulating and representing collections. Benefits of Collections Framework : 1. Improves program quality and speed 2. Increases the chances of reusability of software 3. Decreases programming effort. Q2 What is the root interface in collection hierarchy ?  Root interface in collection hierarchy is  Collection interface .  Few interviewer may argue that  Collection interface extends  Iterable interface . So iterable should be the root interface. But you should reply iterable interface present in java.lang package not in java.util package .It is clearly men...