1. Architectures and Protocols
2. Applicability and Best Practices
3. Servlets
4. JSP
5. EJB
6. Internationalization and Localization
7. Design Patterns
8. Messaging
9. Security and Legacy Connectivity
HR Questions
INDEX
136: Explain how to create remote interface for stateful session bean.
Answer:
We can create remote interface for stateful session bean as follows:
import java.rmi.*;
import javx.ejb.*;
public interface MySFSRemote extends EJBObject {
public int size() throws RemoteException;
}
When the client wants to call an EJB object, they have to use this remote interface. The EJB container is responsible for delegating the call to the actual bean code.
137: Explain how to create a stateful session bean class.
Answer:
We can create stateful session bean class as follows:
import javax.ejb.*;
public class MySFSBean implements SessionBean {
private SessionContext sContext;
private int iCount;
public void ejbCreate (int myParam) throws CreateException {
this.iCount = myParam;
}
public void ejbActivate() {}
public void ejbPassivate() {}
public void ejbRemove() {}
public int size() {
return iCount;
}
}
In the above code, when the bean is created, the counter is assigned with the parameter value. As per the specification, we have to implement all the methods ejbRemove, ejbActivate, and ejbPassivate along with the business method ‘size’.
138: What are accessor methods?
Answer:
When we use container managed persistence, in order to make access to data storage, we don’t use direct read and write methods. Instead, we use get and set methods which are called as the accessor methods.
For example getName() and setName(String name) are accessor method for the field ‘name’.
139: Explain EntityContext.
Answer:
The entity bean instance is provided by EJB container with the help of EntityContext. The EntityContext provides access to any object reference associated with the entity bean instance including EJB Objects, EJB Local Objects, and primary key objects.
The access to EJB Objects, EJB Local Objects and primary key objects is provided by getEJBObject(), getEJBLocalObject(), and getPrimaryKey() method.
140: Explain getEJBHome, getEJBLocalHome, and getCallerPrinipal methods.
Answer:
getEJBHome(): The remote home interface of the enterprise entity bean is returned by this method.
getEJBLocalHome(): The local home interface of the enterprise entity bean is returned by this method.
getCallerPrincipal(): This method identifies which invokes the bean instance’s EJB object.
141: Explain getRollBack, setRollBack, and getUserTransaction methods.
Answer:
getRollBack(): Using this method, we can identify whether the existing transaction for a bean instance has been set as rollback.
setRollBack(): Using this method, we can set the bean instance of a particular transaction outcome as rollback.
getUserTransaction(): This method should not be called by entity bean instances as this method returns javax.transaction.UserTransaction interface.
142: Explain Transaction.
Answer:
Transaction is a task that executes a single unit of work or atomic operation. If the task is not performed successfully, the transaction will be reverted or rolled back.
Transactions are often referred as ACID acronym. ACID refers to Atomicity, Consistency, Isolation, and Durability.
143: What are the transaction attributes available for container managed transaction?
Answer:
The following are the container managed transaction attributes:
a) Required: In this, the container starts a new transaction if the transaction does not exist
b) RequiresNew: In this, the container creates new transaction for each method call
c) Supports: In this, the bean can execute without transaction
d) NotSupported: In this, the bean cannot be invoked with in a transaction
e) Never: In this, the bean will never execute a transaction
f) Mandatory: In this, each method call requires a transaction context
144: How does container manage multiple transactions?
Answer:
The EJB container manages multiple transactions by the following two ways:
a) The EJB container instantiate multiple instances of enterprise bean thereby allowing database to handle any issues related to transaction processing
b) The EJB container acquires exclusive lock on the enterprise bean instance’s database state thereby serializing access to the instance from multiple transactions
145: Explain JTS.
Answer:
JTS refers to Java Transaction Service. It specifies the transaction manager implementation of Java Transaction API (Application Programming Interface).
It supports distributed transactions i.e. multiple database on multiple systems supported by multiple transaction managers. Using JTS, the container makes sure that the transaction can span through multiple containers.
146: What are the services provided by EJB container?
Answer:
EJB container provides the following services:
a) Transaction Management: The container manages start, enrollment, rollback, and transaction commitment
b) Lifecycle Management: It includes bean creation, destroy, activate and passivate
c) Persistence: The beans do not explicitly retrieve or store data from database but do so with the help of container
d) State Management: The container automatically manages state of the bean object
e) Remote Access (Distributed): The container supports distributed remote access with the help of RMI and IIOP protocols
f) Security: The container performs automatically all security checks on behalf of enterprise beans
147: What are the benefits of EJB framework as architecture?
Answer:
The following are the benefits of EJB framework as architecture:
a) The EJB architecture is distributed, scalable, portable, transactional, multi tired, and secure
b) The server for EJB automatically manages services such as threading, lifecycle, transaction, and persistence for the enterprise bean component
c) The enterprise bean components are platform independent i.e. they can be executed on any operating system
d) The EJB components contain only business logic; thereby developers are given freedom to maintain system level code







