I know when starting an RMI registry I can use either LocateRegistry.createRegistry(port) or running the rmiregistry.exe program. I tried to export objects using UnicastRemoteObject.exportObject(obj,port) and used the same port number as the RMI registry port. If I started the RMI registry using LocateRegistry.createRegistry, it works fine. But if I started it using rmiregistry.exe, I get a port already in use exception. I understand why I get the port in use exception, but why don't I get it when I've started the reigstry using LocateRegistry.createRegistry? Thanks.
RMI registry is just another RMI server object and RMI has a concept of sharing the same server socket for multiple server objects, as specified here.
In case you start the registry from outside the JVM, the JVM can not share the socket as it is a different process but if you start it using LocateRegistry, then RMI can share the port between two server objects.
P.S.: I do not have a document that talks about this but this is according to my understanding of RMI.