🌐

Java RMI Overview and Concepts

Aug 17, 2025

Overview

This lecture introduces Java Remote Method Invocation (RMI), explaining its purpose in distributed applications, core concepts like stubs and skeletons, requirements for distributed systems, and demonstrates a basic hands-on example.

What is Java Remote Method Invocation?

  • Java RMI is an API that enables invoking methods on remote objects located on different machines.
  • RMI is used for building distributed applications where objects interact over a network as if they were local.
  • It operates on a client-server model, using the Java Remote Method Protocol (JRMP).
  • RMI makes remote objects accessible through regular method calls, simplifying distributed system development.

Stubs and Skeletons

  • The stub is a client-side proxy representing the remote object; it hides communication details from the client.
  • The stub is generated by the RMI compiler and implements the remote interface.
  • The skeleton is a server-side object that receives method calls from the client and forwards them to the actual remote object.
  • The skeleton handles unmarshalling parameters, invoking methods, and returning results to the client.
  • Both stub and skeleton are necessary for transparent client-server communication and are generated automatically by RMI tools.

Requirements for Distributed Applications

  • Require reliable network connectivity between multiple machines (nodes).
  • Security mechanisms such as authentication and authorization are essential for data protection.
  • Need a suitable communication protocol for inter-node data exchange (e.g., message passing, remote procedure calls).
  • A distributed computing framework (e.g., Apache Hadoop, Spark) provides tools and APIs for building these applications.
  • Load balancing ensures work is spread across nodes for optimal performance.
  • Fault tolerance allows continued operation even if some nodes fail, achieved through data or process replication.
  • Effective data management strategies are needed for consistency, integrity, and partitioning.

RMI Hands-On Example Overview

  • Create a remote interface that extends java.rmi.Remote and declares methods throwing RemoteException.
  • Implement the remote interface by extending UnicastRemoteObject and defining the method logic.
  • Generate stub and skeleton objects using RMI tools.
  • Start the RMI registry for registering remote objects.
  • The server binds the remote object in the registry, while the client looks up the stub using Naming.lookup() to invoke methods.
  • For remote access, adjust the host/IP in client code as needed.

Key Terms & Definitions

  • Java RMI — An API for invoking methods on objects across different JVMs.
  • Stub — A client-side proxy for a remote object, handling communication.
  • Skeleton — A server-side proxy that forwards client calls to the actual remote object.
  • JRMP (Java Remote Method Protocol) — The network protocol used by RMI.
  • RemoteException — An exception that signals distributed communication errors.

Action Items / Next Steps

  • Practice creating and running a simple RMI application using the adder example.
  • Review the process of generating stubs and skeletons with the RMI compiler.
  • Ensure understanding of RMI registry usage and remote object binding.