You are on page 1of 11

EX.

NO:

Develop an Enterprise Java Bean for Banking operations Problem Definition:


To develop an Enterprise Java Bean for banking operations.

Problem Description:
Enterprise Java Beans(EJB) is a managed,server side component architecture for modular construction of enterprise applications. The EJB specification defines the roles played by the EJB container and the EJBs as well as how to deploy the EJBs in a container. EJB simplifies the development,deployment and access to deploy the EJBs in a container. The implementation class to be called the bean class, is instantiated at runtime and becomes a distributed object.

Procedure:
1. Create four programs- Bankbean, Bankhome, Bank, and Bankclient 2. In the Bankbean class first define the prototypes of the various methods 3. Next, provide the implementation for ejbCreate(), ejbPostCreate(), credit(), and debit() methods 4. In the Bankhome class just invoke the methods create() and findbyprimarykey() with the respective number of arguments 5. In the Bankremote class just define the prototypes of the various methods which throws the Remoteexception 6. In the Bankclient class, display the options to the user and use the lookup() method and perform the operations accordingly

Coding: BankBean.java
import javax.ejb.*; import java.rmi.*; public interface BankBean extends EJBObject { public int deposite(int a,int b)throws RemoteException; public int withdraw(int x,int y) throws RemoteException; }

BankHome.java
import java.rmi.*; import javax.ejb.*; public interface BankHome extends EJBHome { public BankHome create() throws RemoteException,CreateException; }

Bank.java
import javax.rmi.*; import javax.ejb.*; public class Bank implements SessionBean { public void ejbCreate(){} public void ejbActivate() {} public void ejbPassivate() {} public void ejbRemove() {} public void setSessionContext(SessionContext sc) {} public int deposite(int a,int b) { return(a+b); } public int withdraw(int x,int y) { return(x-y); } }

BankClient.java
import javax.naming.*; import javax.naming.*; import javax.rmi.*; import java.io.*; import java.util.*;

import javax.ejb.*; import javax.naming.Context; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject; public class BankClient { public static void main(String args[])throws Exception { Properties pro = new Properties(); pro.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFact ory"); pro.put(Context.PROVIDER_URL,"t3://localhost:7001"); Context c = new InitialContext(pro); Object o = c.lookup("BanC22"); BankClient h = (BankHome)PortableRemoteObject.narrow(o,BanB2.class); BankBean h1=h.create(); int a,b,x,y,z,e,d; a=10000; System.out.println("Banking Operations"); System.out.println("\n 1.DEPOSIT\n2. WITHDRAW\n3. EXIT "); do { DataInputStream m=new DataInputStream(System.in); z=Integer.parseInt(m.readLine()); if(z==1) { System.out.println("Enter the Deposit Amount:"); b = Integer.parseInt(m.readLine()); a = h1.deposite(a, b); System.out.println("Total Amount:Rs"+a); } else if(z==2) { System.out.println("\nEnter the Withdraw Amount");

y=Integer.parseInt(m.readLine()); a=h1.withdraw(a,y); System.out.println("Balance:Rs"+a); } else { System.exit(0); } } while(z<2); h1.remove(); } }

Steps:
Step1: Type the program and save it with .java extension to C:\bea folder Program Name BankRemote BankHome BankBean2 BankClient Description Remote Interface Home Interface Bean class Client program

Step2. Go to DOS prompt. Go to the folder C:\bea\user_projects\domains\mydomain and set the environment using setenv command.

Step3: go to the folder c:\bea\library Step4:compile the programs using javac *.java Step5: Invoke the marathon tool to initialize the EJB component.

Step 6: create the jar file using the following command jar cvf bb.jar *.class META-INF

Step7:start the weblogic server by selecting start->allprograms->bea weblogic platform.1>userprojects->mydomain->start server and see the port number 7001 in the server window.

Step8: Go to Internet Explorer and type the following URL to deploy the EJB module. Step 9: Deploy the EJB component using following steps.

To run the EJB Application goto the Internet Explorer and type the URL http://localhost:7001/console then type the userbname and password as weblogic.
To Deploy the New EJB module follows the given steps carefully. Click Deploy a new EJB Module.

Click upload your file(s)

To Browse the corresponding location to Upload the jar file.

Click myserver

Select the corresponding jar file for our application.

Finally Click the Deploy Button.

Step 10: Go to Dos prompt and set the class path using set classpath=%classpath%;.; and run the client program using Java BankClient

OUTPUT:

CONCLUSION:
Thus the enterprise Java Bean for the Banking operation was developed successfully.

You might also like