AboutBlogContact
Backend EngineeringJuly 14, 1999 2 min read 114Updated: May 18, 2026

Distributed Java: Serialization and RMI Stubs (1999)

AunimedaAunimeda
📋 Table of Contents

Distributed Java: Serialization and RMI Stubs

Java's "Write Once, Run Anywhere" promise is great, but "Write Once, Run Everywhere Simultaneously" is better. Remote Method Invocation (RMI) is the Java way of doing distributed computing. Unlike CORBA, it's native to the JVM, which means no complex IDL files to maintain.

The Remote Interface

Everything starts with an interface that extends java.rmi.Remote. Every method must throw RemoteException because, well, the network can fail.

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface StockServer extends Remote {
    double getPrice(String symbol) throws RemoteException;
}

Implementing the Server

Your implementation must extend UnicastRemoteObject. This handles the heavy lifting of listening for socket connections and dispatching calls.

import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;

public class StockServerImpl extends UnicastRemoteObject implements StockServer {
    public StockServerImpl() throws RemoteException { super(); }
    
    public double getPrice(String symbol) {
        return 42.0; // Real-time logic here
    }
}

The rmic Magic

The most confusing part of RMI is that you don't just compile the code. You have to run the rmic compiler on your implementation class. This generates the "Stub" and "Skeleton" classes. The client uses the Stub to talk to the Skeleton, which then talks to your actual object.

javac StockServerImpl.java
rmic StockServerImpl
# This creates StockServerImpl_Stub.class

Registration and Discovery

Finally, you bind the object to the rmiregistry.

StockServerImpl obj = new StockServerImpl();
java.rmi.Naming.rebind("rmi://localhost/StockService", obj);

RMI is incredibly powerful for building enterprise-grade Java applications. It handles object serialization automatically-as long as your objects implement Serializable. Just watch out for the performance hit of those deep object graphs.


Aunimeda builds production-grade backend systems - APIs, microservices, real-time applications, and system integrations.

Contact us for backend engineering services. See also: Custom Software Development, Web Development

Read Also

Spring Framework: Dependency Injection for the Massesaunimeda
Backend Engineering

Spring Framework: Dependency Injection for the Masses

Is the era of heavyweight EJB over? Rod Johnson’s Spring Framework offers a 'lightweight' alternative that promises to make Java Enterprise development fun again.

Distributed .NET: Remoting with TCP Channels (2002)aunimeda
Backend Engineering

Distributed .NET: Remoting with TCP Channels (2002)

Tired of the overhead of SOAP and XML? Learn how to use .NET Remoting with binary serialization over TCP for high-performance distributed systems.

OOP in PHP 4: Implementing Singleton and Factory Patterns (2001)aunimeda
Backend Engineering

OOP in PHP 4: Implementing Singleton and Factory Patterns (2001)

PHP 4's object model is limited, but with a bit of ingenuity and references, we can still implement robust design patterns like Singleton and Factory.

Need IT development for your business?

We build websites, mobile apps and AI solutions. Free consultation.

Get Consultation All articles