??????????


import java.rmi.Naming; 
import java.rmi.RemoteException; 
import java.rmi.server.UnicastRemoteObject; 
 
/** 
 *  
 *    MyRemoteImpl.java 
 * 
 *     ??   ??? TODO  
 *     ??   ???? MyRemoteImpl.java 
 * 
 *  ver     ?????       ???    ??????     ??????? 
 *     ???????????????????????????????????????????????????????????????????????????????????????????? 
 *  V1.00   2013-3-19   ???    ??????     ???? 
 * 
 *     Copyright (c) 2013 dennisit corporation All Rights Reserved. 
 *    
 *  Email:<a href="mailto:DennisIT@163.com">???????</a> 
 *   
 *  ????????????????????????????????й?????????м??????????UnicastRemoteObject 
 *  (????java.rmi.server)???????????????Щ???? 
 * 
 */
public class MyRemoteImpl extends UnicastRemoteObject implements MyRemote{ 
 
    /** 
     * ?????????????????????????????д?????????????????????????????????з?????????? 
     *  
     * UnicastRemoteObject?и?С??????????????????RemoteException.???????????? 
     * ???????????????????????????е????????????RemoteException.?????????????????? 
     * ?????????????????????????????????????????????????????????????????????? 
     * @throws RemoteException 
     */
    protected MyRemoteImpl() throws RemoteException { 
 
    } 
 
    /** 
     * ??????????е????????????????RemoteException 
     */
    @Override
    public String sayHello(){ 
        return "server says?? rmi hello world !"; 
    } 
 
    public static void main(String[] args) { 
        try { 
            /** 
             * ???????????????????????????????????????????????????????????RMI Registry 
             * (????????????????????????????).???????????RMI?????stub???registry?У? 
             * ??????????????????.???java.rmi.Naming??rebind()???????? 
             */
            MyRemote service = new MyRemoteImpl(); 
            /** 
             * ?????????????????t????Naming.rebind()???????????????????????????????? 
             */
            Naming.rebind("Remote Hello World"?? service); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
    } 
     

????????????


import java.rmi.Naming; 
/** 
 *  
 *    MyRemoteClient.java 
 * 
 *     ??   ??? TODO  
 *     ??   ???? MyRemoteClient.java 
 * 
 *  ver     ?????       ???    ??????     ??????? 
 *     ???????????????????????????????????????????????????????????????????????????????????????????? 
 *  V1.00   2013-3-19   ???    ??????     ???? 
 * 
 *     Copyright (c) 2013 dennisit corporation All Rights Reserved. 
 *    
 *  Email:<a href=mailto:DennisIT@163.com>???????</a> 
 * 
 */
public class MyRemoteClient { 
 
    public void exec(){ 
        try { 
            /** 
             * ???????????stub???????????????????????????.????RMI registry??.???????????綽 
             * ???????????????????????????????????. 
             * ???????RMIRegistry??????stub???? 
             * Naming.lookup("rmi://127.0.0.1/Remote Hello World"); 
             * ??????? 
             * rmi://127.0.0.1/Remote Hello World 
             * 127.0.0.1????????????????IP??? 
             * Remote Hello World?????????????????? 
             *  
             */
            MyRemote service = (MyRemote)Naming.lookup("rmi://127.0.0.1/Remote Hello World"); 
            String tmp = service.sayHello(); 
            System.out.println(tmp); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
    } 
     
    public static void main(String[] args) { 
        new MyRemoteClient().exec(); 
    } 
}