Once the application has installed a usable security manager, it can then retrieve the remote object's reference from the RMI naming registry. To do so, call the static "lookup" method, passing the same name under which the object server registered the remote object. The "lookup" method will retrieve a reference to the remote object and create a stub object, here stored in the variable named "r".

If the name supplied by the client doesn't match a name in the registry, the "lookup" method throws the NotBoundException. If the supplied URL is not valid, "lookup" throws MalformedURLException. In this simple code snippet, we don't explicitly catch these exceptions, but you would in a real-world program.

Note the type of the returned reference: it's of type Remote, which is the superclass of all remote objects. But we really want a reference to a Meeting interface as defined in the remote interface. Therefore, we will need to down-cast the reference as described on the next page.