O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required