Professional Documents
Culture Documents
Q.1. What is EJB (Enterprise Java Bean)? Explore the EJB life cycle. What exactly is
an EJB container?
Explain the uses of EJB as well as its benefits and drawbacks
A.1.
Enterprise JavaBeans (EJB) is a server-side component architecture for building
distributed, scalable, and transactional enterprise applications using Java. EJB
provides a set of specifications that define a standardized way to develop reusable
and interoperable business components.
The life cycle of an EJB involves several stages:
2. Activation: Once the EJB instance is created, it becomes active and ready to
process requests from clients.
3. Passivation: When the EJB instance is idle or the container needs to reclaim
resources, it may be passivated. In this state, the instance's state is stored and
can be activated again when needed.
4. Removal: At some point, an EJB instance may be removed from the container,
typically due to explicit removal by the client or container shutdown.
The EJB container plays a crucial role in managing the execution and life cycle of
EJB components. It provides services such as transaction management, security,
concurrency control, and resource pooling. The container is responsible for creating
and destroying EJB instances, handling concurrency, managing transactions, and
providing access to external resources like databases or messaging systems. It
shields the developer from low-level concerns, allowing them to focus on business
logic implementation.
The uses of EJB include:
Assignment - 4 1
components to be deployed on different machines.
Benefits of EJB:
Drawbacks of EJB:
1. Complexity: EJB has historically been criticized for its complexity, steep learning
curve, and verbose APIs, although newer versions have addressed some of
these concerns.
Assignment - 4 2
b.Entity Bean
c.Message Driven Bean
A.3.
a. Session Bean:
A session bean represents a single client's interaction with the EJB container. It
encapsulates business logic and represents a transient conversation or session
between a client and the server. Session beans can be of two types:
ii. Stateless Session Bean (SLSB): A stateless session bean doesn't preserve
conversational state between method invocations. It is designed to be stateless,
allowing multiple clients to access the bean concurrently. SLSBs are commonly used
to encapsulate business logic and perform operations that don't require maintaining
client-specific state.
b. Entity Bean:
Entity beans represent persistent data in a database and provide an object-relational
mapping. However, starting from EJB 3.0, the entity bean model has been
deprecated, and the Java Persistence API (JPA) is now the preferred approach for
dealing with persistence. In earlier versions, there were two types of entity beans:
ii. Bean-Managed Persistence (BMP) Entity Bean: Developers are responsible for
managing the persistence and mapping of BMP entity beans. They explicitly define
the database operations and queries required for managing the entity's state.
Assignment - 4 3
Q.5. What is Java Database Connectivity (JDBC)? Explain all four types of JDBC
driver connectivity and provide a comparative table.
A.5.
Java Database Connectivity (JDBC) is a Java API that provides a standard way for
Java applications to interact with databases. It enables developers to execute SQL
statements, retrieve and manipulate data, and manage database connections.
JDBC drivers are responsible for establishing the connection between Java
applications and databases. There are four types of JDBC drivers, each with its own
connectivity mechanism:
Description: This driver uses the Open Database Connectivity (ODBC) API
to connect to databases. It translates JDBC calls into ODBC calls, allowing
Java applications to interact with databases that support ODBC.
Assignment - 4 4
middleware handles the translation.
3. Rolling Back a Transaction: The rollback() method is used to roll back the
changes made during a transaction. If an error occurs or if you decide to
discard the changes made within the transaction, calling this method will
revert the database to its previous state.
Assignment - 4 5
By using transaction management in JDBC, you can ensure the following:
Assignment - 4 6