//Client program
import java.rmi.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class AddClient
{
public static void main(String arges[])
{
String host=”localhost”;
Scanner sc=new Scanner(System.in);
System.out.println(“Enter first parameter”);
int a=sc.nextInt();
System.out.println(“Enter second parameter”);
int b=sc.nextInt();
try
{
AddRem remobj=(AddRem)Naming.lookup(“rmi://”+host+”/AddRem”);
System.out.println(remote.addNum(a,b));
}
catch(RemoteException re)
{
re.printStackTrace();
}
catch(NotBoundException nbe)
{
nbe.printStackTrace();
}
catch(MalformedURLException mfe)
{
mfe.printStackTrace();
}
}
}
import java.rmi.*;
public interface AddRem extends Remote
{
public int addNum(int a ,int b) throws RemoteException;
}
//implementation of interface
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
public class AddRemImpl extends UnicastRemoteObject implements
AddRem
{
public AddRemImpl() throws RemoteException{}
public int addNum(int a, int b)
{
return(a+b);
}
}
//server program
import java.rmi.*;
import java.net.*;
public class AddServer
{
public static void main(String args[])
{
try
{
AddRemImpl locobj=new AddRemImpl();
Naming.rebind(“rmi:///AddRem”,locobj);
}
catch(RemoteException re)
{
re.printStackTrace();
}
catch(MalformedURLException mfe)
{
mfe.printStackTrace();
}
}
}