HOME      BLOG       FORUMS      CONTACT       ABOUT

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. What is EJB?
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. What are the different type of Enterprise JavaBeans ?
There are 3 types of enterprise beans, namely: Session bean, Entity beans and Message driven beans.

3. What is Session Bean ?
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. What are different types of session bean ?
There are two types of session beans, namely: Stateful and Stateless.

5. What is a Stateful Session bean?
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. What is stateless session bean ?
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. What is an Entity Bean?
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. What are different types of entity beans?
There are two types of entity beans available. Container Managed Persistence (CMP) , Bean managed persistence (BMP).

9. What is CMP (Container Managed Persistence) ?
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. What is BMP (Bean managed persistence) ?
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. What is abstract schema ?
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. When we should use Entity Bean ?
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. When to Use Session Beans ?
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. When to use Stateful session bean?
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. When to use a stateless session bean?
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.

Share

Tags: , , ,


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply