This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
RMI
*.Create distributed name server like DNS using RMI //DNS PROGRAM//DnsInter.java:
*.Program to develop a Remote Object for a Bank Application to find Balance Amount from the Bank Account The method should authenticate the user by Mens of account-no and password.Use AWT/SWING to create user interface and JDBC to connect to the database
BankInter.java
import java.rmi.*;public interface Rem extends Remote{ public String validate(String acc,String passwd) throws RemoteException;}
Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery("Select * from bank where acno="+acc); System.out.println("Account no.:"+acc); String pwd1=""; while(rs.next()) { pwd1=rs.getString(2); } rs.close(); if(passwd.equals(pwd1)) { ResultSet rs1=stmt.executeQuery("Select * from bank where acno="+acc);
public static void main(String args[]) { RmiClient rc=new RmiClient(); }}
6
*.Develop Remote Object for an Employee application having a remote method to find employee details such as empid,ename,date_of_joining,service,salary with RMI
*.Develop a remote object for railway reservation application having remote method to find status of reservation which when supplied by PNR number.Implement the above using RMI
System.out.println(“enter the trainname in which u want to travel”);System.in(trainname);
System.out.println(“enter no of seats u want”);System.in(wanted);
if(availabeseats>=wanted){System.out.println(“seats available”);//issue ticketSystem.out.println(“enter the name of the bank in which u have credit card”);System.in(“bankname”);System.out.println(“enter ur creditcard no”);System.in(“creditcardno”);
for(i=1;1<=100;i++){Statement s=con.createStatement(“select creditbal from BankDB where bankname=”+bankname+”creditcardno=”+creditcardno”);if(i==creditcardno&&creditbal>=chargeamt ){System.out.println(“ur a/c has been verified”);System.out.println(“seat no”+seat no+”has been allotted to u with a charge of “+chargeamt);System.in(“chargeamt”);System.out.println(“ur seat has been confirmed”);availableseats=availableseats-wanted;elseSystem.out.println(“seat may not be confirmed”);}
*.Consider an E-commerce application of “Shopping Cart” for purchasing things over the web.Implement the above application using EJB by considering necessary issues involved
public void ejbRemove(){}public void setSessionContext(SessionContext ctx){s=ctx;} public Product[] getProductList () throws RemoteException{try{Connection con=DriverManager.getConnection(get DBURL());String query=”select * from ItemList”; Statement s=con.createStatement();resultSet rs=s.executeQuery(query);rs.next();if(!more){rs.getString(“itemname”);rs.getInt (“iprice”);
rs.getInt(“itemid”);
rs.getInt(“quantity”);}rs.close();return itemid,itemname,quantity,iprice;}public String Purchase(int itemid,int quantity) throws RemoteException{int Price=0;int n;System.out.println(“enter the no of items u want to buy”);System.in(n);
System.out.println(“enter the itemid which u want to buy”);System.in(itemid);
}//issue itemsSystem.out.println(“enter the name of the bank in which u have credit card”);System.in(“bankname”);System.out.println(“enter ur creditcard no”);System.in(“creditcardno”);
Statement s=con.createStatement(“select creditbal from BankDB where bankname=”+bankname+”creditcardno=”+creditcardno”);
if(i==creditcardno&&creditbal>=Price ){System.out.println(“ur a/c has been verified”);System.out.println(“items with ids”+itemid +”has been allotted to u with a charge of “+chargeamt);System.in(“chargeamt”);System.out.println(“transaction completed”);}
<!DOCTYPE ejb_jar PUBLIC ‘_//SUN MicroSystems,Inc .//DTD Enterprise JavaBean 2.0//EN’ ‘http://java.sun.com/j2ee/dtds/ejb_jar_2_0.dtd’><ejb_jar><enterprise_beans><session><ejb_name>OnlineShoppingApplication</ejb_name><home>OnlineShopping.OnlineShopHome</home><remote>OnlineShopping.OnlineShopRemote</remote><ejb_class>OnlineShopClass</ejb_class></session></enterprise_beans>
weblogic_ejb_jar.xml
<!DOCTYPE weblogic_ejb_jar PUBLIC ‘_//BEA Systems,Inc.//DTD weblogic8.1.0 EJB//EN’ ‘http://www.bea.com/servers/w1s810/dtd/weblogic_ejb_jar.dtd’><weblogic_ejb_jar><weblogic_enterprise_bean><ejb_name>OnlineShoppingApplication</ejb_name><jndi_name>OnlineShopHome</jndi_name></weblogic_enterprise_bean></weblogic_ejb_jar>
15
*.Consider an Inventory application which supports three basic use cases: (i) Adding Items to the Stock(ii)Receive items(iii)Issue Items The application starts with adding item information to the stock.Then it allows enter goods receiving and issuing information.All those updated information are stored in the inbuilt database Implement the above application using EJB by considering necessary issues involved
public interface InventoryHome extends ejbHome{InventoryItem[ ] create() throws createException, RemoteException;}
InventoryRemote.java
public interface InventoryRemote extends ejbObject{ public InventoryItem[ ] get Inventory() throws RemoteException;
public void addItem(int custid,String itemcode,int quantity) throws RemoteException;
public void removeItem(int custid,String itemcode,int quantity) throws RemoteException,ItemNotFoundException;
public InventoryItem[ ] get BagContents(int custid) throws RemoteException;public void finalizeOrder(int custid) throws RemoteException;}InventoryClass.java
package Inventoryctrl;import javax.ejb.*;public class InventoryBean implements SessionBean
public InventoryItem[ ] get Inventory() {String query=”select count(*) from inventory”;Connection c=DriverManager.getC onnection(get DBURL());Statement s=c.createStatement();ResultSet rs=s.executeQuery(query);rs.next();
16
int count=rs.getInt(1);System.out.println(“count is”+conunt); rs.close();
public void addItem(int custid,String itemcode,int quantity) throws RemoteException;{try{Connection c=DriverManager.getC onnection(get DBURL());Int quantityOrdered=getItemCount(int custid,itemcode,c);If(quantityOrdered>0){String query=”update orders set quantity=” “(quantityOrdered+quantity)+”where custid+”and “itemcode=”+itemcode+” “;Statement s=c.createStatement();s.executeUpdate(query);s.close:}else{String query=”insert into orders(custid,itemcode,quantity) values(?,?,?)”;Prepared Statement ps=con. Prepared Statement(query);ps.setInt(1,custid);
ps.setString(2,itemcode);ps.setInt(3,quantity) ;ps.executeUpdate() ;ps.close() ;}c.close() ;}catch(SQL Exception e){log(“SQL exception in addItem:”+e);}}
public int getItemCount(int custid,String itemcode,int quantity) throws SQLException;{String query=”select quantity from orders where custid=”+custid+”and itemcode=”+itemcode+” “;Statement s=c.createStatement();ResultSet rs=s.executeQuery(query);boolean more=rs.next();int quantity;if(!more){quantity=0;
public void removeItem(int custid,String itemcode,int quantity) throws RemoteException,ItemNotFoundException;{try{Connection c=DriverManager.getC onnection(get DBURL());int numordered=getItemCount((int custid,String itemcode,int quantity) throws SQLException{if(numorderd==0){c.close();throw ItemNotFoundException();}log(“numordered=+ numordered){if(numordered<=quantity){String query=”delete from orders where custid=”+custid+”and itemcode=”+itemcode;Statement s=c.createStatement();int count=s. executeUpdate(query);s.close();}else{Statement s=c.createStatement();String query=”update orders set quantity=” “(quantity-itemsToRemove)+”where custid+”and “itemcode=”+itemcode+” “;int count=s. executeUpdate(query);s.close();}
public void finalizeOrder(int custid) throws RemoteException;{Connection c=DriverManager.getC onnection(get DBURL());Sring query=”insert int orders (int custid,String itemcode,int quantity) select custid, itemcode, quantity from orders where custid=”+custid;Statement s=c.createStatement()
18
s. executeUpdate(query);s.close();Sring query=”delete from orders where custid=”+custid;Statement s=c.createStatement()s. executeUpdate(query);s.close();}}
public void ejbActivate () { System.out.println (“student bean activated”); }
public void ejbpassivate () { System.out.println (“student bean passivated”); }
<!DOCTYPE ejb_jar PUBLIC ‘_//SUN MicroSystems,Inc .//DTD Enterprise JavaBean 2.0//EN’ ‘http://java.sun.com/j2ee/dtds/ejb_jar_2_0.dtd’><ejb_jar><enterprise_beans><session><ejb_name>StudentApplication</ejb_name><home>Student.StudentHome</home><remote>Student.StudentRemote</remote><ejb_class>StudentClass</ejb_class></session></enterprise_beans>
weblogic_ejb_jar.xml
<!DOCTYPE weblogic_ejb_jar PUBLIC ‘_//BEA Systems,Inc.//DTD weblogic8.1.0 EJB//EN’ ‘http://www.bea.com/servers/w1s810/dtd/weblogic_ejb_jar.dtd’><weblogic_ejb_jar><weblogic_enterprise_bean><ejb_name>StudentApplication</ejb_name><jndi_name>StudentHome</jndi_name></weblogic_enterprise_bean></weblogic_ejb_jar>
23
*.Develop a Library application for issuing and returning books by considering Book(BookID,Title,author,edition,year,price) information.Implement the above application using EJB//a stateful session bean for Library operation
s=ctx;} public Product[] getProductList () throws RemoteException{try{Connection con=DriverManager.getConnection(get DBURL());String query=”select * from ItemList”; Statement s=con.createStatement();resultSet rs=s.executeQuery(query);rs.next();if(!more){rs.getString(“itemname”);rs.getInt (“iprice”);
rs.getInt(“itemid”);
rs.getInt(“quantity”);}rs.close();return itemid,itemname,quantity,iprice;}public String Purchase(int itemid,int quantity) throws RemoteException{int Price=0;int n;System.out.println(“enter the no of items u want to buy”);System.in(n);
System.out.println(“enter the itemid which u want to buy”);System.in(itemid);
System.out.println(“enter quantity”);System.in(quantity);if(n>1){for(i=1;i=n;i++){Price=Price+iprice;}}//issue itemsSystem.out.println(“enter the name of the bank in which u have credit card”);System.in(“bankname”);System.out.println(“enter ur creditcard no”);
29
System.in(“creditcardno”);
Statement s=con.createStatement(“select creditbal from BankDB where bankname=”+bankname+”creditcardno=”+creditcardno”);
if(i==creditcardno&&creditbal>=Price ){System.out.println(“ur a/c has been verified”);System.out.println(“items with ids”+itemid +”has been allotted to u with a charge of “+chargeamt);System.in(“chargeamt”);System.out.println(“transaction completed”);}
public void setSessionContext(SessionContext ctx){s=ctx;} public String getAvailList () throws RemoteException{try{Connection con=DriverManager.getConnection(get DBURL());String query=”select trainnames,timings,chargeamt,availableseats from TrainList where source=”+source+’destiny=”+destiny;Statement s=con.createStatement();ResultSet rs=s.executeQuery(query);rs.next();if(!more){rs.getString(“trainnames”);rs.getString(“timings”);
rs.getInt(“chargeamt”);
rs.getInt(“availableseats”);}rs.close();return trainnames,timings,chargeamt,availableseats;}public String Reservation(String trainname,int wanted) throws RemoteException;{System.out.println(“enter the trainname in which u want to travel”);System.in(trainname);
System.out.println(“enter no of seats u want”);System.in(wanted);
//issue ticketSystem.out.println(“enter the name of the bank in which u have credit card”);System.in(“bankname”);System.out.println(“enter ur creditcard no”);System.in(“creditcardno”);
for(i=1;1<=100;i++){
33
Statement s=con.createStatement(“select creditbal from BankDB where bankname=”+bankname+”creditcardno=”+creditcardno”);if(i==creditcardno&&creditbal>=chargeamt ){System.out.println(“ur a/c has been verified”);System.out.println(“seat no”+seat no+”has been allotted to u with a charge of “+chargeamt);System.in(“chargeamt”);System.out.println(“ur seat has been confirmed”);availableseats=availableseats-wanted;elseSystem.out.println(“seat may not be confirmed”);}
import java.naming.*;import java.ejb.*;import java.util.*;import java.rmi.*;import dt_time.*;public class DateTimeClient{public static void main(String args[ ]) throws Exception{try{Properties p=new Properties( );p.put(Context.PROVIDER_URL,”t3://192.168.100.71:7001”);p.put(Context.INTIAL_CONTEXT_FACTORY,”weblogic.jndi.T3IntialContextFactory”);IntialContext ic=new IntialContext(p);Dt_time.Date-TimeHome home=(dt_time.MyHome)ic.lookup(“lateef_jndi”);Dt_time.Date-TimeRemote remote=(dt_time.MyRemote)home.create();String s=remote.getDate();System.out.println(“current date is=”+s);String s=remote.getTime();System.out.println(“current time is=”+s);
}Catch(Exception e){e.printStackTrace();}}}
37
ejb-jar.xml
<!DOCTYPE ejb_jar PUBLIC ‘_//SUN MicroSystems,Inc .//DTD Enterprise JavaBean 2.0//EN’ ‘http://java.sun.com/j2ee/dtds/ejb_jar_2_0.dtd’><ejb_jar><enterprise_beans><session><ejb_name>Date and Time Application</ejb_name><home>dt_Time.Date_TimeHome</home><remote>dt_Time.Date_TimeRemote</remote><ejb_class>Date TimeClass</ejb_class></session></enterprise_beans>
weblogic_ejb_jar.xml
<!DOCTYPE weblogic_ejb_jar PUBLIC ‘_//BEA Systems,Inc.//DTD weblogic8.1.0 EJB//EN’ ‘http://www.bea.com/servers/w1s810/dtd/weblogic_ejb_jar.dtd’><weblogic_ejb_jar><weblogic_enterprise_bean><ejb_name>Date and Time Application</ejb_name><jndi_name>Date_Time Home</jndi_name></weblogic_enterprise_bean></weblogic_ejb_jar>
38
CORBA
*.Consider an Employee database and develop a Payroll application by considering BasicPay,DA,HRA,CCA,Deductions which generates pay slip using CORBA
*.Develop a bank application to find the balance amount from the saving account by considering necessary issues.Implement the above application by using CORBA IDL// bank.idl
Module bank{Interface Bank { Float displaBalance (float Val) };}
// BankImpl.java
import bank .*;import org.omg.CORBA.*;import java.sql.*;Public class BankImpl extends BankImplBase {Public float display Balance (float Val) { try { Class.forName (“sun.jdbc.odbc.JdbcOdbcdriver”); Connection con=DriverManager.getConnection (“Jdbc: Odbc: MyDb”,”Scott”,”and tige@orastub”); Statement stmt=con.CreateStatement (); Resultset rs=stmt.executeQuery (“select balance from bank where no= val”); if (rs.next ()) { if (rs.getFloat()) return (rs.getFloat(1)); } rs.close(); stmt.close(); con.close (); } catch (Exception e) { System.out.println (“error”); } return (0);}
*.Implement a COM component to perform the fallowing operations on bank account:(i) Deposit (ii)Withdraw
/* VB */Dim bal As LongDim val(6) As LongDim i,x As Integerpublic Function deposit(ByVal acno As Long,ByVal amt As Long) As Longi=0For i=0 To 5If(i=acno) Thenval(i)=val(i)+amtEnd IfNext Deposit=Val(acno)End FunctionPublic Function withdraw(ByVal acno As Long,ByVal amt As Long) As Longbal=0For i=0 To 5If(i=acno) Thenval(i)=val(i)-amtEnd IfNextwithdraw=val(acno)End FunctionPublic Function showBal(ByVal acno As Long) As Longbal=0For i=0 To 5If(i=acno) Thenbal=val(i)End IfNextShowbal=balEnd FunctionPublic Function initialize()x=500For i=0 To 5Val(i)=1000+xNextEnd Function
/* C# */
46
Using system;Using bankproj;Namespace CConsoleApplication8{///<summary>//.description for class1///</summary>Class class1{///<summary>//.entry point for application///</summary> [STA Thread]Static void Main(string[] args){//bank b=new bank();b.intialize(); Console.Writeline(“intial bal”+b.showBal(1));Console.writre(“After depositing 1500\t”); Console.Writeline(b.deposit(1,1500));Console.write(“After withdrawing 1000\t”);Console.Writeline(b.withdraw(1,1000));Console.write(“current balance \t”);Console.Writeline(b.showBal(1));Console.ReadLine();//TODO :Add code to start application here//}}}
47
.NET
*.Develop a component for converting currency from rupees to dollar and dollar to rupees using .NET//Windows Application for currenc conversionUsing system;Using system.Drawing;Using system.Collection;Using system.ComponentModel;Using system.Windows.Forms;Using system.Data;private void radioButton1_CheckedChanged(object sender,System.EventArgs e){double k=convert.ToDouble(textBox1.Text);k=(double) k*0.5;string v=” “+k;textBox2.Text=v;}
*.Develop a component for browsing CD catalogue using COM/.NET
Import System.IOPublic Class Form1Inherits Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadDim str() As StringDim i As IntegerStr = Directory.GetLogicalDrives()For i=0 To str.Length-1LostBpx1.Items.Add(str(i))NextEnd SubPrivate Sub ListBox1_SelectedIndexChanged (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChangeDim d As New DirectoryInfo(ListBox1.SelectedItem)Dim dinfo() As DirectoryInfoDim i As Integerdinfo=d.GetDirectoriesListBox2.Items.Clear()For i=0 To dinfo.Length-1ListBox2.Items.Add(dinfo(i).Name)NextEnd Sub Private Sub ListBox2_SelectedIndexChanged (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChangeDim d As New DirectoryInfo(ListBox1.SelectedItem&ListBox1.SelectedItem)Dim dinfo() As FileInfoDim i As IntegerListBox3.Items.Clear()dinfo=d.GetDirectories
For i=0 To dinfo.Length-1ListBox3.Items.Add(dinfo(i).Name)NextEnd SubEnd class
49
*.Develop a calculator component for arthimetic operation using .NET
public partial class Form1 : Form
{
// Load variables
private int sum; // Uses Double for large numbers: um = total
private string TextEntry = null; // String for reading text box entry