SlideShare une entreprise Scribd logo
1  sur  5
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
{
    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:
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");
          }
    }
}
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
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

Contenu connexe

Tendances (19)

Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Avl tree
Avl treeAvl tree
Avl tree
 
Hashing endereçamento aberto - main
Hashing endereçamento aberto - mainHashing endereçamento aberto - main
Hashing endereçamento aberto - main
 
C Programming Language Part 4
C Programming Language Part 4C Programming Language Part 4
C Programming Language Part 4
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
week-1x
week-1xweek-1x
week-1x
 
New text document
New text documentNew text document
New text document
 
Security Events correlation with ESPER
Security Events correlation with ESPERSecurity Events correlation with ESPER
Security Events correlation with ESPER
 
week-2x
week-2xweek-2x
week-2x
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
week-10x
week-10xweek-10x
week-10x
 
Tu1
Tu1Tu1
Tu1
 
Linked list imp of list
Linked list imp of listLinked list imp of list
Linked list imp of list
 
Backdoor coding
Backdoor codingBackdoor coding
Backdoor coding
 
งานนำเสนอ อาจารย์ลาวัลย์
งานนำเสนอ อาจารย์ลาวัลย์งานนำเสนอ อาจารย์ลาวัลย์
งานนำเสนอ อาจารย์ลาวัลย์
 
Pattern printing programs
Pattern printing programsPattern printing programs
Pattern printing programs
 
Phpbase
PhpbasePhpbase
Phpbase
 
C#
C#C#
C#
 

En vedette

Crowdopolis 14-slides-caleb-light-wills tongal
Crowdopolis 14-slides-caleb-light-wills  tongalCrowdopolis 14-slides-caleb-light-wills  tongal
Crowdopolis 14-slides-caleb-light-wills tongalTCLABZ.com
 
Wasteful world powerpoint_task_1
Wasteful world powerpoint_task_1Wasteful world powerpoint_task_1
Wasteful world powerpoint_task_1lbeaumont
 
Clinica del bebe antecedentes
Clinica del bebe antecedentesClinica del bebe antecedentes
Clinica del bebe antecedentesCarla Sima
 
Br stochastic best practice
Br stochastic best practiceBr stochastic best practice
Br stochastic best practiceTCLABZ.com
 
New microsoft word document
New microsoft word documentNew microsoft word document
New microsoft word documentchanhyen1990
 
Crowdopolis 14-slides-alph-bingham inno centive pharma
Crowdopolis 14-slides-alph-bingham  inno centive pharmaCrowdopolis 14-slides-alph-bingham  inno centive pharma
Crowdopolis 14-slides-alph-bingham inno centive pharmaTCLABZ.com
 
Crowdopolis 14-slides-ram-rampalli walmart
Crowdopolis 14-slides-ram-rampalli  walmartCrowdopolis 14-slides-ram-rampalli  walmart
Crowdopolis 14-slides-ram-rampalli walmartTCLABZ.com
 
Prototyping is an attitude
Prototyping is an attitudePrototyping is an attitude
Prototyping is an attitudeWith Company
 
50 Essential Content Marketing Hacks (Content Marketing World)
50 Essential Content Marketing Hacks (Content Marketing World)50 Essential Content Marketing Hacks (Content Marketing World)
50 Essential Content Marketing Hacks (Content Marketing World)Heinz Marketing Inc
 
10 Insightful Quotes On Designing A Better Customer Experience
10 Insightful Quotes On Designing A Better Customer Experience10 Insightful Quotes On Designing A Better Customer Experience
10 Insightful Quotes On Designing A Better Customer ExperienceYuan Wang
 
How to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanHow to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanPost Planner
 
Learn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionLearn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionIn a Rocket
 
20 Ideas for your Website Homepage Content
20 Ideas for your Website Homepage Content20 Ideas for your Website Homepage Content
20 Ideas for your Website Homepage ContentBarry Feldman
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting PersonalKirsty Hulse
 

En vedette (18)

Crowdopolis 14-slides-caleb-light-wills tongal
Crowdopolis 14-slides-caleb-light-wills  tongalCrowdopolis 14-slides-caleb-light-wills  tongal
Crowdopolis 14-slides-caleb-light-wills tongal
 
Wasteful world powerpoint_task_1
Wasteful world powerpoint_task_1Wasteful world powerpoint_task_1
Wasteful world powerpoint_task_1
 
Phobe
PhobePhobe
Phobe
 
Clinica del bebe antecedentes
Clinica del bebe antecedentesClinica del bebe antecedentes
Clinica del bebe antecedentes
 
Final1243
Final1243Final1243
Final1243
 
Br stochastic best practice
Br stochastic best practiceBr stochastic best practice
Br stochastic best practice
 
New microsoft word document
New microsoft word documentNew microsoft word document
New microsoft word document
 
Crowdopolis 14-slides-alph-bingham inno centive pharma
Crowdopolis 14-slides-alph-bingham  inno centive pharmaCrowdopolis 14-slides-alph-bingham  inno centive pharma
Crowdopolis 14-slides-alph-bingham inno centive pharma
 
bin
binbin
bin
 
Crowdopolis 14-slides-ram-rampalli walmart
Crowdopolis 14-slides-ram-rampalli  walmartCrowdopolis 14-slides-ram-rampalli  walmart
Crowdopolis 14-slides-ram-rampalli walmart
 
Mmc1
Mmc1Mmc1
Mmc1
 
Prototyping is an attitude
Prototyping is an attitudePrototyping is an attitude
Prototyping is an attitude
 
50 Essential Content Marketing Hacks (Content Marketing World)
50 Essential Content Marketing Hacks (Content Marketing World)50 Essential Content Marketing Hacks (Content Marketing World)
50 Essential Content Marketing Hacks (Content Marketing World)
 
10 Insightful Quotes On Designing A Better Customer Experience
10 Insightful Quotes On Designing A Better Customer Experience10 Insightful Quotes On Designing A Better Customer Experience
10 Insightful Quotes On Designing A Better Customer Experience
 
How to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanHow to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media Plan
 
Learn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionLearn BEM: CSS Naming Convention
Learn BEM: CSS Naming Convention
 
20 Ideas for your Website Homepage Content
20 Ideas for your Website Homepage Content20 Ideas for your Website Homepage Content
20 Ideas for your Website Homepage Content
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting Personal
 

Similaire à 5 Rmi Print

Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfmayorothenguyenhob69
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manualsameer farooq
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4Abed Bukhari
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012Sandeep Joshi
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operatorsHarleen Sodhi
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)Chhom Karath
 
Assignment no39
Assignment no39Assignment no39
Assignment no39Jay Patel
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfkostikjaylonshaewe47
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specificationsrajkumari873
 
Apache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheelApache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheeltcurdt
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy codeShriKant Vashishtha
 

Similaire à 5 Rmi Print (20)

Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operators
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
My java file
My java fileMy java file
My java file
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
 
Presentation1
Presentation1Presentation1
Presentation1
 
programming for Calculator in java
programming for Calculator in javaprogramming for Calculator in java
programming for Calculator in java
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specifications
 
Apache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheelApache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheel
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
 
Java programs
Java programsJava programs
Java programs
 

5 Rmi Print

  • 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