RMI Concept

Remote Method Invocation (RMI):
RMI API is a Java application programming interface for performing the object equivalent of remote procedure calls. The concept of RMI is that, the client can use the services provided by a server which is on a different JVM, making remote calls to it. The client talks to a proxy server, which is in the same JVM as the client, and in turn talks to the actual server on a different JVM. So for the client it feels as if it is talking to a local server. This abstraction is taken care by the RMI API.
For the client to make remote calls on the server, it has to know what all methods are available for it to use. The representation of the service provided by the server to the client is in the form of an interface which the server implements. Therefore, the key to understanding RMI is to remember that interfaces define behavior and classes define implementation. RMI supports two classes that implement the same interface. The first class is the implementation of the behavior, and it runs on the server. The second class acts as a proxy for the remote service and it runs on the client.
RMI Architecture:

RMI Architecture

Stub & Skeleton Layer:
Stub is present on the client and Skeleton is present on the server. In this layer, RMI uses the Proxy design pattern. In the Proxy pattern, an object in one context is represented by another (the proxy) in a separate context. The proxy knows how to forward method calls between the participating objects. In RMI’s use of the Proxy pattern, the stub class plays the role of the proxy, and the remote service implementation class plays the role of the RealSubject.

When a stub's method is invoked, it does the following: