//code for remote Interface
import java.rmi.*;
public interface HelloInterface extends Remote
{
public String getMessage() throws RemoteException;
public void display() throws RemoteException;
}
//Code for Server
import java.rmi.*;
import java.rmi.server.*;
public class HelloServer extends UnicastRemoteObject implements HelloInterface
{
public HelloServer() throws RemoteException
{
}
public String getMessage() throws RemoteException
{
return”Hello Sir”;
}
public void display() throws RemoteException
{
System.out.println(”hi how r u”);
}
public static void main(String args[])
{
try
{
HelloServer Server=new HelloServer();
Naming.rebind(”rmi://localhost:1099/Server”,Server);
}
catch(Exception e)
{
}
}
}
// Code for Client
import java.rmi.*;
public class HelloClient
{
public static void main(String args[])
{
try
{
HelloInterface Server=(prgm7)Naming.lookup(”rmi://localhost:1099/Server”);
String msg=Server.getMessage();
System.out.println(msg);
Server.display();
}
catch(Exception e)
{
}
}
}
//Execution Method
OUTPUT :
>javac HelloInterface.java
>javac HelloServer.java
>javac HelloClient.java
>rmic HelloServer
>start rmiregistry // Opens a New Window
>java HelloServer // Run in the New Window
>java HelloClient // Run in New Window
Hello Sir
Server Window Output
————————-
hi how r u