Steps for developing RMI applications are as follows:
- Defining the remote interface
- Implementing the remote interface
- Writing the code for registering the object
- Writing the client that uses the remote objects
- Generating stubs (client proxies) and skeletons (server entities)
- Running the RMI Registry, server and client
# Defining the remote interface
A remote Interface by definition is the set of methods that can be invoked remotely by a client:
- Clients program communicate to remote interfaces, not to classes implementing it.
- To be a remote interface, an interface must extend the Remote interface of java.rmi package.
- Each method must throw a java.rmi.RemoteException (or a superclass of RemoteException)
Example:
import java.rmi.Remote;
public interface ExampleInterface extends Remote {
public String printJava() throws java.rmi.RemoteException;
public void addAmount(int a, int b) throws java.rmi.RemoteException;
}