Java Interview Questions -38
1.What is IOC (or Dependency Injection)?
The basic concept of the Inversion of Control pattern (also known as dependency injection) is that you do not create your objects but describe how they should be created. You don’t directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container (in the case of the Spring framework, the IOC container) is then responsible for hooking it all up.
i.e., Applying IoC, objects are given their dependencies at creation time by some external entity that coordinates each object in the system. That is, dependencies are injected into objects. So, IoC means an inversion of responsibility with regard to how an object obtains references to collaborating objects. .
2.What are the different types of IOC (dependency injection) ?
There are three types of dependency injection:
==>Constructor Injection (e.g. Pico container, Spring etc): Dependencies are provided as constructor parameters.
==>Setter Injection (e.g. Spring): Dependencies are assigned through JavaBeans properties (ex: setter methods).
==>Interface Injection (e.g. Avalon): Injection is done through an interface. Note: Spring supports only Constructor and Setter Injection
3.What are the benefits of IOC (Dependency Injection)?
Benefits of IOC (Dependency Injection) are as follows: ·
Minimizes the amount of code in your application. With IOC containers you do not care about how services are created and how you get references to the ones you need. You can also easily add additional services by adding a new constructor or a setter method with little or no extra configuration.
· Make your application more testable by not requiring any singletons or JNDI lookup mechanisms in your unit test cases. IOC containers make unit testing and switching implementations very easy by manually allowing you to inject your own objects into the object under test.
· Loose coupling is promoted with minimal effort and least intrusive mechanism. The factory design pattern is more intrusive because components or services need to be requested explicitly whereas in IOC the dependency is injected into requesting piece of code. Also some containers promote the design to interfaces not to implementations design concept by encouraging managed objects to implement a well-defined service interface of your own.
· IOC containers support eager instantiation and lazy loading of services. Containers also provide support for instantiation of managed objects, cyclical dependencies, life cycles management, and dependency resolution between managed objects etc.
4.What is Spring ?
Spring is an open source framework created to address the complexity of enterprise application development. One of the chief advantages of the Spring framework is its layered architecture, which allows you to be selective about which of its components you use while also providing a cohesive framework for J2EE application development. .
5.What are the advantages of Spring framework?
The advantages of Spring are as follows:
i.Spring has layered architecture. Use what you need and leave you don’t need now.
ii.Spring Enables POJO Programming. There is no behind the scene magic here. POJO
iii.programming enables continuous integration and testability.
iv.Dependency Injection and Inversion of Control Simplifies JDBC
v.Open source and no vendor lock-in. .
6.What are features of Spring ?
Lightweight: spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 1MB. And the processing overhead is also very negligible.
Inversion of control (IOC): Loose coupling is achieved in spring using the technique Inversion of Control. The objects give their dependencies instead of creating or looking for dependent objects.
Aspect oriented (AOP): Spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services.
Container: Spring contains and manages the life cycle and configuration of application objects.
MVC Framework: Spring comes with MVC web application framework, built on core Spring functionality. This framework is highly configurable via strategy interfaces, and accommodates multiple view technologies like JSP, Velocity, Tiles, iText, and POI. But other frameworks can be easily used instead of Spring MVC Framework.
Transaction Management: Spring framework provides a generic abstraction layer for transaction management. This allowing the developer to add the pluggable transaction managers, and making it easy to demarcate transactions without dealing with low-level issues. Spring’s transaction support is not tied to J2EE environments and it can be also used in container less environments.
JDBC Exception Handling: The JDBC abstraction layer of the Spring offers a meaningful exception hierarchy, which simplifies the error handling strategy. Integration with Hibernate, JDO, and iBATIS: Spring provides best Integration services with Hibernate, JDO and iBATIS
7.How many modules are there in Spring? What are they?
Spring comprises of seven modules. They are..
The core container: The core container provides the essential functionality of the Spring framework. A primary component of the core container is the BeanFactory, an implementation of the Factory pattern. The BeanFactory applies the Inversion of Control (IOC) pattern to separate an application’s configuration and dependency specification from the actual application code.
Spring context: The Spring context is a configuration file that provides context information to the Spring framework. The Spring context includes enterprise services such as JNDI, EJB, e-mail, internalization, validation, and scheduling functionality.
Spring AOP: The Spring AOP module integrates aspect-oriented programming functionality directly into the Spring framework, through its configuration management feature. As a result you can easily AOP-enable any object managed by the Spring framework. The Spring AOP module provides transaction management services for objects in any Spring-based application. With Spring AOP you can incorporate declarative transaction management into your applications without relying on EJB components.
Spring DAO: The Spring JDBC DAO abstraction layer offers a meaningful exception hierarchy for managing the exception handling and error messages thrown by different database vendors. The exception hierarchy simplifies error handling and greatly reduces the amount of exception code you need to write, such as opening and closing connections. Spring DAO’s JDBC-oriented exceptions comply to its generic DAO exception hierarchy.
Spring ORM: The Spring framework plugs into several ORM frameworks to provide its Object Relational tool, including JDO, Hibernate, and iBatis SQL Maps. All of these comply to Spring’s generic transaction and DAO exception hierarchies.
Spring Web module: The Web context module builds on top of the application context module, providing contexts for Web-based applications. As a result, the Spring framework supports integration with Jakarta Struts. The Web module also eases the tasks of handling multi-part requests and binding request parameters to domain objects.
Spring MVC framework: The Model-View-Controller (MVC) framework is a full-featured MVC implementation for building Web applications. The MVC framework is highly configurable via strategy interfaces and accommodates numerous view technologies including JSP, Velocity, Tiles, iText, and POI.
8.What are the types of Dependency Injection Spring supports?>
Setter Injection: Setter-based DI is realized by calling setter methods on your beans after invoking a no-argument constructor or no-argument static factory method to instantiate your bean.
Constructor Injection: Constructor-based DI is realized by invoking a constructor with a number of arguments, each representing a collaborator
9.What is Bean Factory ?
A BeanFactory is like a factory class that contains a collection of beans. The BeanFactory holds Bean Definitions of multiple beans within itself and then instantiates the bean whenever asked for by clients.
BeanFactory is able to create associations between collaborating objects as they are instantiated. This removes the burden of configuration from bean itself and the beans client. BeanFactory also takes part in the life cycle of a bean, making calls to custom initialization and destruction methods.
10. What is Application Context?
A bean factory is fine to simple applications, but to take advantage of the full power of the Spring framework, you may want to move up to Springs more advanced container, the application context. On the surface, an application context is same as a bean factory.Both load bean definitions, wire beans together, and dispense beans upon request.
But it also provides: A means for resolving text messages, including support for internationalization. A generic way to load file resources. Events to beans that are registered as listeners.
11. What is the difference between Bean Factory and Application Context
Application contexts provide a means for resolving text messages, including support for i18n of those messages. Application contexts provide a generic way to load file resources,
such as images.Application contexts can publish events to beans that are registered as listeners. Certain operations on the container or beans in the container, which have to be handled in a programmatic fashion with a bean factory,
can be handled declaratively in an application context.ResourceLoader support: Spring’s Resource interface us a flexible generic abstraction for handling low-levelresources. An application context itself is a ResourceLoader, Hence provides an application with access to deployment-specific Resource instances.
MessageSource support: The application context implements MessageSource, an interface used to obtain localized messages, with the actual implementation being pluggable
12.What do you mean by Bean wiring ?
The act of creating associations between application components (beans) within the Spring container is reffered to as Bean wiring.
13.What do you mean by Auto Wiring?
The Spring container is able to autowire relationships between collaborating beans. This means that it is possible to automatically let Spring resolve collaborators (other beans) for your bean by inspecting the contents of the BeanFactory. The autowiring functionality has five modes. · no · byName · byType · constructor · autodirect
14.What is DelegatingVariableResolver?
Spring provides a custom JavaServer Faces VariableResolver implementation that extends the standard Java Server Faces managed beans mechanism which lets you use JSF and Spring together. This variable resolver is called as DelegatingVariableResolver
15.How to integrate Java Server Faces (JSF) with Spring?
JSF and Spring do share some of the same features, most noticeably in the area of IOC services. By declaring JSF managed-beans in the faces-config.xml configuration file, you allow the FacesServlet to instantiate that bean at startup. Your JSF pages have access to these beans and all of their properties.We can integrate JSF and Spring in two ways:
DelegatingVariableResolver: Spring comes with a JSF variable resolver that lets you use JSF and Spring together.
< ?xml version=”1.0″ encoding=”UTF-8 “? >
< ! DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd” >
< faces-config >
< application >
< variable-resolver >
org.springframework.web.jsf.DelegatingVariableResolver < / variable-resolver >
< / application >
< / faces-config >
The DelegatingVariableResolver will first delegate value lookups to the default resolver of the underlying JSF implementation, and then to Spring’s ‘business context’ WebApplicationContext. This allows one to easily inject dependencies into one’s JSF-managed beans.
FacesContextUtils:custom VariableResolver works well when mapping one’s properties to beans in faces-config.xml, but at times one may need to grab a bean explicitly. The FacesContextUtils class makes this easy. It is similar to WebApplicationContextUtils, except that it takes a FacesContext parameter rather than a ServletContext parameter. ApplicationContext ctx = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
16.How to integrate your Struts application with Spring?
To integrate your Struts application with Spring, we have two options:
Configure Spring to manage your Actions as beans, using the ContextLoaderPlugin, and set their dependencies in a Spring context file.
Subclass Spring’s ActionSupport classes and grab your Spring-managed beans explicitly using agetWebApplicationContext()
17.What are the ways to access Hibernate using Spring ?
There are two approaches to Spring’s Hibernate integration:
1.Inversion of Control with a HibernateTemplate and Callback
2.Extending HibernateDaoSupport and Applying an AOP Interceptor nodes.
18.What is AOP? and How the AOP used in Spring?
Aspect-oriented programming, or AOP, is a programming technique that allowsprogrammers to modularize crosscutting concerns, or behavior that cuts across the typical divisions of responsibility, such as logging and transaction management. The core construct of AOP is the aspect, which encapsulates behaviors affecting multiple classes into reusable modules.
AOP is used in the Spring Framework: To provide declarative enterprise services, especially as a replacement for EJB declarative services. The most important such service is declarative transaction management, which builds on the Spring Framework’s transaction abstraction.To allow users to implement custom aspects, complementing their use of OOP with AOP.
19.Explain about the Spring DAO support
The Data Access Object (DAO) support in Spring is aimed at making it easy to work with data access technologies like JDBC, Hibernate or JDO in a consistent way. This allows one to switch between the persistence technologies fairly easily and it also allows one to code without worrying about catching exceptions that are specific to each technology.
20.What is SQLExceptionTranslator ?
SQLExceptionTranslator, is an interface to be implemented by classes that can translate between SQLExceptions and Spring’s own data-access-strategy-agnostic org.springframework.dao.DataAccessException.
21.What’s MVC pattern ?
The main purpose of using MVC pattern is to decouple the GUI from the Data. It also gives the ability to provide multiple views for the same Data. MVC pattern separates objects into three important sections:-
Model: – This section is specially for maintaining data. It is actually where your business logic, querying database, database connection etc. is actually implemented.
Views: – Displaying all or some portion of data, or probably different view of data. View is responsible for look and feel, Sorting, formatting etc.
Controller: – They are event handling section which affects either the model or the view. Controller responds to the mouse or keyboard input to command model and view to change.
Controllers are associated with views. User interaction triggers the events to change the model, which in turn calls some methods of model to update its state to notify other registered views to refresh their display.
Struts are an open source framework for developing JAVA web applications. It extends Java Servlets API and helps developers to adopt MVC architecture. MVC pattern is good but developing the same can be real pain. Using struts it’s a breeze to implement MVC in projects. Struts provide a standard way of implementing MVC.
23.Can you explain the directory structure for a struts folder in brief ?
Below are the folders from point of view of root folder.
META-INF: – This directory has the Meta information.
WEB-INF/classes: – This location has the actual JAVA classes.
WEB-INF/classes/ApplicationResources.properties:- Contains text which application can
use. For instance error messages.
WEB-INF/lib/struts.jar:- Contains the Struts servlet, helper classes, taglib code etc.
WEB-INF/*.tld:- The Struts tag libraries.
WEB-INF/struts-config.xml:- A Struts configuration file.
WEB-INF/web.xml:- Configuration file for the servlet container
Index.jsp:- All JSP files come in the root directory as this one Index.jsp.
24.Can you give an overview of how a struts application flows ?
just to summarize how the execution flows in the struts application.
User makes browser makes a request to the Struts application that is processed by ActionServlet (Controller).ActionServlet (Controller) populates the ActionForm (View) object with HTML JSP form data method.
ActionServlet (Controller) executes the Action object (Controller).Action object uses the model and does the necessary execution and passes the control back to the ActionServletAction (Controller) forwards control to the JSP pages.
JSP pages use model data to generate a response to the browser
25.how do you decide whether you should use session, entity or message driven bean?
Session beans should only implement business logic and work flow.Entity beans are data objects and represent persistent data. They are only responsible to do database activities like add, update and delete
Message-driven beans are used for receiving asynchronous messages from other systems.
26.explain EJBHome and EJBObject in EJB?
Bean Interface:Client uses the Bean interface to communicate with the session bean which resides on the EJB application server. The Bean interface extends the EJBObject interface of the javax.ejb package. This interface has all the methods, functions which the final session bean has.
Home Interface:In order the client gets a reference to the Bean interface it must call the Beans home interface. The Home interface extends EJBHome interface of the javax.ejb package. Home Interface of a bean is responsible for creating the object and giving the reference of the Bean interface.
27.explain the concept of local interfaces ?
Local objects implement local interface rather than using remote interface. Just to have a comparison below are the steps how the local object works. JAVA client calls the local object. Local object does connection pooling, transactions and security. It then passes calls the bean and when bean completes its work it returns the data to the Local object who then passes the same to the end client. You can understand from the above steps we have by passed completely marshalling and de-marshalling. .
28.What are the limitations of using Local object ?
Local object only work if you are calling beans in the same process. Second they marshal data by ref rather than by Val. This may speed up your performance but you need to change semantics for the same. So finally it’s a design and the requirement decision. If you are expecting to call beans remotely then using local object will not work.
29.what is Passivation and Activation in EJB?
When we are dealing with stateful session beans we need to store the client conversation of the bean so that it can be available in client’s next request. But when we talk about server it has limited resources. If the conversation of the bean is large then the server can run out of resource. So in order to preserve resources EJB server swaps this conversational data in memory to hard disk thus allowing memory to be reclaimed. This process of saving the memory data to hard disk is called as “Passivation”. Now when the client comes back the conversational data is again swapped from the hard disk to the bean. This process is called as “Activation”. The container informs the bean that its about to passivate or activate using the “ejbPassivate()” and “ejbActivate()” methods.
30.Can beans who are involved in transaction have “Passivation” process?
31.How does the server decide which beans to passivate and activate ?
Most servers use the (LRU) Last Recently Used time as a strategy. Which mean passivate the beans which have been called recently.
32.In what format is the conversational data written to the disk ?
Bean conversational data is saved in the disk as serialized object. This is possible because “javax.ejb.EnterpriseBean” implements “java.io.Serializable” interface. So during passivation time it converts the bean conversational data to a bit-blob and during activation it just reverses the process.
33.What is Mandatory Dependency for Spring basic Dependency Injection ?
Logging is the Mandatory Dependency for Spring basic Dependency Injection.
34.Which logging framework is used for providing logging support in Spring ?
Jakarta Commons Logging API is used as the mandatory logging dependency in Spring.
35.What are the main Modules present in Spring Core Container ?
Core module, Bean Module, Context Module, Epression Language Module are the modules found in Spring Core Container.
36.What are the modules in Spring Data Access/ Integration layer ?
JDBC Module, ORM Module, OXM Module, JMS Module, Transaction module are the modules found in Spring’s Data Access/Integration layer.
37.What are the modules present in Spring’s Web layer ?
Spring’s Web Module, Web-Servlet module, Web-Struts module, Web-portal module are present in Spring’s web layer.
38.What is the major difference on functionality provided by Spring’s ORM module and OXM module ?
Spring’s ORM module works with Object Relational Mapping tools/frameworkssuch as Hibernate, Oracle TopLink, JDO, JPA, iBatis and many more.While Spring’s OXM module works with Object XML Mapping implementationslike JAXB, Castor and many more.
39.What would be your thought on testing Spring components while using JUnit as testing framework ?
There is a Test module from Spring that supports testing of Spring components with JUnit.
40.Can you be able to use Declarative Transaction Management while not opting for EJB components in the business layer, not even deploying application in Application server?
Yes, one can use Declarative Transaction by using Spring’s Transaction module, but one catch is that it is not supporting transaction management across multiple resources/distributed transaction inremote calls.
41.Can you be able to use Spring’s Transaction module for working with declarative transaction management for a POJO , while using JTA transaction support from the Application Server’s JTA implementation ?
Yes, Spring can be used along with the JTA transaction by using Spring’s Transaction module along with Application Server’s JTAimplementation.
42.Does Spring Framework support Transaction context propagation across remote calls ?
No, Spring Framework doesn’t support Transaction context propagationacross remote calls.
43.What are the basic steps required while using Spring’s Annotation based declarative transaction management along with a POJO/Bean?
Spring’s declarative transaction management can be applied to a POJO or Bean by just declaring @Transactional at class level, interface level, for method defined in the interface and only for public methods from a
class. All @Transactional annotations can have appropriate Element defined as well, like isolation, propagation, noRollbackFor, noRollbackForClassName,
readOnly, rollbackFor, rollbackForClassName, timeout, value etc.and then declaring <PLACE_HOLDER:annotation-driven/> in the applicationContext or equivalent configuration XML file, while PLACE_HOLDER
is the namespace definition that is pointing to the Spring TX XSD file, can be “http://www.springframework.org/schema/tx/spring-tx-3.0.xsd”
44.Why basically there are two different implentation for context loader for a web application deplyed onto a Servlet Container? What are those?
For web application deplyed onto Servlet 2.3 container, absense of ServletListener prompts for usage of ContextLoaderServlet, while web application
on Servlet 2.4 container, can make use of the ContextLoaderListener for loadingSpring based application context.
45.Are there any ways to pass value of property of a bean as NULL ?
Yes, NULL tag can be used for passing as property’s value.
46.If the Value tag is empty then what will be passed as value to the property of the bean?
An empty string “” will be passed as value to the property tag if empty value tag is present in property tag of a bean such as follows:
47.What is a compound property name in Spring’s definition?
If the name of the property is having multiple/nested property name such as a.b.c and none of the property’s value should be null, except the last one, or else Null pointer exception will be thrown at runtime.
48.Can there be singleton bean initialized lazily?
Yes, by using lazy-init=”true” in the bean tag, Spring’s ApplicationContext can be instructed not to eagerly instantiate and configure this bean. But can instantiate this bean on request only.
49.What are the different scopes applicable to Spring bean?
Various predefined scopes such as singleton, prototype, request, session, global session can be used.
50.Can there be any custom scope that can be defined and used along with other Spring configurations declaratively and programmatically?
Yes, one can define custom scope for the bean while scope can be registered programmatically and can be used in configuration file declaratively.
51.How to handle Spring bean initialization and destruction so as to be able to write some logic to be executed during construction and destruction?
Initialization and destruction callbacks can be assigned to specific methods as defined in the configuration declaratively or programmatically by the bean class
implementing InitializingBean and DisposableBean interfaces and implementing declared methods to receive callbacks.
52.Can there be custom initialization/destruction callback method like init/destroy defined in Spring?
Yes, there are predefined attributes in bean tag for user defined callback methods to be called during initialization/destruction method of bean.
53.What is that attribute?
default-init-method and default-destroy-method are the attributes for defined custom / user defined initialization/destruction callback methods of bean.
54.Is there any way to enable lazy initialization of bean defined in Spring’configuration XML file?
Yes, the attribute lazy-init with value as true/false that decides whether to carry out lazy initilization of the corresponding bean or not.
55.What will happen if a singleton-scoped bean has a reference property for the bean that has attribute as lazy-init=”true”?
In this case, Spring’s container will create the bean wvwn though this is defined as lazy-init=”true” and inject it into the other Spring bean.that is singleton-scoped.
56.Can you tell difference between Spring’s session and globalsession scopes for the bean?
Spring’s session is some what similar to the HTTP session in case of a web application, while Spring’s globalsession is more useful in case of portlet-based web application, where portlets are sharing a global
HTTP session for a portlet web application.
57.is ther any specific care that should be taken while configuring HTTP request,HTTP session or HTTP global session scope for a bean in a web-based application,while this bean is to be injected to another singleton scoped bean?
Yes, while request, session or global session scopes can be used for scoping dependency injection, but by default the bean with singleton scope will be initialized for once and it will be injected for once the dependent bean with
scope as request/session/globalsession, thus making it not usable for all other HTTP client requests, as for any other client request corresponding different request/session/globalsession scoped bean may be applicable.
58.How to work with this type of singleton scoped bean behavior of a bean operating along with request/session/globalsession scoped bean as dependency?
One way is to use >aop-schema-name:scoped-proxy/< tag for the bean that is to be defined with scope as request/session/globalsession. This way the other bean
that is scoped as singleton will be getting appropriate dependent beans scoped as request/session/globalsession.
59.Can you tell any example showing this behavior?
<bean id=”EmployeeRequest” class=”example.EmployeeRequest” scope=”request”>
<bean id=”CalculateSalary” class=”example.SalaryCalculate”>
<property name=”employeeRequest” ref=”EmployeeRequest”/>
60.What will be used either CGLIB-based class proxy or JDK-based dymanic proxy?
In this case/example, CGLIB-based class proxy will be used.
61.Can you be able to use JDK-based dynamic proxy?
Yes, by providing a false value to the proxy-target-class attribute of scoped-proxy tag from the aspect schema definition.
62.If the bean “EmployeeRequest” would have implemented an interface, then which class proxy type is suitable to use?
JDK-based dynamic proxy can be used in case the bean that has implemented an interface and has scoped-proxy tag defined in configuration.
63.What is Java based bean metadata in SpringFramework version 3.0?
Various annotations such as @Configuration, @Bean, @DependsOn @Primary, @Lazy, @Import, @ImportResource, @Value are added in SpringFramework version 3.0 as part of Java based bean
64.What is the pre-requisite for using request, session and global session scope for bean in SpringFramework version 3.0, as far as Spring ApplicationContext implementation is of concern?
For using scopes such as request, session and global session for Beans used in SpringFramework’s implementation for ApplicationContextis of concern, one should be using a web-aware Spring’s ApplicationContext
implementation such as XmlWebApplicationContext (from the package org.springframework.web.context.support) can be used.
65.What will happen if someone tries to use FileSystemXmlApplicationContext or ClassPathXmlApplicationContext class for using request, session and global session scopes for beans defined in the Spring’s Application Context?
There will be an exception IllegalStateException thrown as the bean scope is not known for these implementation of Application context from SpringFramework.
66.What is the major difference over the definition of Singleton, as we know from the GoF Singleton design pattern with that of Spring’s Singleton scoped bean?
GoF Singleton design pattern is the single instance of a class in a Classloader.But in SpringFramework, Singleton scoped bean is single instance per container per bean.
67.What would be the default scope for a bean in SpringFramework configuration if the scope attribute is not mentioned in the bean tag?
By default scope for a bean is Singleton, when there is no scope attribute value mentioned for that bean in the Spring configuration file.
68.What is a key design principle in Spring web MVC ?
“Open for extension and closed for modification” is a key design principle in Spring Web MVC.
69.What represents a Model in Spring’s MVC architecture?
Spring’s Model is based on Map interface, so by this abstraction of Model, loose coupling between View and Model is achieved in Spring Web MVC implementation.
70.In Spring’s Web MVC Architecture, is it required to have the Model class uses framework specific class or interface?
No, it is not required to have the model implementation depend on Spring’s Framework specific class or interface. Spring’s Model can be a POJO with no dependency on
Spring’s Framework class files.
71.In Spring Web MVC, can the Controller implementation be able to write directly to the output/response stream?
Yes, in Spring Web MVC, Controller can write content to the output/response stream.
72.What are the ways one can achive view resolution in Spring Web MVC?
One can achive view resolution in Spring Web MVC by view configuration using bean names,a properties file or custom ViewResolver implementation by user.
73.What are the various View Resolvers available with Spring Framework version 3.0?
Various View Resolvers available with Spring Framework version 3.0 web module are XsltViewResolver, InternalResourceViewResolver, ResourceBundleViewResolver,
UrlBasedViewResolver, VelocityViewResolver, XmlViewResolver, VelocityLayoutViewResolver,FreeMarkerViewResolver, BeanNameViewResolver, ContentNegotiatingViewResolver,
74.Are there any view resolver those having caching mechanism associated with?If yes, what are those view resolver?
ResourceBundleViewResolver, UrlBasedViewResolver, XmlViewResolver are the resolvers those are having caching mechanism associated with these.
75.Are there any view resolvers those use Templating for rendering view elements?
FreeMarkerViewResolver, VelocityViewResolver are those view resolvers having support for Templating capabilities.
76.How input data validation is handled while using Spring’s Web MVC?
Input data type mismatch is captured as validation error while working with Spring Web MVC Framework.
77.Can any object be used as command while using Spring Framework Web MVC?
Yes, any object can be used as Command object while using Spring Web MVC.
78.Is it possible to write directly to the response stream from Spring’s Controller ?
Yes, while working with Spring’s Web MVC Controller, one can write directly to the response stream.
79.What basic elements ModelAndView instance contains?
View name and Model as Map element can be found in ModelAndView instance.
80.What are the different values a View element can have?
View name/value can be bean name, a properties file name or a custom ViewResolver name.
81.From design/abstraction perspective how Spring Framework’s Web MVC module uses various UI rendering technologies/frameworks?
As Model element from Spring’s Web MVC Module is based on Map interface,one can easily integrate various UI rendering technologies such as JSP, XSLT, JSTL, Velocity Templates, PDF and many more utilities.
82.What are the various Special beans instances can be found/associated with Spring’s WebApplicationContext instance?
Controller instance, Handling mapping, various resolvers such as view resource locale resolvers, Theme resolver, exception handler resolvers, multipart file resolvers.
83.While using Spring’s Web MVC module, how one can define/configure to use Controller?
Any POJO can be used as cotroller either by defining the POJO class in the *-servlet.xml file (whereby * is to be replaced by the servlet-name from web.xml
descriptor file) as bean or by using @Controller annotation (in case of appropriate version of Spring Framework with support for annotations).
84.Presence of request parameters with value in request object might need to be mapped to appropriate configured method parameters, Is it possible if yes then how?
If annotation is supported, then Request level parameters and its value can be mapped to controller method argument by using @RequestParam annotation.
85.What is the significance of @RequestBody annotation?
Annotation @RequestBody can be used at method level to accept body part of request object as a parameter value of type String.
86.How to send reponse data directly to the response object without adding it to the Model or not to be considered as view name?
By using annotation @ResponseBody tagged to a method for making the return value from the same method added to the response body, and not making it as Model value or as view name.
87.Can Hibernate Session Factory be bound to JNDI?
Yes, by configuring in hibernate.cfg file, session factory can be bound to initial context (as defined by properties hibernate.jndi.url and hibernate.jndi.class).
88.Can Hibernate be used to call stored procedures and SQL statements?
Yes, there are provision in Hibernate 3.2, for defining callable statements and SQL in mapping HBM files.
89.Can the custom SQL be defined for creation of Java entity object by loading values from database tables and populating Java Object?
Yes, Javaentity objects can be loaded with custom SQL queries and can be defined in HBM file in form of HQL (Hibernate Query Language).
90.What are the different Fetching Strategies available with Hibernate 3.2?
There are four different Fetching standards available in Hibernate3.2, as follows: join fetching, select fetching, batch fetching, sub-select fetching.
91.What are the different types of statistics available in Hibernate 3.2?
Different types of statistics like QueryStatistics, CategorizedStatistics, CollectionStatistics, EntityStatistics etc., available in Hibernate 3.2.
92.How can you get a handle on Hibernate Statistics?
If Hibernate is deployed in a JMX enabled Application server, then Hibernate provided a statistics service,that can be registered as MBean with JMX server and be used to retrieve different types of statistics available.
Hibernate statistics can be obtained from session factory as well.
93.Can Hibernate be used to map persistent entity POJO to XML files?
Yes, Hibernate can be used to mapp XML file/tags to POJO entity classes.
94.If there are multiple databases to be used to interact with domain classes, how can session factory be able to manage multiple datasources?
Each datasource will be configured to each session factory, and to use a single database, a session is created to use database.
95.What is lazy initialization in Hibernate?
When there is an association of one-to-one, or one-to-many, or many-to-many between classes, and on creation of one object, it has to bedecided whether to bring associated objects along
with this object or not. By setting lazy=”true” we instruct Hibernate not to bring the associated object/objects during creation of the required object.By setting lazy=”false”, it is the reverse, this means
we instruct Hibernate to bring all the associated objects also at the time of returning the associating object.
96.if there any impact on performance by this attribute lazy ?
This is purely a configuration time decision one has to take to use lazy attribute and its value (true/false)
appropriately. As SessionFactory is created once and reused, all the configuration setting in HBM file is read once, and cann’t be changed at runtime.
97.What are the different states of an instance in Hibernate?
There are three states that exist for any instance of aclass. These are transient, persistent and detached.Those instances that are created but not associated with
any session or not saved in database are trasient objects.Those instances that are created and be used in any of themethods like save, saveOrUpdate, update of Session are
called persistent objects.Those instances that were used in Session methods like save,saveOrUpdate or update to be inserted or updated in database
table, and then session is flushed and closed, now theseobjects are in JVM, but these are not bound to any session.
98.How can certain type of logic executed on execution of CRUD operation of session, without duplicating it across many places in code base?
Hibernate Interceptors can be used to receive callbackfor certain type of events or operations like save, delete,load, update of session. Session Factory level interceptor and session level interceptor.
These Interceptors can be used to have code for certain type of logic to be called for every lifecycle method of session.
99.How can multiple threads access session factory simulteneously to create session instance?
session factory is thread-safe, so it is okay to be used by many threads to have session from session factory, but I think session is not thread safe and it should be
used by one thread at a time, and after use,session has to be flushed and closed.
100.How many ways Hibernate manages concurrency ?
Hibernate has different ways of managing concurrency.These are automatic versioning, detached object and extended user sessions.
101.What are the different contextual session in Hibernate?
There are three different types of contextual session Hibernate provides, these are JTA session context, local thread session context and managed session context.
JTA session context is applicable in case Hibernate session is running in JTA (JavaTransaction API), request thread level session scoped applicable in case of local thread session,
and managed session, requires application to open, close and flush session, so creation of session should be handled by application only.
102.Can you tell us difference between Hibernate HQL over SQL?
HQL is fully object oriented, with support for object inheritence, polymorphism and association, but SQL is more of Relational with structured form of queries.
103.What are the different scopes one can introduce while using Interceptors with Hibernate?
Probably, one can use interceptors with hibernate Sessionscoped or SessionFactory scoped contexts, while using Interceptors with Hibernate.
104.How many ways client application that uses Hibernate to react to certain events?
Probably, if I am not wrong, two ways one can react/act to certain events generated out of Hibernate Framework.These are either Interceptors or event systems.
105.Can I be able to persist a XML DOM object tree to database by defining mapping between XML DOM to database table,without using POJOs?
Yes, one can use Hibernate mapping to persist XML DOM tree hierarchy to database tables.