10 minutes to learn Java RMI

Source: Internet
Author: User

RMI is the Java Platform for remote invocation of the specification, here is a small example, the native test through

A total of three Java classes, remote interfaces, server-side programs, client programs

Remote interface:

import java.rmi.*;

public interface HelloIn extends java.rmi.Remote{
  String sayHello() throws RemoteException;
}

Service-Side programs:

/**
* author by http://www.bt285.cn  http://www.5a520.cn
*/
import java.rmi.*;
import java.net.*;
import java.rmi.registry.*;
import java.rmi.server.*;

public class Hello extends java.rmi.server.UnicastRemoteObject implements HelloIn{
 public Hello() throws RemoteException{
  super();
 }
  public String sayHello() throws RemoteException{
  return "Hello,World!";
 }
  public static void main(String[] args){
  //System.setSecurityManager(new java.rmi.RMISecurityManager());
  try{

      Hello h=new Hello();
       java.rmi.Naming.rebind("hello",h);
      System.out.print("Ready......");
    }
   catch(Exception e){
    e.printStackTrace();
   }

 }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.