What is the difference between Java RMI and JMS?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Java RMI (Remote Method Invocation) and JMS (Java Messaging Service) are both integral parts of Java-based distributed computing, but they serve distinct purposes and operate under different paradigms. This distinction is especially crucial for software developers and system architects who need to choose the appropriate communication mechanism depending on the requirements of their applications.
Java RMI (Remote Method Invocation)
Java RMI is a mechanism that allows one Java Virtual Machine (JVM) to invoke methods on an object residing in another JVM. RMI facilitates the development of distributed Java applications, where the components can interact over a network. The objects communicating via RMI can pass and return primitives or serializable Java objects.
Key Operation Steps in RMI:
- Define the remote interfaces: These are Java interfaces that declare the methods that can be invoked remotely.
- Implement the remote interfaces: These implementations must extend
UnicastRemoteObjectand implement the remote interface. - Compile and deploy the application: RMI requires generating stubs and skeletons; however, post Java 5, this process is automated.
- Use the
Namingclass for registry service: RMI uses a registry service to obtain references of remote objects.
Example of RMI:
Java Messaging Service (JMS)
JMS is a Java API for sending messages between two or more clients. It is an integral part of the Java EE platform. JMS supports both message queueing and publish-subscribe styles of messaging. Unlike RMI, JMS is inherently asynchronous and loosely coupled, meaning the producer and consumer of the message do not need to be available at the same time.
Key Components of JMS:
- JMS Provider: An implementation of the JMS interface for message-oriented middleware (MOM).
- JMS Producer/Publisher: Sends messages to the JMS provider.
- JMS Consumer/Subscriber: Receives messages from the JMS provider.
- JMS Message: An object that encapsulates data in a format understandable to both the sender and receiver.
Example of JMS:
Comparison Table
| Feature | Java RMI | JMS |
| Communication Style | Synchronous | Asynchronous |
| Coupling | Tight | Loose |
| Architecture | Method invocation on objects | Producer-Consumer messaging |
| Registry Required | Yes (RMI Registry) | No (Broker-based, e.g., Apache ActiveMQ) |
| Use Case | Real-time systems, distributed objects | Decoupled systems, various subscribers |
| Reliability | Dependent on network connection | Provides delivery modes, durable subscriptions |
Conclusion
Choosing between Java RMI and JMS largely depends on the specific needs of your application. For tightly coupled, synchronous interactions where method calls need to be made on remote objects, Java RMI is suitable. In contrast, for applications requiring high levels of decoupling, reliability, and asynchronous processing, JMS is preferable. Understanding these technologies and their suitable use cases ensures the design of more efficient and robust distributed systems.
Related reading
- What is the difference between Java RMI and RPC?
- What is the difference between javac and the Eclipse compiler?
- What is the difference between JDK and JRE?
- What is the difference between JDK dynamic proxy and CGLib?
- What is the difference between JSF, Servlet and JSP?
- What is the difference between JVM, JDK, JRE & OpenJDK?
- What is the difference between List.of and Arrays.asList?
- What is the difference between MANUAL and MANUAL_IMMEDIATE in spring-kafka AckMode

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.