Version 1.1 of the Java Development Kit (JDK) introduced the Remote Method Invocation (RMI) API to support remote method invocations on objects across Java virtual machines. RMI provides new Java interfaces to find remote objects, load them, and then run them securely. One can think of RMI as a mini-CORBA for Java. RMI was never intended to compete against CORBA, as DCOM does, but rather to offer a subset of CORBA functionality for pure Java environments. Because it offers a small subset of the CORBA functionality, RMI can be much easier to learn than CORBA for new developers. RMI fills a definite need, as many applications have a simple requirement for remote method invocation without all the functionality of CORBA. On the other hand, larger, more complicated distributed systems developers might just do very well to take the plunge and use CORBA.
To help compare CORBA and RMI, let's examine the steps you would follow to create an RMI client and server.
For the Server:
Define a remote interface. A remote interface always extends the java.rmi.Remote interface and must throw a java.rmi.RemoteException.
Implement the remote interface. By extending the java.rmi.UnicastRemoteObject class, you create the server class that implements your remote interface.
Compile the server class. This is done using any Java compiler.
Run the stub compiler, rmic. The rmic compiler creates client and server stubs for your remote class from your server's .class file.
Start the RMI registry on your server. The RMI registry implements a non-persistent naming service for RMI servers. Only one RMI registry per server machine is required.
Start your server objects. You must load your server classes and then create instances of remote objects.
Register your remote objects with the registry. Each instance of a server object must be registered using the java.rmi.Naming class.
For the Client:
Write the client code. The java.rmi.Naming class is used to locate a remote server object. Methods are invoked on this remote object using the client stubs created by rmic.
Compile the client code with any Java compiler.
Start the client.
In the future, there will be greater convergence between RMI and CORBA. RMI enhancements included in the JDK 1.2 release include support for persistent object references and support for remote object activation. Sun also has announced plans to provide a version of RMI that works over the IIOP transport. This will provide RMI with built-in support for propagation of transactions, ORB-based firewall support (as opposed to the current HTTP tunneling), and interoperability with objects written in other languages via the RMI/IDL subset.