Remote Method Invocation

Client Server Java Programming
Remote Method Invocation

Java's Remote Method Invocation (commonly referred to as RMI) is used for client and server models. RMI is the object oriented equivalent to RPC (Remote procedure call).

The Java Remote Method Invocation (RMI) system allows an object running in one Java Virtual Machine (VM) to invoke methods of an object running in another Java VM. RMI provides for remote communication between programs written in the Java programming language.

RMI is only defined for use with the Java platform. If you need to call methods between different language environments, use CORBA. With CORBA a Java client can call a C++ server and/or a C++ client can call a Java server. With RMI that can not be done.


The remote method invocation goes through a STUB on the client side and a so called SKELETON on the server side.

CLIENT --> STUB --> ... Network ... --> SKELETON --> REMOTE OBJECT

Prior to Java 1.2 the skeleton had to be explicitly generated with the rmic tool. Since 1.2 a dynamic skeleton is used, which employs the features of Java Reflection to do its work.


Remote objects can be listed in the RMI Registry. Clients can get a reference to the remote object by querying the Registry. After that, the client can call methods on the remote objects. (Remote object references can also be acquired by calling other remote methods. The Registry is really a 'bootstrap' that solves the problem of where to get the initial remote reference from.)

The RMI Registry can either be started within the server JVM, via the LocateRegistry.createRegistry API, or a separate process called rmiregistry that has to be started before remote objects can be added to it, e.g. by the command line in Unix:

Standard input or output rmiregistry on Unix
rmiregistry <port> &

or under Windows:

Standard input or output rmiregistry on Windows
start rmiregistry <port>

If port is not specified the default 1099 is used. The client will need to connect to this port to access the Registry.

The Registry can also be started from a program by calling the following code:

Example Code section 1: rmiregistry starting
import java.rmi.registry.LocateRegistry;
Registry reg = LocateRegistry.createRegistry(iPort);

Objects passed in as parameters to the remote objects's methods will be passed by value. If the remote object changes the passed-in object values, it won't be reflected on the client side, this is opposite what happens when a local object is called. Objects that used as parameters for remote methods invocation must implement the interface, as they are going to be serialized when passed through the network, and a new object will be created on the other side.

However, exported remote objects passed as parameters are passed by remote reference.

rmic tool


To do:
Complete this section.

RMI Remote object

The remote object has to either extend the java.rmi.server.UnicastRemoteObject object, or be explicitly exported by calling the java.rmi.server.UnicastRemoteObject.exportObject method.

RMI clients

Here is an example of RMI client:

Computer code Code listing 7.10:
 1 import java.rmi.registry.LocateRegistry;
 2 import java.rmi.registry.Registry;
 4 public class HelloClient{
 6     private HelloClient {}
 8     public static void main(String[] args) {
 9         String host = (args.length < 1) ? null : args[0];
10         try {
11             Registry registry = LocateRegistry.getRegistry(host);
12             Hello stub = (Hello) registry.lookup("Hello");
13             String response = stub.sayHello;
14             System.out.println("response: " + response);
15         } catch (Exception e) {
16             System.err.println("Client exception: " + e.toString);
17             e.printStackTrace;
18         }
19     }
20 }


To do:
Add some exercises like the ones in Variables

Client Server Java Programming
Remote Method Invocation

  This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.



Connect with defaultLogic
What We've Done
Led Digital Marketing Efforts of Top 500 e-Retailers.
Worked with Top Brands at Leading Agencies.
Successfully Managed Over $50 million in Digital Ad Spend.
Developed Strategies and Processes that Enabled Brands to Grow During an Economic Downturn.
Taught Advanced Internet Marketing Strategies at the graduate level.

Manage research, learning and skills at Create an account using LinkedIn to manage and organize your omni-channel knowledge. is like a shopping cart for information -- helping you to save, discuss and share.

  Contact Us