Home Java Technology EJB EJB Sample Interview Questions - 5

Login Form




EJB Sample Interview Questions - 5 Print E-mail

1. Can the primary key in the entity bean be a Java primitive type such as int?
Answer: The primary key can't be a primitive type--use the primitive wrapper classes, instead.For example, you can use java.lang.Integer as the primary key class, but not int (it has to be a class, not a primitive)

2. What is the difference between Message Driven Beans and Stateless Session beans?
Answer: In several ways, the dynamic creation and allocation of message-driven bean instances mimics the behavior of stateless session EJB instances, which exist only for the duration of a particular method call.However, message-driven beans are different from stateless session EJBs (and other types of EJBs) in several significant ways:Message-driven beans process multiple JMS messages asynchronously, rather than processing a serialized sequence of method calls.Message-driven beans have no home or remote interface, and therefore cannot be directly accessed by internal or external clients.Clients interact with message-driven beans only indirectly, by sending a message to a JMS Queue or Topic.Note: Only the container directly interacts with a message-driven bean by creating bean instances and passing JMS messages to those instances as necessary.The Container maintains the entire lifecycle of a message-driven bean; instances cannot be created or removed as a result of client requests or other API calls.

3. What is Session Bean?
Answer: A session bean is a non-persistent object that implements some business logic running on the server.

4. What are transaction isolation levels in EJB?
Answer: The transaction isolation levels in EJB are:

  • Transaction_read_uncommitted
  • Transaction_read_committed
  • Transaction_repeatable_read

5. What is the difference between Message Driven Beans and Stateless Session beans?
Answer: Message-driven beans are different from stateless session EJBs in several significant ways:
Message-driven beans process multiple JMS messages asynchronously, rather than processing a serialized sequence of method calls.
Message-driven beans have no home or remote interface, and therefore cannot be directly accessed by internal or external clients.Clients interact with message-driven beans only indirectly, by sending a message to a JMS Queue or Topic.
Only the container directly interacts with a message-driven bean by creating bean instances and passing JMS messages to those instances as necessary.
The Container maintains the entire lifecycle of a message-driven bean; instances cannot be created or removed as a result of client requests or other API calls.

6. What is Ripple Effect?
Answer: The process of propagating the changes in the properties of a server group during runtime to all the associated clones is called Ripple Effect.


7. Is it legal to have static initializer blocks in EJB?
Answer: Although technically it is legal, static initializer blocks are used to execute some piece of code before executing any constructor or method while instantiating a class.Static initializer blocks are also typically used to initialize static fields - which may be illegal in EJB if they are read/write - In EJB this can be achieved by including the code in either the ejbCreate(), setSessionContext() or setEntityContext() methods.

8. What is an EJB Context?
Answer: 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.

9. Does RMI-IIOP support code downloading for Java objects sent by value across an IIOP connection in the same way as RMI does across a JRMP connection?
Answer: Yes.The JDK 1.2 support the dynamic class loading.
What is the difference between a "Coarse Grained" Entity Bean and a "Fine Grained" Entity Bean?
Answer: A 'fine grained' entity bean is pretty much directly mapped to one relational table, in third normal form.A 'coarse grained' entity bean is larger and more complex, either because its attributes include values or lists from other tables, or because it 'owns' one or more sets of dependent objects.Note that the coarse grained bean might be mapped to a single table or flat file, but that single table is going to be pretty ugly, with data copied from other tables, repeated field groups, columns that are dependent on non-key fields, etc.Fine grained entities are generally considered a liability in large systems because they will tend to increase the load on several of the EJB server's subsystems (there will be more objects exported through the distribution layer, more objects participating in transactions, more skeletons in memory, more EJB Objects in memory, etc.)

10. Can an EJB send asynchronous notifications to its clients?
Answer: Asynchronous notification is a known hole in the first versions of the EJB spec.The recommended solution to this is to use JMS, which is becoming available in J2EE-compliant servers.The other option, of course, is to use client-side threads and polling.This is not an ideal solution, but it's workable for many scenarios.