Java EJB Questions - Question Set 1

Thursday, September 23, 2010

Java EJB Questions

Q.1  What is EJB?
Ans. 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.

Q.2  What are the different type of Enterprise JavaBeans ?
Ans  There are 3 types of enterprise beans, namely: Session bean, Entity beans and Message driven beans.

Q.3  What is Session Bean ?
Ans. 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.

Q.4  What are different types of session bean ?
Ans. There are two types of session beans, namely: Stateful and Stateless.

Q.5  What is a Stateful Session bean?
Ans. 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.

Q.6  What is stateless session bean ?
Ans. 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.

Q.7  What is an Entity Bean?
Ans. 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

Q.8  What are different types of entity beans?
Ans.  There are two types of entity beans available. Container Managed Persistence (CMP) , Bean managed persistence (BMP).

Q.9  What is CMP (Container Managed Persistence) ?
Ans. 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.

Q.10  What is BMP (Bean managed persistence) ?
Ans. 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.

Q.11 What is abstract schema ?
Ans. 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.

Q.12 When we should use Entity Bean ?
Ans. 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).

Q.13 When to Use Session Beans ?
Ans. 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.

Q.14 When to use Stateful session bean?
Ans. 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.

Q.15 When to use a stateless session bean?
Ans. 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.


Post a Comment

Free Website templateswww.seodesign.usFree Flash TemplatesRiad In FezFree joomla templatesAgence Web MarocMusic Videos OnlineFree Wordpress Themeswww.freethemes4all.comFree Blog TemplatesLast NewsFree CMS TemplatesFree CSS TemplatesSoccer Videos OnlineFree Wordpress ThemesFree CSS Templates Dreamweaver
This post confirms my ownership of the site and that this site adheres to Google AdSense program policies and Terms and Conditions: ca-pub-0558527597907982 nitin jain a 24 c.c colony opp r.p bagh delhi