Won Contests Let Us Talk Mail Me Light of Knowledge


 E nterprise Java Beans - EJB
  
 Java Beans Components and Enterprise Beans

     JavaBeans components and enterprise beans are not the same. Although both components are written in the Java programming language, they are not interchangeable. JavaBeans components define a convention for making a Java class instance customizable by design tools, allowing the tools to link these customized objects via events. Enterprise beans implement multi-user, transactional services.

     We will build up a small EJB program which will calculate
1) my income = my salary + part time work + tips taken during work and with this income , i assume
2) my expense is 2000 , find my savings = income - expense

 
 Coding the Enterprise Bean : The EJB interfaces
Each EJB provides some interfaces that its clients use to work with the EJB.

Remote Interface

The remote interface is the business end of the EJB. This is the set of actual services provides by the EJB. (or)

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

Example : C:\myejb\myRemote.java
	import javax.ejb.EJBObject;
	import java.rmi.RemoteException;

	public interface myRemote extends EJBObject 
	{
		//Business Methods called by Client
		public double find_income(double salary, double part_time_jobs, double tips) 
			throws RemoteException;
		public double find_savings(double income, double expense) 
			throws RemoteException;		
	}
Home Interface

The home interface is the book-keeping interface. It helps clients create a new instance of an EJB, or to find an existing instance of an EJB.
The methods used to find existing EJBs are known as "finder" methods. Since session beans are not designed to be shareable, there are no session bean finder methods. (or)

A home interface defines the methods that allow a client to create, find, or remove an enterprise bean .
The Home interface contains a single create() method, which returns an object of the remote interface type

Example : C:\myejb\myHome.java
	import java.io.Serializable;
	import java.rmi.RemoteException;
	import javax.ejb.CreateException;
	import javax.ejb.EJBHome;

	public interface myHome extends EJBHome 
	{
		myRemote create() throws RemoteException, CreateException;
	} 
Implementation

The home interface doesn't actually need an implementation! This is because its tasks are straightforward enough that the EJB container can automatically provide the implementation.
The remote interface, however, needs an implementation which is supplied by the EJB programmer.

Example : C:\myejb\myEJB.java
	import java.rmi.RemoteException; 
	import javax.ejb.SessionBean;
	import javax.ejb.SessionContext;

	public class myEJB implements SessionBean
	{ 
		public double find_income(double salary, double part_time_jobs, double tips) 
		{
			return ( salary+part_time_jobs+tips ) ;
		}
		public double find_savings(double income, double expense) 
		{
			return (income-expense);
		}
		public myEJB() {}
		public void ejbCreate() {}
		public void ejbRemove() {}
		public void ejbActivate() {}
		public void ejbPassivate() {}
		public void setSessionContext(SessionContext sc) {}
	}
 Compile : Create a Batch File C:\myejb\compileEJB.bat
set J2EE_HOME=C:\j2sdkee1.3.1
set CPATH=C:\j2sdkee1.3.1\lib\j2ee.jar
javac -classpath %CPATH% myRemote.java myHome.java myEJB.java
C:\myejb\>compileEJB

 NEXT >> Creating the J2EE Application
 My Dream to be your Friend and Create a Group of Intelligent and Understanding Programmers
     If you like this article and/or code mailme or Join our small Java User Group which is by the Programmers for the Programmers ,
Till we meet next time BYE      Kind Regards - James Smith

  Java, J2EE, J2SE and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc.
in the United States and other countries.