167

What is the actual difference between Java RMI and RPC?

I have read in some places that RMI uses Objects?

user207421
  • 289,834
  • 37
  • 266
  • 440
Aran
  • 3,048
  • 6
  • 27
  • 32

8 Answers8

143

RPC is C based, and as such it has structured programming semantics, on the other side, RMI is a Java based technology and it's object oriented.

With RPC you can just call remote functions exported into a server, in RMI you can have references to remote objects and invoke their methods, and also pass and return more remote object references that can be distributed among many JVM instances, so it's much more powerful.

RMI stands out when the need to develop something more complex than a pure client-server architecture arises. It's very easy to spread out objects over a network enabling all the clients to communicate without having to stablish individual connections explicitly.

Community
  • 1
  • 1
fortran
  • 67,715
  • 23
  • 125
  • 170
  • 19
    This is incorrect. RPC is Java based as well. JAX-RPC 1.1 was replaced by 2.0, which was then renamed JAX-WS. In Java, when you talk about RPC, you are talking about SOAP and Web Services. Here is an IBM article about JAX-RPC 1.1 changing to JAX-WS. http://www.ibm.com/developerworks/library/ws-tip-jaxwsrpc/ – MattC Apr 10 '15 at 14:19
  • 2
    @MattC I think the article you linked to pointed out that the reason for this name change from "JAX-RPC" to "JAX-WS" is exactly that the original name was not accurate, as this specification involved more than just "RPC" in a traditional sense. So this answer, which talks about what RPC traditionally means, is still correct. – xji May 11 '16 at 08:55
  • 2
    yeah, what I meant is that RPC originated in the C/Unix world (at least the most common RPC implementation, ONCRPC) and as such it is modeled after that computation model; of course nothing prevents to implement it on top of any other programming language – fortran May 12 '16 at 15:13
  • 6
    A little difference of opinion on the way semantics are used don't make an answer wrong (or misleading). Anyone who reads this can easily understand that "C based" basically means "procedure oriented" - Anyone who has learnt Java knows the POP vs OOP difference. – Navin Israni Jun 19 '17 at 17:50
  • can a nodejs client(say) invoke RMI calls on server? Is there any such way? – Hitesh Bajaj Nov 04 '19 at 11:32
  • @HiteshBajaj you could use CORBA for that as RMI supports CORBA interoperability, I'm almost sure there are bindings for all imaginable languages; if you need a more elaborate answer you should ask a proper question instead of a comment. – fortran Nov 07 '19 at 12:04
  • 1
    @xji JAX-RPC is Java-based. The original Sun RPC was C-based, but the idea can be implemented in many languages, including Java. – user207421 Jan 11 '21 at 09:22
44

The main difference between RPC and RMI is that RMI involves objects. Instead of calling procedures remotely by use of a proxy function, we instead use a proxy object.

There is greater transparency with RMI, namely due the exploitation of objects, references, inheritance, polymorphism, and exceptions as the technology is integrated into the language.

RMI is also more advanced than RPC, allowing for dynamic invocation, where interfaces can change at runtime, and object adaption, which provides an additional layer of abstraction.

Barsan Ionut
  • 45
  • 1
  • 1
  • 6
Humphrey Bogart
  • 6,733
  • 12
  • 50
  • 58
18

1. Approach:

RMI uses an object-oriented paradigm where the user needs to know the object and the method of the object he needs to invoke.

RPC doesn't deal with objects. Rather, it calls specific subroutines that are already established.

2. Working:

With RPC, you get a procedure call that looks pretty much like a local call. RPC handles the complexities involved with passing the call from local to the remote computer.

RMI does the very same thing, but RMI passes a reference to the object and the method that is being called.

RMI = RPC + Object-orientation

3. Better one:

RMI is a better approach compared to RPC, especially with larger programs as it provides a cleaner code that is easier to identify if something goes wrong.

4. System Examples:

RPC Systems: SUN RPC, DCE RPC

RMI Systems: Java RMI, CORBA, Microsoft DCOM/COM+, SOAP(Simple Object Access Protocol)

Dhaval Simaria
  • 1,366
  • 2
  • 22
  • 31
  • In my application, I am using JAX-WS to expose/consume soap services. Can I call it RPC type mechanism ? As per my understanding, in JAX-WS, we are invoking remote method using java reflection API. So its matching with definition of RPC. Please confirm ! – Gunjan Shah Jul 08 '18 at 11:38
12

Remote Procedure Call (RPC) is a inter process communication which allows calling a function in another process residing in local or remote machine.

Remote method invocation (RMI) is an API, which implements RPC in java with support of object oriented paradigms.

  1. You can think of invoking RPC is like calling a C procedure. RPC supports primitive data types where as RMI support method parameters/return types as java objects.

  2. RMI is easy to program unlike RPC. You can think your business logic in terms of objects instead of a sequence of primitive data types.

  3. RPC is language neutral unlike RMI, which is limited to java

  4. RMI is little bit slower to RPC

Have a look at this article for RPC implementation in C

Ravindra babu
  • 42,401
  • 8
  • 208
  • 194
6

The difference between RMI and RPC is that:

  • RMI as the name indicates Remote Method Invoking: it invokes a method or an object. And
  • RPC it invokes a function.
nalply
  • 20,652
  • 12
  • 75
  • 93
sis
  • 77
  • 1
  • 1
  • 2
    What are the differences you implicitly emphasize, but don't clarify, between a `method` and a `function`? In Java there is no functions... but in OOP as far as I can remember, they are synonyms, and so are `invocation` and `call`. – mins Aug 29 '14 at 05:39
  • RPC invokes a procedure/function - flat out. – foo May 24 '19 at 13:42
6

RMI or Remote Method Invokation is very similar to RPC or Remote Procedure call in that the client both send proxy objects (or stubs) to the server however the subtle difference is that client side RPC invokes FUNCTIONS through the proxy function and RMI invokes METHODS through the proxy function. RMI is considered slightly superior as it is an object-oriented version of RPC.

From here.

For more information and examples, have a look here.

Kyle Rosendo
  • 23,930
  • 7
  • 75
  • 114
  • 5
    method is what functions is called in java, function is what method is called in c/c++. So still what's the difference? – starcorn Feb 09 '11 at 07:07
  • 1
    A difference is that (in the case of instance methods), there is an invoking object. The invoking object either needs to be sent (along with its code) or needs to live on the remove server but have a way to be referenced on the local server. – Ellen Spertus Feb 09 '12 at 13:40
  • Ignoring how specific programming languages treat methods vs. functions, the literary meaning is that functions return a value whereas methods modify state. – Dan Apr 05 '15 at 18:28
  • RPC invokes FUNCTIONS through the proxy function and RMI invokes METHODS using the proxy OBJECT. Right? – Noor Nawaz Sep 23 '15 at 04:36
  • The client doesn't normally 'send proxy objects (or stubs) to the server'. Poor quality citation. – user207421 Jan 02 '20 at 03:50
6

The only real difference between RPC and RMI is that there is objects involved in RMI: instead of invoking functions through a proxy function, we invoke methods through a proxy.

jiby
  • 61
  • 1
  • 1
2

RPC is an old protocol based on C.It can invoke a remote procedure and make it look like a local call.RPC handles the complexities of passing that remote invocation to the server and getting the result to client.

Java RMI also achieves the same thing but slightly differently.It uses references to remote objects.So, what it does is that it sends a reference to the remote object alongwith the name of the method to invoke.It is better because it results in cleaner code in case of large programs and also distribution of objects over the network enables multiple clients to invoke methods in the server instead of establishing each connection individually.

  • 2
    Which protocol is "RPC", specifically? To my knowledge, there's two dozen protocols for RPC, and half of those available for Java. – foo May 02 '19 at 20:18
  • @foo No doubt he is referring to Sun-RPC, but all RPCs mean Remote Procedure Call, nO objects or methods, so it isn't really relevant. – user207421 Jan 02 '20 at 03:52