What does Server object, Remote object mean in RMI Java?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Remote Method Invocation (RMI) in Java is a mechanism that allows an object residing in one Java Virtual Machine (JVM) to invoke methods on an object running in another JVM. This is one of the fundamental techniques used in building distributed applications in Java. Integral to this process are the concepts of the "Server object" and "Remote object".
Understanding the Server Object and Remote Object
Server Object: In Java RMI, the server object refers to the object that resides on the server-side of a client-server network. It implements one or more remote interfaces and is responsible for handling client requests. Upon receiving a method invocation from a client, it processes the request, performs the necessary operations, and optionally, returns a result to the client.
Remote Object: Generally speaking, a remote object in RMI is any object whose methods can be invoked from another JVM. Technically, a remote object can be both a client and a server because it handles requests from remote clients and may also serve as a client to other remote objects. To be considered a remote object, an object must implement a remote interface, which is a special Java interface that declares the methods that can be called remotely.
Technical Implementation in RMI
To enable the distributed operation, RMI utilizes several key components:
- Remote Interface: This defines the methods that can be called remotely. Each method must declare
java.rmi.RemoteExceptionin its throws clause, which is the checked exception used to report any issue that occurs during a remote method call. - Stub and Skeleton (used in classic RMI, though replaced by just stubs in more recent Java versions):
- Stub: Acts as a gateway on the client side. It is a proxy that represents the remote object and forwards client requests over the network to the server.
- Skeleton: Used in early versions of RMI, the skeleton was present on the server side and handled dispatching the incoming requests to the actual server objects methods. This component is no longer needed as of Java 2 (JDK 1.2) and later.
- Registry Service: RMI uses a registry service (typically running on the server) where remote objects can be registered by their names. Clients look up these objects by name to obtain a reference to the stub which can then be used to invoke methods remotely.
Example Implementation
For a clearer understanding, consider a simple example where a Calculator remote interface has methods to perform basic arithmetic operations. Here’s what the setup might look like:
A server-side implementation of this could be:
A client needs to look up the Calculator object in the RMI Registry and invoke its methods:
Comparison Table for Server and Remote Objects
| Feature | Server Object | Remote Object |
| Definition | Object that processes client requests on server-side. | Object that can have its methods invoked from another JVM. |
| Example | CalculatorImpl in RMI server. | Both CalculatorImpl on server and proxy (stub) in client. |
| Role | Typically provides the implementation of services. | Acts as server or client or both. |
| Location | Resides in the server JVM. | Can reside in any JVM (client or server) involved in RMI. |
Conclusion
Understanding the roles and functioning of server and remote objects in Java RMI is foundational in developing distributed Java applications effectively. Their correct implementation allows for seamless, location-transparent method invocations across JVMs, helping to architect robust multi-tier applications.

