|
EJB Interview Questions |
|
|
|
Here you can find out a list of interview questions for
EJB. These questions are often asked by the interviewer for EJB (Enterprise
Java Bean)
interview. We put our maximum effort to make this answers error free.
But still there might be some errors. If you feel out any answer given for
any question is wrong, please, please inform us by clicking on report
bug button provided below.
In this section we are offering interview questions for EJB only. if
you need interview questions for any other java related technologies ,
please check the relevant sections.
|
|
|
|
|
|
| 1 |
Q |
What is EJB? |
| |
A |
Enterprise JavaBeans (EJB) technology is the server-side
component architecture for the Java 2 Platform, Enterprise Edition (J2EE)
platform. EJB technology enables rapid and simplified development of
distributed, transactional, secure and portable applications based on Java
technology. |
| |
|
|
| 2 |
Q |
What are the different type of Enterprise JavaBeans ? |
| |
A |
There are 3 types of enterprise beans, namely: Session bean, Entity beans
and Message driven beans. |
| |
|
|
| 3 |
Q |
What is Session Bean ? |
| |
A |
Session bean represents a single client inside the J2EE
server. To access the application deployed in the server the client invokes
methods on the session bean. The session bean performs the task shielding
the client from the complexity of the business logic.
Session bean components implement the javax.ejb.SessionBean interface.
Session beans can act as agents modeling workflow or provide access to
special transient business services. Session beans do not normally represent
persistent business concepts.
A session bean corresponds to a client server session. The session bean is
created when a client requests some query on the database and exists as long
as the client server session exists. |
| |
|
|
| 4 |
Q |
What are different types of session bean ? |
| |
A |
There are two types of session beans, namely: Stateful
and Stateless.
|
| |
|
|
| 5 |
Q |
What is a Stateful Session
bean? |
| |
A |
Stateful session bean maintain the state of the
conversation between the client and itself. When the client invokes a
method on the bean the instance variables of the bean may contain a state
but only for the duration of the invocation.
A stateful session bean is an enterprise bean (EJB component) that acts as
a server-side extension of the client that uses it. The stateful session
bean is created by a client and will work for only that client until the
client connection is dropped or the bean is explicitly removed. The
stateful session bean is EJB component that implements the
javax.ejb.SessionBean interface and is deployed with the declarative
attribute "stateful". Stateful session beans are called "stateful" because
they maintain a conversational state with the client. In other words, they
have state or instance fields that can be initialized and changed by the
client with each method invocation. The bean can use the conversational
state as it process business methods invoked by the client. |
| |
|
|
| 6 |
Q |
What is stateless session
bean ? |
| |
A |
Stateless session beans are of equal value for all
instances of the bean. This means the container can assign any bean to any
client, making it very scalable.
A stateless session bean is an enterprise bean that provides a stateless
service to the client. Conceptually, the business methods on a stateless
session bean are similar to procedural applications or static methods; there
is no instance state, so all the data needed to execute the method is
provided by the method arguments. The stateless session bean is an EJB
component that implements the javax.ejb.SessionBean interface and is
deployed with the declarative attribute "stateless". Stateless session beans
are called "stateless" because they do not maintain conversational state
specific to a client session. In other words, the instance fields in a
stateless session bean do not maintain data relative to a client session.
This makes stateless session beans very lightweight and fast, but also
limits their behavior. Typically an application requires less number of
stateless beans compared to stateful beans. |
| |
|
|
| 7 |
Q |
What is an Entity Bean? |
| |
A |
An entity bean represents a business object in a
persistent storage mechanism. An entity bean typically represents a table in
a relational database and each instance represents a row in the table.
Entity bean differs from session bean by: persistence, shared access,
relationship and primary key. T |
| |
|
|
| 8 |
Q |
What are different types of
entity beans? |
| |
A |
There are two types of entity beans available.
Container Managed Persistence (CMP) , Bean managed persistence (BMP). |
| |
|
|
| 9 |
Q |
What is CMP (Container
Managed Persistence) ? |
| |
A |
The term container-managed persistence means that the EJB
container handles all database access required by the entity bean. The
bean's code contains no database access (SQL) calls. As a result, the bean's
code is not tied to a specific persistent storage mechanism (database).
Because of this flexibility, even if you redeploy the same entity bean on
different J2EE servers that use different databases, you won't need to
modify or recompile the bean's code. So, your entity beans are more
portable. |
| |
|
|
| 10 |
Q |
What is BMP (Bean managed persistence) ? |
| |
A |
Bean managed persistence (BMP) occurs when the bean
manages its persistence. Here the bean will handle all the database access.
So the bean's code contains the necessary SQLs calls. So it is not much
portable compared to CMP. Because when we are changing the database we need
to rewrite the SQL for supporting the new database. |
| |
|
|
| 11 |
Q |
What is abstract schema ? |
| |
A |
In order to generate the data access calls, the
container needs information that you provide in the entity bean's abstract
schema. It is a part of Deployment Descriptor. It is used to define the
bean's persistent fields and relation ships. |
| |
|
|
| 12 |
Q |
When we should use Entity
Bean ? |
| |
A |
When the bean represents a business entity, not a
procedure. we should use an entity bean. Also when the bean's state must be
persistent we should use an entity bean. If the bean instance terminates or
if the J2EE server is shut down, the bean's state still exists in persistent
storage (a database). |
| |
|
|
| 13 |
Q |
When to Use Session Beans ? |
| |
A |
At any given time, only one client has access to the bean
instance. The state of the bean is not persistent, existing only for a short
period (perhaps a few hours). The bean implements a web service. Under all
the above circumstances we can use session beans. |
| |
|
|
| 14 |
Q |
When to use Stateful session
bean? |
|
|
A |
The bean's state represents the interaction between the
bean and a specific client. The bean needs to hold information about the
client across method invocations. The bean mediates between the client and
the other components of the application, presenting a simplified view to the
client. Under all the above circumstances we can use a stateful session
bean. |
|
|
|
|
|
15 |
Q |
When to use a stateless
session bean? |
|
|
A |
The bean's state has no data for a specific client. In a
single method invocation, the bean performs a generic task for all clients.
For example, you might use a stateless session bean to send an email that
confirms an online order. The bean fetches from a database a set of
read-only data that is often used by clients. Such a bean, for example,
could retrieve the table rows that represent the products that are on sale
this month. Under all the above circumstance we can use a stateless session
bean. |
|
|
|
|
|
|
|
|
|