Java Remote Method Invocation (RMI) architecture is a distributed-object model in which a client invokes methods on a remote Java object through a local stub that forwards the call over the network to a server-side object, with a registry used to look up remote objects by name. The core pieces are the remote interface, the client stub (proxy), the server-side object implementation, the RMI registry, and the transport layer that serializes and transmits the call. This description reflects the classic RMI design; some implementation details differ between older JDK versions and modern Java, so version-specific behavior is flagged where it matters.

The Big Picture: A Local Call That Crosses a Network

RMI lets a programmer write code that looks like an ordinary Java method call, even though the target object lives in another JVM (possibly on another machine). The trick is that the compiler-generated stub on the client side has the same methods as the remote interface. When the client calls service.add(2, 3), the stub intercepts that call, marshals the arguments (method name, parameters) into a serialized form, sends them to the server, waits for the result, unmarshals the return value, and hands it back as if the method had executed locally.

The architecture is therefore a proxy pattern over a network transport. The client never holds a direct reference to the remote object; it holds a reference to a stub that knows how to reach the remote object. This is the fundamental abstraction that makes RMI "remote method invocation" rather than "remote procedure call with manual socket code."

The Layers of RMI Architecture

RMI is usually described in terms of layers, from the programmer-facing API down to the wire. These layers are conceptual, and different textbooks split them slightly differently, but the standard decomposition is useful.

The Stub and Skeleton Layer (Proxy Layer)

This is the layer closest to application code. On the client side, the stub implements the remote interface and acts as a local representative of the remote object. On the server side, the classic design used a skeleton, which received the incoming call, unmarshaled arguments, dispatched to the actual remote object, and marshaled the result back.

An important version note: since Java 2 (J2SE 1.2), skeletons are no longer required and are not generated by rmic. The stub alone, combined with the RMI runtime, handles dispatch. Older tutorials and textbooks that describe rmic generating both _Stub and _Skel classes are describing the pre-1.2 model. If you are reading a source that shows skeletons, check its date. In modern Java, rmic has been deprecated and, in recent JDKs (JDK 15 and later), removed from the distribution. The stub itself is also often generated dynamically at runtime rather than precompiled.

So the accurate modern statement is: the client stub layer remains; the server skeleton layer is largely historical, replaced by runtime dispatch.

The Remote Reference Layer (RRL)

The Remote Reference Layer sits between the stub/skeleton layer and the transport. It handles the semantics of how a remote reference behaves: for example, whether a call is a direct unicast to one object, and how the runtime locates and contacts the remote object. It manages the connection and the invocation semantics (such as the default "at-most-once" or "at-least-once" behavior depending on configuration). This layer is mostly internal; application programmers rarely touch it directly.

The Transport Layer

The transport layer handles the actual network connection, typically TCP, and the framing of messages. It manages connections, listens on ports, and moves serialized call data between JVMs. The default RMI transport uses TCP, and the registry by default listens on port 1099. The transport layer is where the serialized byte stream actually travels.

A useful mental model: the stub is the what (the method call as the client sees it), the remote reference layer is the how it is routed and invoked, and the transport is the pipe.

The Essential Components in a Working RMI System

The Remote Interface

A remote interface extends java.rmi.Remote and declares methods that throw java.rmi.RemoteException (or a superclass). This is a contract: it tells the RMI system which methods may be invoked remotely. A class that implements the interface and extends UnicastRemoteObject (or is explicitly exported) becomes a remote object.

The throws RemoteException clause is not decoration. Network calls can fail in ways local calls cannot: the server may be down, the connection may drop, the registry may be unreachable. Java forces you to acknowledge this by making the checked exception part of the contract.

The Server Implementation and Export

The server class implements the remote interface. Extending UnicastRemoteObject exports the object, meaning the RMI runtime makes it available to receive incoming calls on a server socket. The object is then bound to a name in the registry.

The RMI Registry

The registry (java.rmi.registry.Registry, often started with rmiregistry) is a simple naming service. The server binds a remote object to a string name; the client looks up that name and receives a stub. The registry does not hold the object itself in the sense of executing it; it holds a reference (in classic RMI, a stub) that the client can use to contact the server.

The registry is a bootstrapping mechanism: it solves the "how does the client find the object in the first place" problem. Once the client has the stub, subsequent calls go directly to the remote object's transport endpoint, not through the registry on every call.

The Client

The client looks up the name, gets a stub typed as the remote interface, and calls methods. It does not need the implementation class, only the interface (and the classes of any parameters and return values, which must be serializable or themselves remote).

What Actually Happens on a Call: A Step-by-Step Trace

Understanding the architecture is easier with a concrete trace of calc.add(2, 3):

1: The client calls add on the stub. Because calc is a stub, this is a local method call into stub code, not into CalculatorImpl. 2: The stub marshals the call: it records which method, the arguments 2 and 3, and prepares a serialized message. In classic RMI this used Java serialization; modern RMI still relies on serialization for arguments and return values. 3: The stub passes the message to the remote reference layer, which determines how to reach the remote object. 4: The transport layer sends the bytes over TCP to the server. 5: On the server, the transport receives the bytes, and the RMI runtime (in modern Java, without a generated skeleton) unmarshals the call and dispatches it to the correct method on the actual CalculatorImpl instance. 6: The method executes and returns 5. 7: The return value is marshaled, sent back over the transport, unmarshaled by the client stub, and returned to the caller.

The client's code never sees steps 2–7. That invisibility is the point of the architecture, and also the source of its costs: every remote call pays serialization, network latency, and the possibility of partial failure.

Parameter Passing: The Critical Ambiguity

The most common point of confusion about RMI is how arguments and return values cross the boundary. RMI does not pass object references in the ordinary Java sense for arbitrary objects. The rule is:

Remote objects (objects implementing a remote interface and exported) are passed by reference: the client receives a stub. Non-remote objects that are Serializable are passed by value: they are serialized, copied, and deserialized on the other side. The receiver gets a copy, not the same object. Non-serializable, non-remote objects cannot be passed; attempting to do so throws a marshaling exception.

This distinction has real consequences. If you pass a mutable Serializable object to a remote method and the method mutates it, the client's original object is not changed, because the server operated on a copy. Conversely, if you pass a remote object, the receiver gets a stub that forwards calls back to the original object.

A specific example: suppose a ShoppingCart is Serializable and a CartService is remote. Passing the cart to cartService.checkout(cart) sends a copy; any change the server makes to the copy is invisible to the client unless the method returns the modified copy or the cart is itself a remote object. This is a frequent source of bugs for programmers used to local object semantics.

Serialization and the Classpath Requirement

RMI relies on Java serialization to move arguments and return values. This creates a deployment constraint that is easy to overlook: the client and server must both have the classes of any serialized parameters and return types on their classpaths. If the client sends a com.example.Order object, the server needs com.example.Order to deserialize it.

Classic RMI also supported dynamic class loading via a codebase (the java.rmi.server.codebase property), which allowed a receiver to download missing classes from a URL. This feature is a well-known security hazard and is disabled by default in modern Java. In contemporary practice, you should assume classes must be present on both sides rather than relying on codebase downloading. Mentioning this matters because older tutorials treat remote class loading as routine; it is not a safe default today.

The Role of the Registry and the "Lookup" Semantics

The registry is often described as holding "the remote object," but technically it holds a binding from a name to a stub (in modern RMI, a serialized reference). The client's lookup returns that stub. Two practical consequences:

Rebinding replaces the name's target. If the server calls rebind again, new lookups get the new stub; existing clients holding the old stub may fail or continue depending on the old object's state. The registry is a separate process or an in-JVM service. You can run rmiregistry as a standalone process, or create one in the server JVM with LocateRegistry.createRegistry. The choice affects lifecycle and port management.

The default port is 1099, but this is a convention, not a requirement; you can specify another port.

RMI vs. RPC and vs. Modern Alternatives

RMI is often compared with older RPC systems (such as Sun RPC or CORBA). The key architectural difference is that RMI is object-oriented: it invokes methods on objects, supports passing remote object references, and integrates with Java's type system through interfaces. Classic RPC tends to be procedure- and message-oriented.

Compared with modern alternatives, RMI is a Java-specific technology. It does not interoperate natively with non-Java clients. For cross-language distributed systems, gRPC, REST/HTTP, or message brokers are more common today. RMI remains useful for Java-to-Java distributed computing, for teaching distributed-object concepts, and in legacy enterprise systems. It is also the conceptual ancestor of later Java distributed technologies (such as EJB remote interfaces), which borrowed its stub/proxy model.

A common misconception is that RMI is "obsolete and unusable." That overstates it. RMI still works in current Java, but its ecosystem role has shrunk, and the removal of rmic and the deprecation of related tooling reflect a shift toward runtime-generated stubs and alternative remoting frameworks. Saying "RMI is dead" is inaccurate; saying "RMI is no longer the default choice for new distributed systems" is accurate.

Failure Modes and the "Partial Failure" Problem

Distributed systems differ from local systems because a call can fail in ambiguous ways. In RMI:

A RemoteException may mean the server never received the call, or it received and executed it but the response was lost. Retrying a non-idempotent operation (like "increment counter") can therefore double-apply it. Network partitions, server crashes, and serialization errors all surface as exceptions that local method calls never produce.

This is why the remote interface forces RemoteException: the architecture is designed to make the possibility of failure visible in the type system. Good RMI design accounts for idempotency, timeouts, and retry policy rather than treating remote calls as free.

Where the Architecture Stops Applying

The description above is the classic UnicastRemoteObject / registry model. It does not cover:

Activation, a legacy RMI feature that allowed remote objects to be activated on demand (largely deprecated and removed in modern JDKs). RMI over IIOP, which allowed interoperability with CORBA; this was removed from later Java versions. Custom socket factories and SSL/TLS transport configuration, which change the transport layer's behavior but not the overall stub/proxy architecture.

If a source describes activation or RMI-IIOP as current, check its Java version. These are historical parts of the RMI story, not present-day defaults.

Summary of the Architecture in One View

Layer / Component Role Modern status
Remote interface Contract for remotely callable methods Current
Client stub Local proxy that marshals calls Current (often runtime-generated)
Server skeleton Server-side dispatch Historical (pre-Java 2)
Remote Reference Layer Routing and invocation semantics Internal, current
Transport layer TCP framing and byte transfer Current
Registry Name-to-stub lookup service Current (default port 1099)
Serialization Moves arguments and return values Current, with classpath constraints

The architecture's core idea is durable: separate the interface from the implementation, put a proxy in front of the network, and let a naming service bootstrap discovery. That model reappears in modern remoting frameworks even where RMI itself is not used.

Frequently Asked Questions

Does the client need the server's implementation class? No. The client needs the remote interface and the classes of any serialized parameters and return values. The implementation class lives only on the server.

Why does every remote method throw RemoteException? Because network calls can fail partially and unpredictably; the checked exception forces callers to handle that possibility.

Is the registry involved in every call? No. The registry is used for lookup (bootstrapping). After the client has the stub, calls go to the remote object's endpoint, not through the registry.

Are arguments passed by reference? Only remote objects are passed by reference (as stubs). Serializable non-remote objects are passed by value (copied). This is the most important semantic distinction in RMI.

Is RMI still supported? Yes, in current Java, though rmic and some legacy features have been removed or deprecated. For new cross-language systems, other remoting technologies are usually preferred.