You are on page 1of 4

1. What is the role of EJB in J2EE?

2. What is the difference between EJB and JavaBeans?


3. The EJB container manages the following services:
 Transactions
 Persistence
 EJB instance pooling
 Security
 Concurrent access (or multi-threading)
 Remote access
4. What are the services provided by EJB container?
 Life cycle management of Enterprise Java beans (EJB).
 Container managed transaction
 Container managed persistent
 Security etc
5. What is the difference between JNDI context, Initial context, session context and EJB context?
JNDI context: Provides mechanism to lookup resources on network.
Initial Context: Provides initial context to resources.
Session Context: It has all the information available which is required to session bean from
container.
EjbContext: It contain information which is required to both session and entity bean.
6. What is an EJB Context?
EJBContext is an interface implemented by the container. It is a part of the bean-container
contract.
EntityContext: This is a sub-class of EJBContext that Entity beans use.
SessionContext: Session beans use this subclass.
These EJBContext objects provide the bean class with information about its:
- Container,
- Client using the bean,
- Bean itself.
7. What are the different kinds of enterprise beans available?
8. What is the difference between stateful and stateless session beans?
9. What is the difference between Container Managed Persistence (CMP) and Bean Managed
Persistence (BMP) entity beans?
10. How does an EJB interact with its container?
11. What are the call-back methods in entity beans?
public void ejbLoad();
public void ejbStore();
public void ejbActivate();
public void ejbPassivate();
public void ejbRemove();
12. JNDI used in EJB?
Java Naming and Directory Interface allow EJB to access resources like JDBC connections, JMS
topics and queues, other EJBs etc.
13. What are transactional attributes? What are isolation levels?
14. What is a distributed transaction? What is a 2-phase commit?
15. Explain exception handling in EJB?
16. What is the difference between optimistic and pessimistic concurrency control?
Pessimistic Concurrency
A pessimistic design assumes conflicts will occur in the database tables and avoids them through
exclusive locks etc.
EJB (also non-EJB) locks the source data until it completes its transaction.
 Provides reliable access to data.
 Suitable for short transactions.
 Suitable for systems where concurrent access is rare.
The pessimistic locking imposes high locking overheads on the server and lower concurrency.

Optimistic Concurrency
An optimistic approach assumes conflicts won’t occur, and deal with them when they do occur.
EJB (also non-EJB) implements a strategy to detect whether a change has occurred. Locks are
placed on the database only for a small portion of the time.
 Suitable for long transactions.
 Suitable for systems requiring frequent concurrent accesses.
The optimistic locking is used in the context of cursors. The optimistic locking works as follows:
 No locks are acquired as rows are read.
 No locks are acquired while values in the current row are changed.
 When changes are saved, a copy of the row in the database is read in the locked mode.
 If the data was changed after it was read into the cursor, an error is raised so that the
transaction can be rolled back and retried.
17. How can we determine if the data is stale (for example when using optimistic locking)?
We can use the following strategy to determine if the data is stale:
 Adding version numbers
 Add a version number (Integer) to the underlying table.
 Carry the version number along with any data read into memory (through value
object, entity bean etc).
 Before performing any update compare the current version number with the
database version number.
 If the version numbers are equal update the data and increment the version
number.
 If the value object or entity bean is carrying an older version number, reject the
update and throw an exception.
 Adding a timestamp to the underlying database table.
 Comparing the data values.
18. EJB invocation is based upon which design pattern? What is Service locator design pattern?
19. How do you call Enterprise Java beans from Servlet or JSP?
20. Does EJB 3.0 support dependency Injection?
21. What are the rules 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 the business methods.
It contains a public constructor with no parameters.
It must not define the finalize method.
22. How can i maintain a user session between servlets and stateful session ejbs?
23. 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?
24. What is 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.
25. What is the difference between JMS and RPC?
RPC uses synchronous messaging while JMS uses asynchronous messaging approach.
In RPC the method invoker waits for the method to finish execution and return the control back
to the invoker.
In JMS the message sender just sends the message to the destination and continues it's own
processing.
26. What is Remote Procedure Calls, RPC?
In distributed systems, a client calls a procedure stored on a server. This is called calling a
remote procedure stored on a server. Though, the call is made as if the procedure was stored on
the local machine.
The steps in which a RPC is made are:
 The client calls the procedure
 The client stub builds the message.
 The message is sent over the network.
 The Server OS gives the message to the server stub.
 The server stub unpacks the message.
 The stub makes a local call to the procedure.
 The server does the work and returns the result to the server stub.
 The stub packs the message and traps to the kernel.
 The remote kernel sends the message the client kernel.
 The client kernel gives the message to the client stub.
 The client stub unpacks the result and gives to the client.
27. Explain how RMI clients contact remote RMI servers?
 The client procedure calls the client stub in the normal way.
 The client stub builds a message and traps to the kernel.
 The kernel sends the message to the remote kernel.
 The remote kernel gives the message to the server stub
 The server stub unpacks the parameters and calls the server.
 The server does the work and returns the result to the stub.
 The server stub packs it in a message and traps to the kernel.
 The remote kernel sends the message to the clients kernel.
 The clients’ kernel gives the message to the client stub.
 The stub unpacks the result and returns to the client.

You might also like