RMI makes life easy

You want your objects to communicate across a network. In other words, you want an object in one JVM to cause a method invocation on a remote object (i.e. an object in a different JVM), but you want to pretend that you’re invoking a method on a local object. That’s what RMI gives you—the ability to pretend (almost) that you’re making a regular old local method call.

What we want...

image with no caption

How RMI pulls it off

Let’s say your “business guy” hat is on, and you want to make an object available to remote clients. Using RMI, you’ll create a proxy and you’ll register your object with some sort of registry. Any client who wants to call your methods will do a lookup on the registry and get a copy of the remote proxy. Then the client will make calls on the remote proxy, pretending it’s the real thing. The remote proxy (called a stub), handles all the communications details like sockets, I/O streams, TCP/IP, serializing and deserializing method arguments and return values, handling exceptions, and so forth.

(Oh, by the way, there’s usually a proxy on the server side (often called a “skeleton”), doing similar chores on the server side where the remote object lives.)

image with no caption

Get Head First Servlets and JSP, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.