R4R
Right Place For Right Person TM
 
R4R Java EJB EJB FAQs EJB Subjective Questions and Answers

 


Tolal:149 Click: 1 2 3 4 5 6 7 8
Previous Home Next

EJB Interview Questions And Answers

Page 1

Ques: 1 What is the need of Remote and Home interface. Why cant it be in one? 

Ans:
The main reason is because there is a clear division of roles and responsabilities between the two interfaces. The home interface is your way to communicate with the container, that is who is responsable of creating, locating even removing one or more beans. The remote interface is your link to the bean, that will allow you to remotely access to all its methods and members. As you can see there are two distinct elements (the container and the beans) and you need two different interfaces for accessing to both of them.

Ques: 2 What is architecture of EJB?

Ans:
Session beans: Session beans are non-persistent enterprise beans. They can be stateful or stateless. A stateful session bean acts on behalf of a single client and maintains client-specific session information (called conversational state) across multiple method calls and transactions. It exists for the duration of a single client/server session. A stateless session bean, by comparison, does not maintain any conversational state. Stateless session beans are pooled by their container to handle multiple requests from multiple clients. Entity beans: Entity beans are enterprise beans that contain persistent data and that can be saved in various persistent data stores. Each entity bean carries its own identity. Entity beans that manage their own persistence are called bean-managed persistence (BMP) entity beans. Entity beans that delegate their persistence to their EJB container are called container-managed persistence (CMP) entity beans. Message-driven beans: Message-driven beans are enterprise beans that receive and process JMS messages. Unlike session or entity beans, message-driven beans have no interfaces. They can be accessed only through messaging and they do not maintain any conversational state. Message-driven beans allow asynchronous communication between the queue and the listener, and provide separation between message processing and business logic. Remote client view The remote client view specification is only available in EJB 2.0. The remote client view of an enterprise bean is location independent. A client running in the same JVM as a bean instance uses the same API to access the bean as a client running in a different JVM on the same or different machine. Remote interface: The remote interface specifies the remote business methods that a client can call on an enterprise bean. Remote home interface: The remote home interface specifies the methods used by remote clients for locating, creating, and removing instances of enterprise bean classes. Local client view The local client view specification is only available in EJB 2.0. Unlike the remote client view, the local client view of a bean is location dependent. Local client view access to an enterprise bean requires both the local cleint and the enterprise bean that provides the local client view to be in the same JVM. The local client view therefore does not provide the location transparency provided by the remote client view. Local interfaces and local home interfaces provide support for lightweight access from enterprise bean that are local clients. Session and entity beans can be tightly couple with their clients, allowing access without the overhead typically associated with remote method calls. Local interface: The local interface is a lightweight version of the remote interface, but for local clients. It includes business logic methods that can be called by a local client. Local home interface: The local home interface specifies the methods used by local clients for locating, creating, and removing instances of enterprise bean classes. EJB client JAR file An EJB client JAR file is an optional JAR file that can contain all the class files that a client program needs to use the client view of the enterprise beans that are contained in the EJB JAR file. If you decide not to create a client JAR file for an EJB module, all of the client interface classes will be in the EJB JAR file. EJB container An EJB container is a run-time environment that manages one or more enterprise beans. The EJB container manages the life cycles of enterprise bean objects, coordinates distributed transactions, and implements object security. Generally, each EJB container is provided by an EJB server and contains a set of enterprise beans that run on the server. Deployment descriptor A deployment descriptor is an XML file packaged with the enterprise beans in an EJB JAR file or an EAR file. It contains metadata describing the contents and structure of the enterprise beans, and runtime transaction and security information for the EJB container. EJB server An EJB server is a high-level process or application that provides a run-time environment to support the execution of server applications that use enterprise beans. An EJB server provides a JNDI-accessible naming service, manages and coordinates the allocation of resources to client applications, provides access to system resources, and provides a transaction service.

Ques: 3 What are different type of Java Bean?
Ques: 4 What is the difference between Container-Managed Persistent (CMP) Bean and Bean-Managed Persistent(BMP)?

Ans:
CMP -- Container-managed persistence beans are the simplest for the bean developer to create and the most difficult for the EJB server to support. This is because all the logic for synchronizing the bean's state with the database is handled automatically by the container. This means that the bean developer doesn't need to write any data access logic, while the EJB server is supposed to take care of all the persistence needs automatically. With CMP, the container manages the persistence of the entity bean. Vendor tools are used to map the entity fields to the database and absolutely no database access code is written in the bean class. BMP--bean-managed persistence (BMP) enterprise bean manages synchronizing its state with the database as directed by the container. The bean uses a database API to read and write its fields to the database, but the container tells it when to do each synchronization operation and manages the transactions for the bean automatically. Bean-managed persistence gives the bean developer the flexibility to perform persistence operations that are too complicated for the container or to use a data source that is not supported by the container.

Ques: 5 What is Container-Managed Persistent (CMP) Bean and Bean-Managed Persistent(BMP)?

Ans:
CMP -- Container-managed persistence beans are the simplest for the bean developer to create and the most difficult for the EJB server to support. This is because all the logic for synchronizing the bean's state with the database is handled automatically by the container. This means that the bean developer doesn't need to write any data access logic, while the EJB server is supposed to take care of all the persistence needs automatically. With CMP, the container manages the persistence of the entity bean. Vendor tools are used to map the entity fields to the database and absolutely no database access code is written in the bean class BMP--bean-managed persistence (BMP) enterprise bean manages synchronizing its state with the database as directed by the container. The bean uses a database API to read and write its fields to the database, but the container tells it when to do each synchronization operation and manages the transactions for the bean automatically. Bean-managed persistence gives the bean developer the flexibility to perform persistence operations that are too complicated for the container or to use a data source that is not supported by the container.

Ques: 6 What is Entity Bean?

Ans:
Entity beans: Entity beans are enterprise beans that contain persistent data and that can be saved in various persistent data stores. Each entity bean carries its own identity. Entity beans that manage their own persistence are called bean-managed persistence (BMP) entity beans. Entity beans that delegate their persistence to their EJB container are called container-managed persistence (CMP) entity beans.

Ques: 7 What are the methods of Entity Bean?

Ans:
1. setEntityContext() 2. ejbCreate() 3. unsetEntityContext() 4. ejbActivate() 5. ejbPassivate() 6. ejbRemove() 7. ejbPostCreate()

Ques: 8 What is an EJB Context?

Ans:
EJBContext is an interface that is implemented by the container, and it is also a part of the bean-container contract. Entity beans use a subclass of EJBContext called EntityContext. Session beans use a subclass called SessionContext. These EJBContext objects provide the bean class with information about its container, the client using the bean and the bean itself. They also provide other functions. See the API docs and the spec for more details.

Ques: 9 How EJB Invocation happens?

Ans:
Step 1: Using JNDI, retrieve Home Object reference from Naming Service Step 2: Send or return Home Object reference to the client. Step 3: Create a new EJB Object through Home Object interface. Step 4: Create EJB Object from the Ebb Object Step 5: Send or return EJB Object reference to the client. Step 6: Invoke business method using EJB Object reference. Step 7: Delegate request to Enterprise Bean. Steps to EJB invocation are: Retrieve Home Object reference from Naming Service via JNDI. Return Home Object reference to the client. Create a new EJB Object through Home Object interface. Create EJB Object from the EJB Object. Return EJB Object reference to the client. Invoke business method using EJB Object reference. Delegate request to Bean (Enterprise Bean).

Ques: 10 What are the callback methods in Entity beans?

Ans:
The bean class implements a set of callback methods that allow the container to notify the events in its life cycle. The call back methods available in Entity Bean are public void setEntityContext(); public void unsetEntityContext(); public void ejbLoad(); public void ejbStore(); public void ejbActivate(); public void ejbPassivate(); public void ejbRemove();

Ques: 11 Can Entity Beans have no create() methods?

Ans:
Entity Beans have no create() method, when entity bean is not used to store the data in the database. In this case entity bean is used to retrieve the data from database.But it's using the no create() method so we say that "Yes", In some cases the data is inserted NOT using Java application, so you may only need to retrieve the information, perform its processing, but not create your own information of this kind.

Ques: 12 What is bean managed transaction?

Ans:
bean-managed transactions, the bean specifies transaction demarcations using methods in the javax.transaction.UserTransaction interface. Bean-managed transactions include any stateful or stateless session beans with a transaction-type set to Bean. Entity beans cannot use bean-managed transactions. For stateless session beans, the entering and exiting transaction contexts must match. For stateful session beans, the entering and exiting transaction contexts may or may not match. If they do not match, the WebLogic Enterprise EJB container maintains associations between the bean and the nonterminated transaction. Session beans with bean-managed transactions cannot use the setRollbackOnly and getRollbackOnly methods of the javax.ejb.EJBContext interface.

Ques: 13 What are transaction attributes?

Ans:
The transaction attribute is a value associated with a method of a session or entity bean's home or component interface or with the onMessage(...) method of a message-driven bean. And the transaction attribute specifies how the Container must manage transactions for a method when a client invokes the method via the enterprise bean's home or component interface or when the method is invoked as the result of the arrival of a JMS message. Enterprise JavaBeans defines the following (SIX) values for the transaction attribute: NotSupported Required Supports RequiresNew Mandatory Never

Ques: 14 What are transaction isolation levels in EJB?

Ans:
Transaction_serializable- All the transactions for resource are performed serial. Transaction_read_uncommitted- Allows a method to read uncommitted data from a DB. Transaction_repeatable_read - Guarantees that all reads of the database will be the same during the transaction. Transaction_read_committed- Guarantees that the data you are getting has been committed.

Ques: 15 What is the difference between EJB2.1 and EJB3.0?

Ans:
No need of Home Interface (EJBHome),but it is needed in EJB2.0 No more confusions to make an EJB remote or local,it's the client which would decide and cast to appropriate. Just write SINGLE simple Java class and annotate it to be Stateless/Stateful/Entity/MessageDriven.Container No Deployment Descriptors , MetaData Annotations are explored which is introduced in J2SE5.0 Forget all EJB life cycles.For example Entity bean life cycle in 3.0 is new,managed,detached,removed. Ejb 3.0 siplifies the developement of the application Ready to develop complex query,inner/outer join with EJB3.0. The main difference lies in the persistence In case of EJB 3.0 there is JPA Java persistence API which makes the mapping of EntityBeans with the database easy with the help of a service called as EntityManager.

Ques: 16 How many types of session beans are?

Ans:
1.statefull beans 2.stateless beans

Ques: 17 What is Session Bean?
Ques: 18 Is it possible to share an HttpSession between a JSP and EJB? How?

Ans:
You can pass the HttpSession as parameter to an EJB method, only if all objects in session are serializable. This has to be consider as passed-by-value, that means that it?s read-only in the EJB. If anything is altered from inside the EJB, it won?t be reflected back to the HttpSession of the Servlet Container.The pass-by-reference can be used between EJBs Remote Interfaces, as they are remote references. While it is possible to pass an HttpSession as a parameter to an EJB object, it is considered to be bad practice in terms of object-oriented design. This is because you are creating an unnecessary coupling between back-end objects (EJBs) and front-end objects (HttpSession). Create a higher-level of abstraction for your EJBs API. Rather than passing the whole, fat, HttpSession (which carries with it a bunch of http semantics), create a class that acts as a value object (or structure) that holds all the data you need to pass back and forth between front-end/back-end. Consider the case where your EJB needs to support a non HTTP-based client. This higher level of abstraction will be flexible enough to support it.

Ques: 19 What happens when I change a value in the HttpSession from inside an EJB?

Ans:
You can pass the HttpSession as parameter to an EJB method, only if all objects in session are serializable.This has to be consider as ?passed-by-value", that means that it?s read-only in the EJB. If anything is altered from inside the EJB, it won?t be reflected back to the HttpSession of the Servlet Container.The ?pass-by-reference? can be used between EJBs Remote Interfaces, as they are remote references. While it IS possible to pass an HttpSession as a parameter to an EJB object, it is considered to be ?bad practice ? in terms of object oriented design. This is because you are creating an unnecessary coupling between back-end objects (ejbs) and front-end objects (HttpSession). Create a higher-level of abstraction for your ejb?s api. Rather than passing the whole, fat, HttpSession (which carries with it a bunch of http semantics), create a class that acts as a value object (or structure) that holds all the data you need to pass back and forth between front-end/back-end. Consider the case where your ejb needs to support a non-http-based client. This higher level of abstraction will be flexible enough to support it.

Ques: 20 Explain EJB container , EJBHome and EJBObject classes?

Ans:
EJB container An EJB container is a run-time environment that manages one or more enterprise beans. The EJB container manages the life cycles of enterprise bean objects, coordinates distributed transactions, and implements object security. Generally, each EJB container is provided by an EJB server and contains a set of enterprise beans that run on the server. EJB Home: When you write the source code for the EJB Home Interface, you must extend the interface EJBHome, and provide method signatures for all the desired create() and find() methods. An object that implements the Home Interface is automatically generated by the EJB Server tools. EJB Object: The "EJB Object", or Remote Object, is actually a Wrapper. It sits somewhere inside the container, between the client and your code. It is responsible for performing all the setup and shutdown tasks (like opening transactions, or restoring data state) immediately before and after your enterprise bean is called. The "EJB Object" is generated by the EJB Server tools -- you don't have to write any part of it. However, you do have to write another interface, called the "Remote Interface" or the "EJBObject Interface," that extends interface EJBObject, and provides method signatures for all the business methods. The server automatically generates a Java class that implements the Remote Interface; it is this object that is registered with RMI, and a reference to it is returned by the Home Interface (which we now know is actually a Factory Object).


Goto Page:

1 2 3 4 5 6 7 8
Share |

EJB Objective

EJB Objective Questions And Answers

EJB Interview Questions And Answers

EJB Interview Questions And Answers

R4R,EJB Objective, EJB Subjective, EJB Interview Questions And Answers,EJB,EJB Interview,EJB Questions ,EJB Answers

New Updates

R4R
R4R
R4R
R4R
R4R
R4R
R4R
R4R