import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;


public class HelloServer implements HelloInterface {
        
    public HelloServer() {}

    public String sayHello() {
        return "Hello, world!";
    }
        
    public static void main(String args[]) {
        try {
            HelloServer obj = new HelloServer();
            HelloInterface stub = (HelloInterface) UnicastRemoteObject.exportObject(obj, 0);

            // Bind the remote object's stub in the registry
            Registry registry = LocateRegistry.getRegistry();
            registry.bind("Hello", stub);

            System.err.println("Server ready");
        } catch (Exception e) {
            System.err.println("Server exception: " + e.toString());
            e.printStackTrace();
        }
    }
}
