7.11.5. Naming

Naming uses the rmiregistry server to register object references under string names and to look up the references using the names.

class java.rmi.Naming
{
  static void bind (String name, Remote obj);
  static void rebind (String name, Remote obj);
  static void unbind (String name);
  static Remote lookup (String name);
  static String [] list (String name);
}

Naturally, both the client and the server have to use the same instance of the rmiregistry server.

// Server side registration.
ExampleImpl obj = new ExampleImpl ();
Naming.rebind ("//localhost/Example", obj);

// Client side lookup.
Example obj = (Example) Naming.lookup ("//localhost/Example");
obj.printMessage ("Hello World !");