Share on Google+Share on Google+

Displaying Hello using RMI

This Example describes the way to display Hello message using RMI. By RMI we mean Remote Method Invocation. RMI serves as a basic technique for supporting distributed objects in java.

Displaying Hello using RMI


This Example describes the way to display Hello message using RMI. By RMI we mean Remote Method Invocation. RMI serves as a basic technique for supporting distributed objects in java. The steps involved in displaying message Hello are described below:-

Step1.Create a Remote interface named in the Directory.


import java.rmi.*;
public interface HelloInterface extends Remote {
  public String say() throws RemoteException;

Create an Remote Class implementation for HelloWorld named in the Directory.

import java.rmi.*;
import java.rmi.server.*;

public class Hello extends UnicastRemoteObject 
HelloInterface {
  private String message;
  public Hello (String msg) throws RemoteException {
  message = msg;
  public String say() throws RemoteException {
  return message;

Compile the above two Source file named and

After compiling the above two classes type the following command i.e-"rmic Hello" in console just like displayed below.

Your Directory Structure will be like this.By running the "rmic Hello" command a new class will be created i.e "Hello_Stub.class" in the directory

Step5.Create Server application named

import java.rmi.Naming;

public class HelloServer 
  public static void main (String[] argv) 
  try {
"Hello"new Hello ("Hello,From pvt ltd!"));
"Server is connected and ready for operation.");
  catch (Exception e) {
  System.out.println ("Server not connected: " + e);

Step6.Create Client application named

import java.rmi.Naming;

public class HelloClient 
  public static void main (String[] argv) {
  try {
HelloInterface hello =(HelloInterface)
 Naming.lookup (
  System.out.println (hello.say());
  catch (Exception e){
  System.out.println ("HelloClient exception: " + e);}

Compile both of the files.

Step7.Type "rmicregistry" on commandprompt and press ENTER.


Step8.Type java HelloServer in commandprompt and press ENTER.The following message will be displayed on console.

Step9.Now,open another separate command terminal,and run the client application like shown in the figure given below:-

Step10. If the message similar to the above appears in figure comes means that you have implemented your RMI application.


Download Source Code





Posted on: September 29, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Displaying Hello using RMI   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
Anshul Agarwal
June 28, 2011
Error in the above example

When I am executing the command "java Hello Server" this error is coming : D:\wkspc23July\MyHello\src>java HelloServer Server not connected: java.rmi.ServerException: RemoteException occurred in serv er thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested excep tion is: java.lang.ClassNotFoundException: Hello_Stub The Hello_Stub file is alredy created.
November 28, 2011

Some correction in above program 1. Use rmiregistry on Step 7. 2. In please change to ur ip address.. you can find one by going to cmd and type the command ipconfig.. Thanks for this wonderful program.. :)
April 22, 2012

thanks a lot for such a meaning full Knowledge ....
December 8, 2012

when i compile it gives error: cant find symbol "HelloInterdface"
November 25, 2012

hello friends 1. i am getting connection refused to host when running this rmi codes 2. rmicregistry does'nt working , i have jdk7 may be it causes? best regards mamuka arabuli
January 1, 2013

I am getting rmiregistry error when i am running the application
January 1, 2013
rmi running problem

whenever i am typing rmi Hello it gives class Hello not found please help me
December 3, 2012

rmicregistry is not executing the error is this is not an internal or external command
July 2, 2013
asking doubt

while i exeute getting errors as cannot find symbol sir... pls send solution for me to my mail