Remote Method Invocation in java

Savin Abeysooriya
2 min readJul 11, 2020

The RMI (Remote Method Invocation) is an API that provides a mechanism to create distributed application in java. The RMI allows an object to invoke methods on an object running in another JVM.The RMI provides remote communication between the applications using two objects stub and skeleton.

Here we gonna create a simple java application using RMI API. This is a simple math operation application mainly operate add, subtract, multiply and divide. First, We have to create following 4 files.

01. MathService.java

02. MathServer.java

03. MathClient.java

04. allowall.policy

MathService.java
MathServer.java
MathClient.java
allowall.policy

after create these files, then open the terminal and compile all the files using “javac *.java” command. Then you can see some additional files has been crated in the folder like below.

Then execute the command “rmic MathServer” to create servers stub. Then start the rmiregistry using the command “start rmiregistry”. After that open the new terminal in the same directory and execute the command “java -Djava.security.policy=allowall.policy Mathserver “ to start the MathServer by giving security policy.

Then open the new terminal in the same directory and execute the command “java -Djava.security.policy=allowall.policy MathClient”to start the MathClient by giving security policy. After finishing this you can see both MathClient and MathServer start and show their results.

--

--