aarya 1 Junior Poster

Intro

Today more and more developers want to write distributed transactional applications for the enterprise and leverage the speed, security, and reliability and server-side technology. If you are already working in this area, you know that in today’s fast moving and demanding world e –commerce and information technology, enterprise have to be designed, built, and produced for less money, with greater speed, and with fewer resources than ever before.

To reduce costs and fast-track enterprise application design and development, the java 2 platform enterprise editions (J2EE) technology provides a component-based approach to the design, development, assembly and deployment of enterprise applications. The J2EE platform offers a multi-development, assembly and deployment of enterprise applications. The J2EE platform offers a multitiered distributes application model, the ability of reuse components, integrated extensible markup language (XML) based data interchange, a unified security model, and flexible transaction control. Not only can you deliver innovative customer solutions to market faster than ever, but also your platform independent J2EE components-based solutions are not tied to the product enjoy the freedom to choose the products and components that best meet their business and technological requirements.

Distributes multi-tired applications

The J2EE platform uses multi-tired distributed application model. Application logic is divided into components according to function, and various application components that make up a J2EE application are installed on different mechanism depending on the tier in the multi-tired J2EE environment to which the application components belongs.

Client-tier components run on the client machines

We-tier components run on J2EE server

Business-tier components run on the J2EE server

Enterprise information system (EIS)-tier software runs on the EIS server
J2EE multi-tired applications are generally considered to be three-tired applications because they are distributed over three different locations: client machines, the J2EE server machine, and the database or legacy machines ate the back end.

J2ee components

J2EE applications are made up of components. A J2EE component is a self-contained functional software unit that is assembled into a J2EE application with its related classes and files and that communicates with other components. The J2EE specification defines the following J2EE components.

Application clients and applets are components that run on the client

Java servlet and JSP technology are web components that run on the server


Enterprise JavaBeans (EJB) components are business components that run on the server

Creating the enterprise bean

An enterprise bean is a server-side component that contains the business logic of an application. At runtime, the application clients execute the business logic of an application clients execute the business logic by invoking the enterprise bean’s methods.

Coding the enterprise bean

The enterprise bean in this example requires the following code:

Remote interface

Home interface

Enterprise bean class

Coding the remote interface

A remote interface defines the business methods that a client may call. The business methods are implemented in the enterprise bean code.

The source code for the converter remote interface follows

import javax.ejb.EJBObject;
import java.rmi.RemoteException;
import java.math.*;
public interface converter extends EJBObject
{
public BigDecimal dollerToYen(BigDecimal dollers) throws RemoteException;
public BigDecimal yetToEuro(BigDecimal yen) throws RemoteException;
}

Coding the home interface

The home interface defines that methods that allow a client to create, find or remove an enterprise bean the convertercome interface contains a single create methods, which returns an object of the remote interface type. Here is the source code of the converterhome interface

import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EjbHome;
public interface ConverterHome extends EJBHome
{
Converter create() throws RemoteException,CreateEXception;
}

Coding te enterprise Bean class

The enterprise bean class for this example is called ConverterBean. This class implements the two business methods, dollerToyen and yenToEuro, that the converter remote interface defines. The source code for the ConverterBean class follows

import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import java.math.*;
public class ConverterBean implements SessionBean
{
BigDecimal yenRate=new BigDecimal("121.6000");
BigDecimal euroRate=new BigDecimal("0.0077");
public BigDecimal dollerToYen(BigDecimal dollars)
{
BigDecimal result=dollorsmultiply(yenRate);
return result.setScale(2,BigDecimal.ROUND_UP);
}
public ConverterBean()  {}
public void ejbCreate()  {}
public void ejbRemove() {}
public void ejbActive()   {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc){}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.