Sunday, September 6, 2009

EJB interview Questions

Does stateless Session bean create() method contain any parameters?
Stateless SessionBean create() method doesnot contain any parameters and the syntax is as follows:
public interface XSessionEJBHome extends EJBHome
{
XSessionEJB create() throws RemoteException, CreateException;
}

What is difference between EJB 1.1 and EJB 2.0?
The bulk of the changes in EJB 2.0 are found in the definition of a new CMP component model. It’s radically different from the old CMP model because it introduces an entirely new participant, the persistence manager, and a completely new way of defining container-managed fields, as well as relationships with other beans and dependent objects.

Can a Session Bean be defined without ejbCreate() method?
The ejbCreate() methods is part of the bean’s lifecycle, so, the compiler will not return an error because there is no ejbCreate() method.
However, the J2EE spec is explicit:
· the home interface of a Stateless Session Bean must have a single create() method with no arguments,
while the session bean class must contain exactly one ejbCreate() method, also without arguments.
· Stateful Session Beans can have arguments (more than one create method)

What is the difference between ejbCreate() and ejbPostCreate ?
The purpose of ejbPostCreate() is to perform clean-up database operations after SQL INSERTs (which occur when ejbCreate() is called) when working with CMP entity beans. ejbCreate() is called before database INSERT operations. You need to use ejbPostCreate() to define operations, like set a flag, after INSERT completes successfully.

Why does EJB needs two interfaces(Home and Remote Interface)
There is a pure division of roles between the two .
Home Interface is the way to communicate with the container which is responsible for creating , locating and removing beans and Remote Interface is the link to the bean that allows acces to all methods and members.

What are the optional clauses in EJB QL?
WHERE and ORDERBY clauses are optional in EJB QL where as SELECT and FROM are required clauses.

Can I invoke Runtime.gc() in an EJB?
You shouldn’t. What will happen depends on the implementation, but the call will most likely be ignored.

What is 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.

1

2

3

4

5

6

7

8

9

10

11

 

No comments:

Post a Comment