SlideShare a Scribd company logo
JAVA Interview Questions Part-2
JAVA J2EE Training
51. What are considered as a web component?
Java Servlet and Java Server Pages technology components are web components.
Servlets are Java programming language that dynamically receive requests and
make responses. JSP pages execute as servlets but allow a more natural approach
to creating static content.
52. Define Hash table?
Hash Table is just like Hash Map or Collection having unique key value pairs. Hash
table is a collection of Synchronized object. It does not allow duplicate values but it
allows null values.
53. What is Hibernate?
Hibernate is a open source object-relational mapping and query service. In
hibernate we can write HQL instead of SQL which save developers to spend more
time on writing the native SQL. Hibernate has more powerful association,
inheritance, polymorphism, composition, and collections. It is a beautiful approach
for persisting into database using the java objects. Hibernate also allows you to
express queries using java-based criteria.
54. What is ORM?
ORM stands for Object-Relational mapping. The objects in a Java class which is
mapped in to the tables of a relational database using the metadata that describes
the mapping between the objects and the database. It works by transforming the
data from one representation to another.
55. Difference between Proxy and Adapter?
Adapter object has a different input than the real subject whereas Proxy object has
the same input as the real subject. Proxy object is such that it should be placed as
it is in place of the real subject.
56. What is MVC?
Model-View-Controller is a design pattern wherein Model holds the business logic
, Controller controls the flow and View takes care of the presentation part of web
application.
57. What is dependency injection or IOC?
It's a mechanism of passing object creation to an external component wherein
dependent objects are identified and created using configuration.
58. What is bean auto wiring?
The Spring container is able to auto wire 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 without using <constructor-arg> and <property> element.
59. What are the different types of IOC (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
60. What are the advantages of Spring framework?
The advantages of Spring are as follows:
Spring has layered architecture. Use what you need and leave you don't need now.
Spring Enables POJO Programming. There is no behind the scene magic here. POJO
programming enables continuous integration and testability.
Dependency Injection and Inversion of Control Simplifies JDBC
Open source and no vendor lock-in.
61. What are the common implementations of the Application Context?
The three commonly used implementation of 'Application Context' are,
ClassPathXmlApplicationContext : It Loads context definition from an XML file
located in the classpath, treating context definitions as classpath resources. The
application context is loaded from the application's classpath by using the code.
ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
FileSystemXmlApplicationContext : It loads context definition from an XML file in
the filesystem. The application context is loaded from the file system by using the
code.
ApplicationContext context = new FileSystemXmlApplicationContext("bean.xml");
XmlWebApplicationContext : It loads context definition from an XML file
contained within a web application.
62. 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.
63. What is Significance of JSF- Spring integration?
Spring - JSF integration is useful when an event handler wishes to explicitly invoke
the bean factory to create beans on demand, such as a bean that encapsulates the
business logic to be performed when a submit button is pressed.
64. What are the ways to access Hibernate using Spring?
There are two approaches to Spring’s Hibernate integration:
Inversion of Control with a HibernateTemplate and Callback
Extending HibernateDaoSupport and Applying an AOP Interceptor.
65. How the AOP used in Spring?
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.
66. What is Session Tracking?
Session simply means a particular interval of time.
Session Tracking is a way to maintain state of an user. Http protocol is a stateless
protocol. Each time user requests to the server, server treats the request as the
new request. So we need to maintain the state of a user to recognize to particular
user.
67. How is a typical spring implementation look like?
For a typical Spring Application we need the following files:
An interface that defines the functions.
An Implementation that contains properties, its setter and getter methods,
functions etc., Spring AOP (Aspect Oriented Programming)
A XML file called spring configuration file.
Client program that uses the function.
68. What is Java Server Faces (JSF) - spring integration mechanism?
Spring provides a custom JavaServer Faces VariableResolver implementation that
extends the standard JavaServer Faces managed beans mechanism. When asked to
resolve a variable name, the following algorithm is performed.
69. What is Significance of JSF- Spring integration?
Spring - JSF integration is useful when an event handler wishes to explicitly invoke
the bean factory to create beans on demand, such as a bean that encapsulates the
business logic to be performed when a submit button is pressed.
70. 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 a getWebApplicationContext() method.
71. How to integrate spring and Hibernate?
Spring and Hibernate can integrate using spring’s SessionFactory called
LocalSessionFactory. The integration process is of 3 steps.
Configure Hibernate mappings.
Configure Hibernate properties.
Wire dependant object to SessionFactory.
72. What are the ways to access Hibernate using Spring?
There are two ways to access Hibernate from Spring:
Through Hibernate Template.
Subclassing HibernateDaoSupport
Extending HibernateDaoSupport and Applying an AOP Interceptor
73. Why most users of the Spring Framework choose declarative transaction
management?
Most users of the Spring Framework choose declarative transaction management
because it is the option with the least impact on application code, and hence is
most consistent with the ideals of a non-invasive lightweight container.
74. When to use programmatic and declarative transaction management?
Programmatic transaction management is usually a good idea only if you have a
small number of transactional operations.
On the other hand, if your application has numerous transactional operations,
declarative transaction management is usually worthwhile. It keeps transaction
management out of business logic, and is not difficult to configure.
75. 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.
76.What are the exceptions thrown by the Spring DAO classes?
Spring DAO classes throw exceptions which are subclasses of
DataAccessException(org.springframework.dao.DataAccessException).Spring
provides a convenient translation from technology-specific exceptions like
SQLException to its own exception class hierarchy with the DataAccessException as
the root exception. These exceptions wrap the original exception.
77. 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.
78. What is Spring's JdbcTemplate ?
Spring's JdbcTemplate is central class to interact with a database through
JDBC. JdbcTemplate provides many convenience methods for doing things such as
converting database data into primitives or objects, executing prepared and
callable statements, and providing custom database error handling.
JdbcTemplate template = new JdbcTemplate(myDataSource);
79. What is PreparedStatementCreator ?
PreparedStatementCreator:
Is one of the most commonly used interfaces for writing data to database.
Has one method – createPreparedStatement(Connection)
Responsible for creating a PreparedStatement.
Does not need to handle SQLExceptions.
80. 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.
81. 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.
82. What are the exceptions thrown by the Spring DAO classes ?
Spring DAO classes throw exceptions which are subclasses of
DataAccessException(org.springframework.dao.DataAccessException).Spring
provides a convenient translation from technology-specific exceptions like
SQLException to its own exception class hierarchy with the DataAccessException as
the root exception. These exceptions wrap the original exception.
83. What is Spring's JdbcTemplate ?
Spring's JdbcTemplate is central class to interact with a database through JDBC.
JdbcTemplate provides many convenience methods for doing things such as
converting database data into primitives or objects, executing prepared and
callable statements, and providing custom database error handling.
JdbcTemplate template = new JdbcTemplate (myDataSource);
84. Explain the three different methods which are provided by the Namespace
Handler interface?
The three different methods which are provided by the name space handler
interface are:
1) Init() is used to allow initialization for name space handler.
2) BeanDefinition parse is used when a Spring encounters a top level element.
3) BeanDefinitionHandler is used when spring encounters an attribute.
85. Which of the beans available in EJB 3 are only called by clients ?
Session and Singleton (EJB 3.1) beans are the ones who encapsulate the business
logic which is why it is the only bean which is called by clients. Other beans like
MDB and Entity beans are called by session and singleton beans to complete the
business requirement.
86. Why is it so to make the session beans into two parts one with interface and
the other as implementation to the interface? Or why session beans should be
used through business interface? (EJB 3.0 Specific).
This approach promotes loose coupling since implementation classes can easily be
swapped out without a lot of code changes. But in recent EJB 3.1 specification you
don't need to implement a business interface for faster development.
87. What is business interface?
An interface through which a client invokes the bean is called a business
interface. There are three types of business interfaces available in EJB 3 : Local,
Remote and WebService
88. Can we have instance fields in Stateless session bean?
Yes. A stateless session bean can have instance field, BUT not for storing state
information as opposed to Stateful beans. There may be a need of storing certain
shareable resources like data source, JMS source etc, which will be used in the
exposed method. So it is perfectly safe to have instance fields in the Stateless
session beans.
89. Can you inject Stateful beans into stateless session bean or Servlet?
Yes!!. Nobody stops you to inject Stateful beans into stateless session bean or a
Servlet. Let’s take a Servlet and inject (definitely as a field in Servlet) a Stateful
bean; What happens? Container creates a single instance of a Servlet, so the
instance field of Servlet ( which is a Stateful Bean ) injected , is shared among
clients.It will lead to drastic data inconsistency ( stored in Stateful bean ) being
shared by clients. And this is no different for a Stateful bean injected into stateless
bean. So you must AVOID injecting into stateless beans and Servlets. Please don't
ask how do you access or make use of Stateful bean in Stateless or Servlet.The
answer is JNDI inside the methods of Stateless and doGet() or doPost() of Servlet.
90. What are Pull-MVC and push-MVC based architecture ? Whicharchitecture
does Struts2 follow?
Pull-MVC and Push-MVC are better understood with how the view layer is getting
data i.e. Model to render. In case of Push-MVC the data( Model) is constructed and
given to the view layer by the Controllers by putting it in the scoped variables like
request or session. Typical example is Spring MVC and Struts1. Pull-MVC on the
other hand puts the model data typically constructed in Controllers are kept in a
common place i.e. in actions, which then gets rendered by view layer. Struts2 is a
Pull-MVC based architecture, in which all data is stored in Value Stack and
retrieved by view layer for rendering.
91. Are Interceptors in Struts2 thread safe?
No, Unlike Struts2 action, Interceptors are shared between requests, so thread
issues will come if not taken care of
92. Are Interceptors and Filters different? , If yes then how?
Apart from the fact that both Interceptors and filters are based on intercepting
filter,there are few differences when it comes to Struts2.
Filters: (1)Based on Servlet Specification (2)Executes on the pattern matches on
the request.(3) Not configurable method calls
Interceptors: (1)Based on Struts2. (2)Executes for all the request qualifies for a
front controller( A Servlet filter ).And can be configured to execute additional
interceptor for a particular action execution.(3)Methods in the Interceptors can be
configured whether to execute or not by means of excludemethods or
includeMethods. ( see tutorial on this Controlling Interceptor Behavior)
93. Which class is the front-controller in Struts2?
The class "org.apache.struts2.dispatcher.FilterDispatcher " is the front controller in
Struts2. In recent time Struts 2.1.3 this class is deprecated and new classes are
introduced to do the job.
94. What is the role of Action/ Model?
Actions in Struts are POJO, is also considered as a Model. The role of Action are to
execute business logic or delegate call to business logic by the means of action
methods which is mapped to request and contains business data to be used by the
view layer by means of setters and getters inside the Action class and finally helps
the framework decide which result to render.
95. What is the relation between ValueStack and OGNL?
A ValueStack is a place where all the data related to action and the action itself is
stored. OGNL is a mean through which the data in the ValueStack is manipulated.
96. What is the difference between Action and ActionSupport?
Action is interface defines some string like SUCCESS,ERROR etc and an execute()
method. For convenience Developer implement this interface to have access to
String field in action methods. ActionSupport on other hand implements Action
and some other interfaces and provides some feature like data validation and
localized error messaging when extended in the action classes by developers
97. Who loads the struts.xml file? Which Struts2 API loads the struts.xml file?
In Struts2 FilterServlet is the responsible class for loading struts.xml file as we
deploy the application on the container. Unlike Servlet (as with Struts1) needs
the load-on-startup tag to load the front controller,a filter doesn't need to have
load on startup tag to be loaded as the application is deployed. As with servlet
specification a filter is loaded/executed as the application starts up.
98. What is JDBC Driver interface?
The JDBC Driver interface provides vendor-specific implementations of the
abstract classes provided by the JDBC API. Each vendor driver must provide
implementations of the java.sql.Connection, Statement, PreparedStatement,
CallableStatement, ResultSet and Driver.
99. What is the jspInit() method?
The jspInit() method of the javax.servlet.jsp.JspPage interface is similar to the init()
method of servlets. This method is invoked by the container only once when a JSP
page is initialized. It can be overridden by a page author to initialize resources such
as database and network connections, and to allow a JSP page to read persistent
configuration data.
100. What is the _jspService() method?
The _jspService() method of the javax.servlet.jsp.HttpJspPage interface is invoked
every time a new request comes to a JSP page. This method takes the
HttpServletRequest and HttpServletResponse objects as its arguments. A page
author cannot override this method, as its implementation is provided by the
container.

More Related Content

PPTX
Introduction to JAVA
PDF
Java Interview Questions
PPT
Hibernate introduction
PDF
Java questions for interview
PPT
Java interview-questions-and-answers
ZIP
Introduction to the Java(TM) Advanced Imaging API
PPSX
Elements of Java Language
PPTX
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Introduction to JAVA
Java Interview Questions
Hibernate introduction
Java questions for interview
Java interview-questions-and-answers
Introduction to the Java(TM) Advanced Imaging API
Elements of Java Language
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...

What's hot (17)

PPT
Basic java part_ii
PDF
Top 10 Java Interview Questions and Answers 2014
PDF
Core Java
PDF
Java interview questions
PPTX
Introduction to java
PPT
Java basic
PDF
Core java interview questions
PDF
50+ java interview questions
PPTX
Technical Interview
PPSX
Core java lessons
PPTX
Core java
PPTX
JAVA PROGRAMMING
PPT
Design pattern
PDF
Swing api
PDF
9 crucial Java Design Principles you cannot miss
PDF
Basic Java Programming
PPT
Presentation on java
Basic java part_ii
Top 10 Java Interview Questions and Answers 2014
Core Java
Java interview questions
Introduction to java
Java basic
Core java interview questions
50+ java interview questions
Technical Interview
Core java lessons
Core java
JAVA PROGRAMMING
Design pattern
Swing api
9 crucial Java Design Principles you cannot miss
Basic Java Programming
Presentation on java
Ad

Similar to Java J2EE Interview Questions Part 2 (20)

PPTX
Spring Framework
PDF
Spring 2
PDF
Spring mvc
PPTX
Introduction to Spring Framework
PPTX
Spring Basics
PPTX
Spring from a to Z
PPTX
Java spring ppt
PPTX
PPT
141060753008 3715301
PPTX
Spring (1)
PPTX
Introduction to Spring sec1.pptx
PPTX
Struts & spring framework issues
PPTX
Introduction Java Web Framework and Web Server.
PPTX
Spring framework-tutorial
PPT
Module 5.ppt.............................
PPT
Spring Framework
ODP
Spring survey
PPTX
Introduction to j2 ee frameworks
PDF
Signal Framework
PPTX
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Spring Framework
Spring 2
Spring mvc
Introduction to Spring Framework
Spring Basics
Spring from a to Z
Java spring ppt
141060753008 3715301
Spring (1)
Introduction to Spring sec1.pptx
Struts & spring framework issues
Introduction Java Web Framework and Web Server.
Spring framework-tutorial
Module 5.ppt.............................
Spring Framework
Spring survey
Introduction to j2 ee frameworks
Signal Framework
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Ad

Recently uploaded (20)

PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
PDF
Become an Agentblazer Champion Challenge Kickoff
PDF
Best Practices for Rolling Out Competency Management Software.pdf
PPTX
Mastering-Cybersecurity-The-Crucial-Role-of-Antivirus-Support-Services.pptx
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Digital Strategies for Manufacturing Companies
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Build Multi-agent using Agent Development Kit
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
DOCX
The Five Best AI Cover Tools in 2025.docx
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
ISO 45001 Occupational Health and Safety Management System
PPTX
Transform Your Business with a Software ERP System
PPT
Introduction Database Management System for Course Database
PDF
System and Network Administraation Chapter 3
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
A REACT POMODORO TIMER WEB APPLICATION.pdf
Become an Agentblazer Champion Challenge Kickoff
Best Practices for Rolling Out Competency Management Software.pdf
Mastering-Cybersecurity-The-Crucial-Role-of-Antivirus-Support-Services.pptx
PTS Company Brochure 2025 (1).pdf.......
Odoo POS Development Services by CandidRoot Solutions
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Digital Strategies for Manufacturing Companies
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Build Multi-agent using Agent Development Kit
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
2025 Textile ERP Trends: SAP, Odoo & Oracle
The Five Best AI Cover Tools in 2025.docx
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
ISO 45001 Occupational Health and Safety Management System
Transform Your Business with a Software ERP System
Introduction Database Management System for Course Database
System and Network Administraation Chapter 3
Softaken Excel to vCard Converter Software.pdf
Upgrade and Innovation Strategies for SAP ERP Customers

Java J2EE Interview Questions Part 2

  • 1. JAVA Interview Questions Part-2 JAVA J2EE Training
  • 2. 51. What are considered as a web component? Java Servlet and Java Server Pages technology components are web components. Servlets are Java programming language that dynamically receive requests and make responses. JSP pages execute as servlets but allow a more natural approach to creating static content. 52. Define Hash table? Hash Table is just like Hash Map or Collection having unique key value pairs. Hash table is a collection of Synchronized object. It does not allow duplicate values but it allows null values. 53. What is Hibernate? Hibernate is a open source object-relational mapping and query service. In hibernate we can write HQL instead of SQL which save developers to spend more time on writing the native SQL. Hibernate has more powerful association, inheritance, polymorphism, composition, and collections. It is a beautiful approach for persisting into database using the java objects. Hibernate also allows you to express queries using java-based criteria.
  • 3. 54. What is ORM? ORM stands for Object-Relational mapping. The objects in a Java class which is mapped in to the tables of a relational database using the metadata that describes the mapping between the objects and the database. It works by transforming the data from one representation to another. 55. Difference between Proxy and Adapter? Adapter object has a different input than the real subject whereas Proxy object has the same input as the real subject. Proxy object is such that it should be placed as it is in place of the real subject. 56. What is MVC? Model-View-Controller is a design pattern wherein Model holds the business logic , Controller controls the flow and View takes care of the presentation part of web application.
  • 4. 57. What is dependency injection or IOC? It's a mechanism of passing object creation to an external component wherein dependent objects are identified and created using configuration. 58. What is bean auto wiring? The Spring container is able to auto wire 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 without using <constructor-arg> and <property> element. 59. What are the different types of IOC (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
  • 5. 60. What are the advantages of Spring framework? The advantages of Spring are as follows: Spring has layered architecture. Use what you need and leave you don't need now. Spring Enables POJO Programming. There is no behind the scene magic here. POJO programming enables continuous integration and testability. Dependency Injection and Inversion of Control Simplifies JDBC Open source and no vendor lock-in. 61. What are the common implementations of the Application Context? The three commonly used implementation of 'Application Context' are, ClassPathXmlApplicationContext : It Loads context definition from an XML file located in the classpath, treating context definitions as classpath resources. The application context is loaded from the application's classpath by using the code. ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml"); FileSystemXmlApplicationContext : It loads context definition from an XML file in the filesystem. The application context is loaded from the file system by using the code. ApplicationContext context = new FileSystemXmlApplicationContext("bean.xml"); XmlWebApplicationContext : It loads context definition from an XML file contained within a web application.
  • 6. 62. 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. 63. What is Significance of JSF- Spring integration? Spring - JSF integration is useful when an event handler wishes to explicitly invoke the bean factory to create beans on demand, such as a bean that encapsulates the business logic to be performed when a submit button is pressed. 64. What are the ways to access Hibernate using Spring? There are two approaches to Spring’s Hibernate integration: Inversion of Control with a HibernateTemplate and Callback Extending HibernateDaoSupport and Applying an AOP Interceptor.
  • 7. 65. How the AOP used in Spring? 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. 66. What is Session Tracking? Session simply means a particular interval of time. Session Tracking is a way to maintain state of an user. Http protocol is a stateless protocol. Each time user requests to the server, server treats the request as the new request. So we need to maintain the state of a user to recognize to particular user. 67. How is a typical spring implementation look like? For a typical Spring Application we need the following files: An interface that defines the functions. An Implementation that contains properties, its setter and getter methods, functions etc., Spring AOP (Aspect Oriented Programming) A XML file called spring configuration file. Client program that uses the function.
  • 8. 68. What is Java Server Faces (JSF) - spring integration mechanism? Spring provides a custom JavaServer Faces VariableResolver implementation that extends the standard JavaServer Faces managed beans mechanism. When asked to resolve a variable name, the following algorithm is performed. 69. What is Significance of JSF- Spring integration? Spring - JSF integration is useful when an event handler wishes to explicitly invoke the bean factory to create beans on demand, such as a bean that encapsulates the business logic to be performed when a submit button is pressed. 70. 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 a getWebApplicationContext() method.
  • 9. 71. How to integrate spring and Hibernate? Spring and Hibernate can integrate using spring’s SessionFactory called LocalSessionFactory. The integration process is of 3 steps. Configure Hibernate mappings. Configure Hibernate properties. Wire dependant object to SessionFactory. 72. What are the ways to access Hibernate using Spring? There are two ways to access Hibernate from Spring: Through Hibernate Template. Subclassing HibernateDaoSupport Extending HibernateDaoSupport and Applying an AOP Interceptor 73. Why most users of the Spring Framework choose declarative transaction management? Most users of the Spring Framework choose declarative transaction management because it is the option with the least impact on application code, and hence is most consistent with the ideals of a non-invasive lightweight container.
  • 10. 74. When to use programmatic and declarative transaction management? Programmatic transaction management is usually a good idea only if you have a small number of transactional operations. On the other hand, if your application has numerous transactional operations, declarative transaction management is usually worthwhile. It keeps transaction management out of business logic, and is not difficult to configure. 75. 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. 76.What are the exceptions thrown by the Spring DAO classes? Spring DAO classes throw exceptions which are subclasses of DataAccessException(org.springframework.dao.DataAccessException).Spring provides a convenient translation from technology-specific exceptions like SQLException to its own exception class hierarchy with the DataAccessException as the root exception. These exceptions wrap the original exception.
  • 11. 77. 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. 78. What is Spring's JdbcTemplate ? Spring's JdbcTemplate is central class to interact with a database through JDBC. JdbcTemplate provides many convenience methods for doing things such as converting database data into primitives or objects, executing prepared and callable statements, and providing custom database error handling. JdbcTemplate template = new JdbcTemplate(myDataSource); 79. What is PreparedStatementCreator ? PreparedStatementCreator: Is one of the most commonly used interfaces for writing data to database. Has one method – createPreparedStatement(Connection) Responsible for creating a PreparedStatement. Does not need to handle SQLExceptions.
  • 12. 80. 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. 81. 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.
  • 13. 82. What are the exceptions thrown by the Spring DAO classes ? Spring DAO classes throw exceptions which are subclasses of DataAccessException(org.springframework.dao.DataAccessException).Spring provides a convenient translation from technology-specific exceptions like SQLException to its own exception class hierarchy with the DataAccessException as the root exception. These exceptions wrap the original exception. 83. What is Spring's JdbcTemplate ? Spring's JdbcTemplate is central class to interact with a database through JDBC. JdbcTemplate provides many convenience methods for doing things such as converting database data into primitives or objects, executing prepared and callable statements, and providing custom database error handling. JdbcTemplate template = new JdbcTemplate (myDataSource); 84. Explain the three different methods which are provided by the Namespace Handler interface? The three different methods which are provided by the name space handler interface are: 1) Init() is used to allow initialization for name space handler. 2) BeanDefinition parse is used when a Spring encounters a top level element. 3) BeanDefinitionHandler is used when spring encounters an attribute.
  • 14. 85. Which of the beans available in EJB 3 are only called by clients ? Session and Singleton (EJB 3.1) beans are the ones who encapsulate the business logic which is why it is the only bean which is called by clients. Other beans like MDB and Entity beans are called by session and singleton beans to complete the business requirement. 86. Why is it so to make the session beans into two parts one with interface and the other as implementation to the interface? Or why session beans should be used through business interface? (EJB 3.0 Specific). This approach promotes loose coupling since implementation classes can easily be swapped out without a lot of code changes. But in recent EJB 3.1 specification you don't need to implement a business interface for faster development. 87. What is business interface? An interface through which a client invokes the bean is called a business interface. There are three types of business interfaces available in EJB 3 : Local, Remote and WebService
  • 15. 88. Can we have instance fields in Stateless session bean? Yes. A stateless session bean can have instance field, BUT not for storing state information as opposed to Stateful beans. There may be a need of storing certain shareable resources like data source, JMS source etc, which will be used in the exposed method. So it is perfectly safe to have instance fields in the Stateless session beans. 89. Can you inject Stateful beans into stateless session bean or Servlet? Yes!!. Nobody stops you to inject Stateful beans into stateless session bean or a Servlet. Let’s take a Servlet and inject (definitely as a field in Servlet) a Stateful bean; What happens? Container creates a single instance of a Servlet, so the instance field of Servlet ( which is a Stateful Bean ) injected , is shared among clients.It will lead to drastic data inconsistency ( stored in Stateful bean ) being shared by clients. And this is no different for a Stateful bean injected into stateless bean. So you must AVOID injecting into stateless beans and Servlets. Please don't ask how do you access or make use of Stateful bean in Stateless or Servlet.The answer is JNDI inside the methods of Stateless and doGet() or doPost() of Servlet.
  • 16. 90. What are Pull-MVC and push-MVC based architecture ? Whicharchitecture does Struts2 follow? Pull-MVC and Push-MVC are better understood with how the view layer is getting data i.e. Model to render. In case of Push-MVC the data( Model) is constructed and given to the view layer by the Controllers by putting it in the scoped variables like request or session. Typical example is Spring MVC and Struts1. Pull-MVC on the other hand puts the model data typically constructed in Controllers are kept in a common place i.e. in actions, which then gets rendered by view layer. Struts2 is a Pull-MVC based architecture, in which all data is stored in Value Stack and retrieved by view layer for rendering. 91. Are Interceptors in Struts2 thread safe? No, Unlike Struts2 action, Interceptors are shared between requests, so thread issues will come if not taken care of
  • 17. 92. Are Interceptors and Filters different? , If yes then how? Apart from the fact that both Interceptors and filters are based on intercepting filter,there are few differences when it comes to Struts2. Filters: (1)Based on Servlet Specification (2)Executes on the pattern matches on the request.(3) Not configurable method calls Interceptors: (1)Based on Struts2. (2)Executes for all the request qualifies for a front controller( A Servlet filter ).And can be configured to execute additional interceptor for a particular action execution.(3)Methods in the Interceptors can be configured whether to execute or not by means of excludemethods or includeMethods. ( see tutorial on this Controlling Interceptor Behavior) 93. Which class is the front-controller in Struts2? The class "org.apache.struts2.dispatcher.FilterDispatcher " is the front controller in Struts2. In recent time Struts 2.1.3 this class is deprecated and new classes are introduced to do the job. 94. What is the role of Action/ Model? Actions in Struts are POJO, is also considered as a Model. The role of Action are to execute business logic or delegate call to business logic by the means of action methods which is mapped to request and contains business data to be used by the view layer by means of setters and getters inside the Action class and finally helps the framework decide which result to render.
  • 18. 95. What is the relation between ValueStack and OGNL? A ValueStack is a place where all the data related to action and the action itself is stored. OGNL is a mean through which the data in the ValueStack is manipulated. 96. What is the difference between Action and ActionSupport? Action is interface defines some string like SUCCESS,ERROR etc and an execute() method. For convenience Developer implement this interface to have access to String field in action methods. ActionSupport on other hand implements Action and some other interfaces and provides some feature like data validation and localized error messaging when extended in the action classes by developers 97. Who loads the struts.xml file? Which Struts2 API loads the struts.xml file? In Struts2 FilterServlet is the responsible class for loading struts.xml file as we deploy the application on the container. Unlike Servlet (as with Struts1) needs the load-on-startup tag to load the front controller,a filter doesn't need to have load on startup tag to be loaded as the application is deployed. As with servlet specification a filter is loaded/executed as the application starts up.
  • 19. 98. What is JDBC Driver interface? The JDBC Driver interface provides vendor-specific implementations of the abstract classes provided by the JDBC API. Each vendor driver must provide implementations of the java.sql.Connection, Statement, PreparedStatement, CallableStatement, ResultSet and Driver. 99. What is the jspInit() method? The jspInit() method of the javax.servlet.jsp.JspPage interface is similar to the init() method of servlets. This method is invoked by the container only once when a JSP page is initialized. It can be overridden by a page author to initialize resources such as database and network connections, and to allow a JSP page to read persistent configuration data. 100. What is the _jspService() method? The _jspService() method of the javax.servlet.jsp.HttpJspPage interface is invoked every time a new request comes to a JSP page. This method takes the HttpServletRequest and HttpServletResponse objects as its arguments. A page author cannot override this method, as its implementation is provided by the container.