More Tutorials| Bioinformatics| Open Source| Photoshop| Questions? | Software Development
 

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 HelloInterface.java in the Directory.

 

    

 

 

HelloInterface.java:-

 

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

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


Hello.java

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

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


Step3.
Compile the above two Source file named HelloInterface.java and Hello.java.



Step4.
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 HelloServer.java

HelloServer.java

import java.rmi.Naming;

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


Step6.
Create Client application named HelloClient.java

HelloClient.java

import java.rmi.Naming;

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


Step6.
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

 

                         

» View all related tutorials
Related Tags: java c object io objects remote method distributed display port rmi using this message porting support basic for example to

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

2 comments so far (
post your own) View All Comments Latest 10 Comments:

thanks a lot

Posted by Quoc Anh on Friday, 12.12.08 @ 20:19pm | #82697

this is very good site for java programming.

Posted by shruti on Thursday, 12.4.08 @ 00:24am | #82354

 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.