Q) Why do we need DTD or XSD declaration tags
in the spring XML configuration file?
A) Either we need to declare DTD at the top level or XSD inside beans root tag
· DTD and XSD are used
to validate our XML file.
·
Inside IOC we have SAX
parser which parsers XML file. SAX parser will read and parsers XML file.
·
To parser the XML file
it should be in the well-formed XML file (means having close and end tag) so DTD or
XSD is used to check the XML file in the well-formed file and check the valid file
which is nothing but tags without a declaration.
Q) What is the use of
container in Spring?
A) The container in spring is responsible for reading the XML file
and creating the instances(objects) of
the respective beans in the XML file. The container is responsible for bean life.
Q) How many containers we have in IOC?
A) In IOC, we have mainly two containers
·
Core Container (Bean Factory)
·
J2ee container (Application Context)
Q) what is the difference between
BeanFactory(Core Container) and ApplicationContext(J2EE container) ?
A) Application Context build on the top of
BeanFactoryContainer
·
Bean
Factory will create the object for the first user request. That means it won’t create an object at the time of loading. By default, bean scope is a singleton.
·
Application
Context container will create object while loading itself if the beans scopes
is a singleton.
·
if we change the bean’s scope in Application
Context to prototype. It will not create the objects for the POJO class while loading
the XML file.
·
If
bean scope is equal to the porotype Application context behaves like Bean factory.
It will create each object for each request.
·
BeanFactory will
create an instance(objects) whenever call get bean method but
ApplicationContext creates instance while loading the XML file into the container.
·
By default, the scope of
the bean singleton. If the scope of the bean is singleton the Bean Factory
Container will create an object for the POJO class on-demand that mean when we
call the bean method (get bean) but in case of application context container if
the scope is singleton application context container will create the objects
for the POJO class at the time of loading the XML file.
·
If the scope of the
bean is prototype than both containers creates the objects, the one demand only
and different objects for each user.
·
If we have 10 beans in
my XML documents than bean factory container will create one object when we
called get bean method and that one object will have used for the remaining 9 beans.
so remaining 9 beans have to wait for first one complete so it will take a lot of
time to give a response to all user at a time but in case of application context
if I have 10 beans it will create 10 objects at the time of loading the XML so
if it uses the response to 10 users same time so there is no time delay when the
scope of the of a bean is a singleton.
·
When the bean scope is a prototype in the Application Context Container it will create the instance when a user requested get bean method. In this scenario both containers Bean Factory
and Application Context behaves same
·
In containers when we
called get bean method in IOC container by using class. for name container
creates an object. when class is public
Q) What is a POJO class?
A) POJO Plain Old Java Object. Basically, a
class with attributes and its getters and setters.
Q) Autowired Annotation in spring?
A) Autowired annotation can be implemented in web applications. We can not implement Autowired in standalone application because to access objects inside the static method we need an instance of the class when you use autowired instance is created after loading application context or configuration file.
Q) Autowired Annotation in spring?
A) Autowired annotation can be implemented in web applications. We can not implement Autowired in standalone application because to access objects inside the static method we need an instance of the class when you use autowired instance is created after loading application context or configuration file.