Enterprise Java Beans

September 21st, 2006 by uCertify Leave a reply »

Enterprise Java Beans (EJB) is a managed, server-side component architecture for modular construction of enterprise applications. The EJB specification is one of several Java APIs in the Java Platform, Enterprise Edition. EJB makes it much easier to partition and scale the application. It is a server-side model that encapsulates the business logic of an application whenever the application complexity grows or the number of concurrent users increases.

It frees the application developer to concentrate on programming only the business logic, while removing the need to write all the “plumbing” code required in any enterprise application development scenario. EJB allows the business functionality to be developed and then deployed independently of the presentational layer. It distinguishes the functionality that an application provides and the user interface that is used to invoke that functionality. There are three types of Enterprise Java Beans:

  1. Entity bean: An entity bean represents an entity such as an employer, student, etc. An entity bean is grammatically a noun. An instance of an entity bean holds a record in memory about a corresponding entity from a table in a database. For example, an instance of the Employer bean may hold name=XXX, age=23, while another instance may hold name=YYY, age =34. An entity bean also provides logic for accessing and manipulating entities in persistent storage. It provides synchronous communication between a bean and a client.
  2. Session bean: A session bean is a type of EJB (Enterprise JavaBean) that encapsulates the logic of a business process and business rules. There are two types of session beans, as classified on the basis of state mode, namely stateless session bean and stateful session bean. A state of an object refers to the value in the instance variable.

    A stateless session bean does not maintain a conversational state for a particular client, whereas a stateful session bean maintains a conversational state for a particular client.A stateful session bean is well suited for implementing a business task dedicated to a single client that maintains a conversational state between the bean and the client. For example, a stateful session bean is required to build an online shopping cart in an e-commerce application. The information is maintained during a session. It is based on multiple calls from the client. The information includes: customerid, a list of items, customer buys, etc.

  3. Message driven beans: A message-driven bean is a type of EJB (Enterprise JavaBean) that provides asynchronous communication. A message-driven bean’s instance handles only one client message at a time. The message from the client arrives through JMS (Java Message Service) and is transferred to the message-driven bean’s instance via the EJB container.

The Enterprise beans uses the services provided by the EJB container. However, it is restricted to perform certain operations to avoid conflicts. The limitations of Enterprise Beans are as follows:

  1. Managing or synchronizing threads
  2. Loading a native directory
  3. Accessing the files and directories with the java.io package
  4. Use of the AWT functionality such as displaying information from a keyboard
  5. Using sockets or multicasting, accepting connections on a socket
  6. Setting a socket factory used by Server Socket

An enterprise bean benefits from many services, such as lifecycle management and security, that are provided implicitly by the EJB container. An enterprise bean benefits by looking up JNDI entries. A bean can use JNDI calls to retrieve references to resources, environment variables, references to other beans. The benefits of Enterprise Java Beans are as follows:

  1. Component portability
  2. Superior transaction management
  3. Superior workload management
  4. Multitier technology
  5. Versatility and scalability
  6. Customization
  7. Architecture independence

The following table depicts the difference between the Java beans and Enterprise java beans:


Java BeansEnterprise Java Beans
Java Beans create user objects, which are based on existing objects. An EJB is NOT used to customize existing objects

JavaBeans may be visible or nonvisible at runtime. It can be a visual component such as button, chart, etc.An EJB is a nonvisual, remote object.
JavaBeans are not typed.EJBs are of three types; session beans, message driven beans, and entity beans.
JavaBeans are intended to be local to a single process and are primarily intended to run on the client side. EJBs are remotely executable components or business objects that can be deployed only on the server.
JavaBeans have an external interface called the Properties interface, which allows a builder tool to interpret the functionality of the bean.EJBs have a deployment descriptor that describes its functionality to an external builder tool or IDE.
JavaBeans is a component technology to create generic Java components that can be composed together into applets and applications.EJB is a component technology. It neither builds upon nor extends the original JavaBean specification.
JavaBeans may have BeanInfo classes, property editors, or customizers.EJBs have no concept of BeanInfo classes, property editors ,or customizers and provide no additional information other than that described in the deployment descriptor.
No explicit support exists for transactions in JavaBeans.EJBs may be transactional and the EJB Servers provide transactional support.
Component bridges are available for JavaBeans. For example, a JavaBean can also be deployed as an ActiveX control. An EJB cannot be deployed as an ActiveX control because ActiveX controls are intended to run at the desktop and EJBs are server side components.

The EJB specification was originally developed in 1997 by IBM and later adopted by Sun Microsystems (EJB 1.0 and 1.1) and enhanced under the Java Community Process as JSR 19 (EJB 2.0), JSR 153 (EJB 2.1) and JSR 220 (EJB 3.0). The EJB specification is one of several Java APIs in the Java Platform, Enterprise Edition. EJB is a server-side model that encapsulates the business logic of an application. The new features of EJB 2.1 are as follows:

  1. Message-driven Bean Enhancements: It can now accept messages from sources other than JMS. The configuration of the MDB is done with a new tag, and by specifying “configuration properties” with the tag . This contains arbitrary name/value pairs that are specific to the messaging service being used. It is more versatile than being forced to use JMS-specific tags, like <message-selector>.
  2. EJB-QL Enhancements: EJB 2.1 extends its language to make it more SQL-like by adding few clauses and aggregate functions to the language.
  3. Web Services support: In EJB 2.1, the EJB can be used as if it were a Web service, and an EJB directly accessing a Web service. A stateless session EJB can now be accessed through a Web service. In order to do that, the client must use SOAP over HTTP or HTTPS, and use a WSDL descriptor. The new EJB 2.1 specification introduces the concept of a Web service reference. This is exactly the same concept as environment entries, EJB references, and resource references. Adding a Web service reference in ejb-jar.xml is done using the new tag . It is up to the container provider to map the reference to the actual Web service location. The reference can be looked up in the bean implementation, and the resulting factory object can be used to connect to the Web service.
  4. EJB Timer Service: The new EJB 2.1 timer service is a mechanism to enable time-based business logic. It provides services such as run a certain query in five minutes, delete the content of the “garbage can” database table two hour from now, post an email saying “server shutdown in 1 hour” to all employees, send a usage report to the administrator every Sunday at 6 p.m., etc.
  5. EJB containers must now support the newest specifications: J2SE 1.4, JMS 1.1, JavaMain 1.3, and JAX-RPC 1.0.
  6. The ejb-jar.xml standard deployment descriptor is now specified with XML schema, rather than DTD.
  7. Message destinations have been added.

The following table depicts the differences between the session bean and the entity bean:

Session BeanEntity Bean
It represents a single conversation with a client. It encapsulates an action or actions to be taken on business data.It encapsulates persistent business data.
It is not re-entrant.It may be re-entrant.
It persists only for the life of the conversation with the client. It persists beyond the life of a client instance. Persistence can be container-managed or bean-managed.
It is not recoverable if the EJB server fails, it may be destroyed.It is recoverable; it survives failures of the EJB server.
It may be stateful or stateless. It is typically stateful.
It may or may not be transactional. If transactional, can manage its own OTS transactions, or use container-managed transactions.It may or may not be transactional. Must use the container-managed transaction model.
The state of a transactional, stateful session bean is not automatically rolled back on transaction rollback. Stateless session bean that manages its own transactions and begins an OTS transaction must commit (or roll back) the transaction in the same method in which it was started.If transactional, its state is automatically rolled back on transaction rollback.

Download free practice test for SUN SCJA exam. Download practice question and study guide for CX310-019 for exam.
Like this article? Share it with others
If you like this article, please leave a comment or subscribe this blog via RSS or via e-mail, Bookmark and share through your network. Click the AddThis button below. Thanks.
  • Share/Bookmark
Advertisement

Leave a Reply

uCertify.com | Our Company | Articles | Contact Us | News and Press Release | uCertify India | Entries (RSS)
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD    Cisco Certification: CCNA, CCENT    A+, Network+, Security+ Project+
Oracle Certification: OCP 11g, OCP 10g, OCA 11g, OCA 10g    CIW foundation    EC-212-32,    CISSP    Photoshop ACE CS4    Adobe Flash ACE, PMP, CAPM
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.