when studying RMI sometimes (head first Java) dudes use
Naming.rebind(name, object)
but other peoples on the web (oracle) use
Registry registry = LocateRegistry.getRegistry();
registry.rebind(name, object);
I know that hf java is a little old, but i don’t see the Naming class deprecated.
So, what’s the difference then?
The difference is that the
namefield toNaming.rebind()is parsed as an URL while theRegistry.rebind()is the “name to associate with the remote reference”. TheLocateRegistry.getRegistry()call assumes the registry is on the local host at the default port while theNaming.rebind()allows you to specify what registry to use.Under Java 1.6
Naming.rebind()parses thenameas an URL and callsNaming.getRegistry()with the host/port of the registry. That callsLocateRegistry.getRegistry(host, port).