What is the difference between the Registry
class and Naming
class.
In my application I am using Registry
class. But I want to know about Naming
class and its uses ?
Java. rmi. Naming class contains a method to bind, unbind or rebind names with a remote object present at the remote registry. This class is also used to get the reference of the object present at remote registries or the list of name associated with this registry.
What is the difference between using bind() and rebind() methods of Naming Class ? The bind method bind is responsible for binding the specified name to a remote object, while the rebind method is responsible for rebinding the specified name to a new remote object.
A Java RMI registry is a simplified name service that allows clients to get a reference (a stub) to a remote object. In general, a registry is used (if at all) only to locate the first remote object a client needs to use.
There are two kinds of classes that can be used in Java RMI. A Remote class is one whose instances can be used remotely. An object of such a class can be referenced in two different ways: Within the address space where the object was constructed, the object is an ordinary object which can be used like any other object.
The difference is that Naming
is a utility class with static methods, while Registry
is a remote interface. Unsurprisingly, Naming
calls Registry
internally. Note that the name
arguments you pass to java.rmi.Naming
are in URL format, and include the location of the registry, whereas with java.rmi.registry.Registry
, the name
is just the name.
For example, you would call something like this:
Naming.rebind("//host/objName", myObj);
whereas with Registry
, you need an existing handle on the registry object, and you'd call:
Registry registry = LocateRegistry.getRegistry("host");
registry.rebind("objName", myObj);
So Naming
is really just a convenience class that saves you having to look up the Registry
manually - it performs the registry lookup and rebind in one step.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With