<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Java_remote_method_invocation</id>
	<title>Java remote method invocation - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Java_remote_method_invocation"/>
	<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Java_remote_method_invocation&amp;action=history"/>
	<updated>2026-04-05T08:24:47Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wiki.sarg.dev/index.php?title=Java_remote_method_invocation&amp;diff=28865&amp;oldid=prev</id>
		<title>imported&gt;BrainStack: /* growthexperiments-addlink-summary-summary:3|0|0 */</title>
		<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Java_remote_method_invocation&amp;diff=28865&amp;oldid=prev"/>
		<updated>2025-07-29T19:52:33Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;growthexperiments-addlink-summary-summary:3|0|0&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Java application-programming interface}}&lt;br /&gt;
[[File:RMI-Stubs-Skeletons.svg|thumb|right|400px|A typical implementation model of Java-RMI using [[Class stub|stub]] and [[Distributed object communication#Skeleton|skeleton]] objects. Java 2 SDK, Standard Edition, v1.2 removed the need for a skeleton.]]&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;Java Remote Method Invocation&amp;#039;&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Java RMI&amp;#039;&amp;#039;&amp;#039;) is a [[Java (programming language)|Java]] [[API]] that performs [[remote method invocation]], the object-oriented equivalent of [[remote procedure call]]s (RPC), with support for direct transfer of [[Serialization#Java|serialized]] Java classes and [[Distributed Garbage Collection|distributed garbage-collection]].&lt;br /&gt;
&lt;br /&gt;
The original implementation depends on [[Java Virtual Machine]] (JVM) class-representation mechanisms and it thus only supports making calls from one JVM to another. The protocol underlying this Java-only implementation is known as Java Remote Method Protocol (JRMP). In order to support code running in a non-JVM context, programmers later developed a [[Common Object Request Broker Architecture|CORBA]] version.&lt;br /&gt;
&lt;br /&gt;
Usage of the term &amp;#039;&amp;#039;&amp;#039;RMI&amp;#039;&amp;#039;&amp;#039; may denote solely the programming interface or may signify both the API and JRMP, [[IIOP]], or another implementation, whereas the term [[RMI-IIOP]] (read: RMI over [[IIOP]]) specifically denotes the RMI interface delegating most of the functionality to the supporting [[CORBA]] implementation.&lt;br /&gt;
&lt;br /&gt;
The basic idea of Java RMI, the distributed garbage-collection (DGC) protocol, and much of the architecture underlying the original Sun implementation, come from the &amp;quot;network objects&amp;quot; feature of [[Modula-3]].&lt;br /&gt;
&lt;br /&gt;
==Generalized code==&lt;br /&gt;
The programmers of the original RMI API generalized the code somewhat to support different implementations, such as a [[HTTP]] transport. Additionally, the ability to pass arguments &amp;quot;[[Call by value|by value]]&amp;quot; was added to CORBA in order to be compatible with the RMI interface. Still, the RMI-IIOP and JRMP implementations do not have fully identical interfaces.&lt;br /&gt;
&lt;br /&gt;
RMI functionality comes in the package {{Javadoc:SE|package=java.rmi|java/rmi|module=java.rmi}}, while most of Sun&amp;#039;s implementation is located in the &amp;lt;code&amp;gt;sun.rmi&amp;lt;/code&amp;gt; package. Note that with Java versions before Java 5.0, developers had to compile RMI stubs in a separate compilation step using &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;rmic&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt;. Version 5.0 of Java and beyond no longer require this step - and static stubs have been deprecated since Java 8.&lt;br /&gt;
&lt;br /&gt;
==Jini version==&lt;br /&gt;
[[Jini]] offers a more advanced version of RMI in Java. It functions similarly but provides more advanced security, object discovery capabilities, and other mechanisms for [[distributed object]] applications.&amp;lt;ref name=&amp;quot;From P2P to Web Services and Grids 2005&amp;quot;&amp;gt;{{cite book |first=Ian J |last=Taylor |title=From P2P to Web Services and Grids : Peers in a Client/Server World |series=Computer Communications and Networks |publisher=Springer-Verlag |location=London |year=2005 |isbn=1852338695 |doi=10.1007/b138333 |url=https://archive.org/details/fromp2ptowebserv0000tayl |oclc=827073874 |url-access=registration }}{{page needed|date=September 2017}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
The following classes implement a simple client-server program using RMI that displays a message.&lt;br /&gt;
&lt;br /&gt;
; &amp;lt;code&amp;gt;RmiServerIntf&amp;lt;/code&amp;gt; interface : defines the interface that is used by the client and implemented by the server. This extends the {{Javadoc:SE|module=java.rmi|package=java.rmi|java/rmi|Remote}} interface, which serves to identify an implementing class as one with remotely-invokable methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import java.rmi.Remote;&lt;br /&gt;
import java.rmi.RemoteException;&lt;br /&gt;
&lt;br /&gt;
public interface RmiServerIntf extends Remote {&lt;br /&gt;
    String getMessage() throws RemoteException;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; &amp;lt;code&amp;gt;RmiServer&amp;lt;/code&amp;gt; class : listens to RMI requests and implements the interface which is used by the client to invoke remote methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import java.rmi.Naming;&lt;br /&gt;
import java.rmi.RemoteException;&lt;br /&gt;
import java.rmi.server.UnicastRemoteObject;&lt;br /&gt;
import java.rmi.registry.*;&lt;br /&gt;
&lt;br /&gt;
public class RmiServer extends UnicastRemoteObject implements RmiServerIntf {&lt;br /&gt;
    public static final String MESSAGE = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
    public RmiServer() throws RemoteException {&lt;br /&gt;
        super(0); // required to avoid the &amp;#039;rmic&amp;#039; step, see below&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public String getMessage() {&lt;br /&gt;
        return MESSAGE;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static void main(String[] args) throws Exception {&lt;br /&gt;
        System.out.println(&amp;quot;RMI server started&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
        try { //special exception handler for registry creation&lt;br /&gt;
            LocateRegistry.createRegistry(1099);&lt;br /&gt;
            System.out.println(&amp;quot;java RMI registry created.&amp;quot;);&lt;br /&gt;
        } catch (RemoteException e) {&lt;br /&gt;
            //do nothing, error means registry already exists&lt;br /&gt;
            System.out.println(&amp;quot;java RMI registry already exists.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
           &lt;br /&gt;
        //Instantiate RmiServer&lt;br /&gt;
        RmiServer server = new RmiServer();&lt;br /&gt;
&lt;br /&gt;
        // Bind this object instance to the name &amp;quot;RmiServer&amp;quot;&lt;br /&gt;
        Naming.rebind(&amp;quot;//localhost/RmiServer&amp;quot;, server);&lt;br /&gt;
        System.out.println(&amp;quot;PeerServer bound in registry&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; &amp;lt;code&amp;gt;RmiClient&amp;lt;/code&amp;gt; class : this is the client which gets the reference (a proxy) to the remote object living on the server and invokes its method to get a message. If the server object implemented java.io.Serializable instead of java.rmi.Remote, it would be serialized and passed to the client as a value.&amp;lt;ref&amp;gt;{{cite web |last1=Wilson |first1=M. Jeff |date=2000-11-10 |df=mdy |url=https://www.infoworld.com/article/2076234/get-smart-with-proxies-and-rmi.html |title=Get smart with proxies and RMI |work=[[JavaWorld]] |access-date=2020-07-18}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import java.rmi.Naming;&lt;br /&gt;
&lt;br /&gt;
public class RmiClient {&lt;br /&gt;
    public static void main(String[] args) throws Exception {&lt;br /&gt;
        RmiServerIntf server = (RmiServerIntf)Naming.lookup(&amp;quot;//localhost/RmiServer&amp;quot;);&lt;br /&gt;
        System.out.println(server.getMessage());&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before running this example, we need to make a &amp;#039;stub&amp;#039; file for the interface we used. For this task we have the RMI compiler - &amp;#039;rmic&amp;#039;&lt;br /&gt;
*Note: we make a stub file from the &amp;#039;*.class&amp;#039; file with the implementation of the remote interface, not from the &amp;#039;*.java&amp;#039; file.&lt;br /&gt;
&lt;br /&gt;
 rmic RmiServer&lt;br /&gt;
&lt;br /&gt;
Note that since version 5.0 of J2SE, support for dynamically generated stub files has been added, and rmic is only provided for backwards compatibility with earlier runtimes,&amp;lt;ref&amp;gt;{{cite web|title=Java RMI Release Notes|url=http://docs.oracle.com/javase/1.5.0/docs/guide/rmi/relnotes.html|publisher=Oracle|access-date=9 May 2012}}&amp;lt;/ref&amp;gt; or for programs that don&amp;#039;t provide an explicit [[Port (computer networking)|port number]] (or zero) when exporting remote objects, which is required for generated stubs to be possible, as described in the [[Javadoc]] for {{Javadoc:SE|module=java.rmi|java/rmi/server|UnicastRemoteObject}}. See the comment in the constructor above.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist}}&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
*{{cite web |title=Remote Method Invocation Home |url=http://www.oracle.com/technetwork/java/javase/tech/index-jsp-136424.html |website= Oracle Technology Network for Java Developers |publisher=[[Oracle Corporation]] |location=Redwood Shores, CA, USA |access-date=2014-07-14}}&lt;br /&gt;
* [https://docs.oracle.com/javase/tutorial/rmi/index.html The Java RMI tutorial] - a good starting point to learn RMI. Also check the [https://docs.oracle.com/javase/1.5.0/docs/guide/rmi/hello/hello-world.html Hello World in RMI (Java 5)]&lt;br /&gt;
* {{Webarchive|url=https://web.archive.org/web/20120812071936/http://java.sun.com/developer/onlineTraining/rmi/RMI.html|date=12-08-2012|title=Java RMI online training (Java 7)|nolink=y}} - Very good for training JavaRMI and as reference&lt;br /&gt;
* [https://docs.oracle.com/javase/8/docs/technotes/guides/rmi/index.html The RMI page in the JDK 8 docs]&lt;br /&gt;
* {{Javadoc:SE|package=java.rmi|module=java.rmi|java/rmi}} (Java API Reference for the RMI package)&lt;br /&gt;
* {{cite web | author1= Ann Wollrath | author2= Roger Riggs | author3 = Jim Waldo |author3-link=Jim Waldo&lt;br /&gt;
  | title= A Distributed Object Model for the Java System &lt;br /&gt;
  | url=http://pdos.csail.mit.edu/6.824/papers/waldo-rmi.pdf |archive-url=https://ghostarchive.org/archive/20221010/http://pdos.csail.mit.edu/6.824/papers/waldo-rmi.pdf |archive-date=2022-10-10 |url-status=live | access-date= 2009-02-11}}&lt;br /&gt;
* [http://docs.oracle.com/cd/E12840_01/wls/docs103/rmi/rmi_intro.html Programming WebLogic RMI] - an introduction to RMI in Oracle Weblogic.&lt;br /&gt;
* [http://notes.corewebprogramming.com/student/RMI.pdf General Remote Method Invocation]&lt;br /&gt;
&lt;br /&gt;
[[Category:JDK components|RMI]]&lt;br /&gt;
[[Category:Remote procedure call]]&lt;br /&gt;
[[Category:Articles with example Java code]]&lt;/div&gt;</summary>
		<author><name>imported&gt;BrainStack</name></author>
	</entry>
</feed>