11). What are the key benefits of the EJB technology?
1. Rapid application development
2. Broad industry adoption
3. Application portability
4. Protection of IT investment

12). Why do we have a remove method in both EJBHome and EJBObject?
With the EJBHome version of the remove, you are able to delete an entity bean without first instantiating it (you can provide a Primary Key object as a parameter to the remove method). The home version only works for entity beans. On the other hand, the Remote interface version works on an entity bean that you have already instantiated. In addition, the remote version also works on session beans (stateless and stateful) to inform the container of your loss of interest in this bean.
13). What are the services provided by container?
Container services are totally depends upon the "vendor implementation". But more or less most of the vendors suppots the basic services like,
LifeCycle Management - It is Automatic...
Resource Management-Creating and destroying the objects based the current load of requests for better usage of memory.
Session Management - it is used by Developer coded callback methods...
Transaction Management - it is used by configuring deployment
descriptor (DD) ...
Security management - it is used by configuring deployment descriptor (DD) ...
The other services, if any will be in advanced versions, and depends on Vendor specific.

14). Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the HttpSession from inside an EJB?

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 its 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 (1)? 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

15). What is the difference between a Coarse Grained? Entity Bean and a Fine Grained? Entity Bean?

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.)
16). Does Stateful Session bean support instance pooling?

Stateful Session Bean conceptually doesn't have instance pooling.
What is the difference between JavaBean and EJB?
A Java Bean is a software component written in the Java programming language that conforms to the JavaBeans component specification. The JavaBeans APIs became part of the "core" Java APIs as of the 1.1 release of the JDK.

The JavaBeans specification defines a Java-based software component model that adds a number of features to the Java programming language. Some of these features include:

* introspection
* customization
* events
* properties
* persistence

Enterprise JavaBeans (EJBs) are Java-based software components that are built to comply with Java's EJB specification and run inside of an EJB container supplied by a J2EE provider. An EJB container provides distributed application functionality such as transaction support,

17). What are the Interfaces need to create to implement Session Bean with Exmaple?

Session bean class (CartBean)
Home interface (CartHome)
Remote interface (Cart)

Session bean class (CartBean) :
public class CartBean implements SessionBean {

String customerName;
String customerId;
Vector contents;

public void ejbCreate(String person)
throws CreateException {

if (person == null) {
throw new CreateException("Null person not allowed.");
}
else {
customerName = person;
}

customerId = "0";
contents = new Vector();
}

public void ejbCreate(String person, String id)
throws CreateException {

if (person == null) {
throw new CreateException("Null person not allowed.");
}
else {
customerName = person;
}

IdVerifier idChecker = new IdVerifier();
if (idChecker.validate(id)) {
customerId = id;
}
else {
throw new CreateException("Invalid id: "+ id);
}

contents = new Vector();
}

public void addBook(String title) {
contents.addElement(title);
}

public void removeBook(String title) throws BookException {

boolean result = contents.removeElement(title);
if (result == false) {
throw new BookException(title + "not in cart.");
}
}

public Vector getContents() {
return contents;
}

public CartBean() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc) {}

}


Home Interface:
public interface CartHome extends EJBHome {
Cart create(String person) throws
RemoteException, CreateException;
Cart create(String person, String id) throws
RemoteException, CreateException;
}

The signatures of the ejbCreate and create methods are similar, but differ in important ways. The rules for defining the signatures of the create methods of a home interface follow.

The number and types of arguments in a create method must match those of its corresponding ejbCreate method.
The arguments and return type of the create method must be valid RMI types.
A create method returns the remote interface type of the enterprise bean. (But an ejbCreate method returns void.)
The throws clause of the create method must include the java.rmi.RemoteException and the javax.ejb.CreateException

Remote Interface :
public interface Cart extends EJBObject {

public void addBook(String title) throws RemoteException;
public void removeBook(String title) throws
BookException, RemoteException;
public Vector getContents() throws RemoteException;
}
The method definitions in a remote interface must follow these rules:

Each method in the remote interface must match a method implemented in the enterprise bean class.
The signatures of the methods in the remote interface must be identical to the signatures of the corresponding methods in the enterprise bean class.
The arguments and return values must be valid RMI types.
The throws clause must include the java.rmi.RemoteEx

18). How many EJB Objects are created for a Bean?

For a Session bean - one EJB object for one bean instance. For entity bean it depends, if 2 users are accessing one row at time then one EJB object is used for both the beans other wise for each bean one EJB object.

19). What are the parameters must follow for Session Bean ?

It implements the SessionBean interface.
The class is defined as public.
The class cannot be defined as abstract or final.
It implements one or more ejbCreate methods.
It implements the business methods.
It contains a public constructor with no parameters.
It must not define the finalize method.

20).When you will chose Stateful session bean and Stateless session bean?

Stateful session beans are used when there is converstional state and when there is a need of temporary storage

Stateless session bean are used when there is no conversational state and when session bean has to be used only for database access