Your SlideShare is downloading. ×
5  Rmi Print
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

5 Rmi Print

430
views

Published on

rmi

rmi


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
430
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. IMPLEMENTATION OR RMI ARITHMETIC OPERATIONS /* cal.java*/ import java.rmi.*; public interface cal extends Remote { public int add(int x,int y) throws RemoteException; public int sub(int x,int y) throws RemoteException; public int mul(int x,int y) throws RemoteException; public int div(int x,int y) throws RemoteException; } /* calimp.java*/ import java.rmi.*; import java.rmi.server.*; import java.io.*; public class calimp extends UnicastRemoteObject implements cal { public calimp() throws RemoteException { super(); } public int add(int x,int y) throws RemoteException { return x+y; } public int sub(int x,int y) throws RemoteException { return x-y; } public int mul(int x,int y) throws RemoteException { return x*y; } public int div(int x,int y) throws RemoteException { return x/y; } } /* calserver.java*/ import java.rmi.*; import java.rmi.server.*; public class calserver
  • 2. { public static void main(String args[]) { try { calimp c=new calimp(); System.out.println("Binding Server implementation to registry .."); Naming.rebind("WIN",c); System.out.println("Registered"); System.out.println("Waiting for client to connect ..."); } catch(Exception e) { e.printStackTrace(); } } } /* calclient.java*/ import java.rmi.*; import java.rmi.server.*; import java.io.*; public class calclient { public static void main(String args[]) throws Exception { int a,b; DataInputStream d =new DataInputStream(System.in); boolean f=false; String url="rmi://localhost/"; try { cal c = (cal) Naming.lookup(url+"WIN"); do { System.out.println("nCALCULATOR"); System.out.println(" 1.Add"); System.out.println(" 2.Subtract"); System.out.println(" 3.Multiply"); System.out.println(" 4.Divide"); System.out.println(" 5.Exit"); System.out.print("nEnter your choice : "); switch(Integer.parseInt(d.readLine())) { case 1:
  • 3. System.out.print("nADDITION"); System.out.print("nNumber 1t: "); a=Integer.parseInt(d.readLine()); System.out.print("Number 2t: "); b=Integer.parseInt(d.readLine()); System.out.println("Sumtt: " + c.add(a,b)); break; case 2: System.out.print("nSUBTRACTION"); System.out.print("nNumber 1t: "); a=Integer.parseInt(d.readLine()); System.out.print("Number 2t: "); b=Integer.parseInt(d.readLine()); System.out.println("Differencet: " + c.sub(a,b)); break; case 3: System.out.print("nMULTIPLICATION"); System.out.print("nNumber 1t: "); a=Integer.parseInt(d.readLine()); System.out.print("Number 2t: "); b=Integer.parseInt(d.readLine()); System.out.println("Producttt: " + c.mul(a,b)); break; case 4: System.out.print("nDIVISION"); System.out.print("nNumber 1t: "); a=Integer.parseInt(d.readLine()); System.out.print("Number 2t: "); b=Integer.parseInt(d.readLine()); System.out.println("Quotientt: " + c.div(a,b)); break; case 5: System.out.print("nProgram Terminatednn"); f=true; break; } d.readLine(); }while(!f); } catch(Exception e) { System.out.println("Error"); } } }
  • 4. OUTPUT: CALCULATOR 1.Add 2.Subtract 3.Multiply 4.Divide 5.Exit Enter your choice : 1 ADDITION Number 1 : 23 Number 2 : 34 Sum : 57 CALCULATOR 1.Add 2.Subtract 3.Multiply 4.Divide 5.Exit Enter your choice : 2 SUBTRACTION Number 1 : 45 Number 2 : 11 Difference : 34 CALCULATOR 1.Add 2.Subtract 3.Multiply 4.Divide 5.Exit Enter your choice : 3 MULTIPLICATION Number 1 : 45 Number 2 :3 Product : 135
  • 5. CALCULATOR 1.Add 2.Subtract 3.Multiply 4.Divide 5.Exit Enter your choice : 4 DIVISION Number 1 : 32 Number 2 : 16 Quotient :2 CALCULATOR 1.Add 2.Subtract 3.Multiply 4.Divide 5.Exit Enter your choice : 5 Program Terminated

×