Calculator.java
public interface Calculator extends java.rmi.Remote
{
public long add(long a,long b) throws java.rmi.RemoteException;
public long sub(long a,long b) throws java.rmi.RemoteException;
public long mul(long a,long b) throws java.rmi.RemoteException;
public long div(long a,long b) throws java.rmi.RemoteException;
}
----------------------------------------------------------------------------------------------------
CalulatorClient.java
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
public class CalculatorClient
{
public static void main(String args[])
{
long num1=Integer.parseInt(args[0]);
long num2=Integer.parseInt(args[1]);
try
{
Calculator c=(Calculator)
Naming.lookup("rmi://localhost/CalculatorService");
System.out.println("The Addition of "+num1+"and"+num2+"is:"+c.add(num1,num2));
System.out.println("The Subtraction of "+num1+"and"+num2+"is:"+c.sub(num1,num2));
System.out.println("The Multiplication of "+num1+"and"+num2+"is:"+c.mul(num1,num2));
System.out.println("The Division of "+num1+"and"+num2+"is:"+c.div(num1,num2));
}
catch(MalformedURLException m)
{
System.out.println("MaluformedURLException");
}
catch(RemoteException re)
{
System.out.println("RemoteException");
}
catch(NotBoundException nbe)
{
System.out.println("NotBoundExceptionException");
}
catch(java.lang.ArithmeticException ae)
{
System.out.println("java.lang.ArithmeticException");
}
}
}
---------------------------------------------------------------------------------------------------------
CalculatorImpl.java
public class CalculatorImpl extends java.rmi.server.UnicastRemoteObject implements Calculator
{
public CalculatorImpl() throws java.rmi.RemoteException
{
super();
}
public long add(long a,long b) throws java.rmi.RemoteException
{
return a+b;
}
public long sub(long a,long b) throws java.rmi.RemoteException
{
return a-b;
}
public long mul(long a,long b) throws java.rmi.RemoteException
{
return a*b;
}
public long div(long a,long b) throws java.rmi.RemoteException
{
return a/b;
}
}
Written by Naresh in
Calculator
---------------------------------------------------------------------------------------------------
CalculatorServer.java
import java.rmi.Naming;
public class CalculatorServer
{
public CalculatorServer()
{
try
{
Calculator c= new CalculatorImpl();
Naming.rebind("rmi://localhost:1099/CalculatorService",c);
}
catch(Exception e)
{
System.out.println("Trouble:"+e);
}
}
public static void main(String args[])
{
new CalculatorServer();
Popular Posts
-
import java.io.*; import java.net.*; import java.util.Scanner; /** Fetches the HTML content of a web page (or HTTP header) as a String....
-
import java.util.*; import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; class common extends Panel im...
-
Calculator.java public interface Calculator extends java.rmi.Remote { public long add(long a,long b) throws java.rmi.RemoteException; ...
-
Client import java.io.*; import java.net.*; class client { public static void main(String args[])throws Exception { String str;...
-
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Bully { static int n,pc,in...
-
import java.net.*; import java.io.IOException; import javax.swing.*; public class Trial { public static void main(String args[]) { ...
-
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Ring { static int n,pc,i...