I wonder if both
UnicastRemoteObject.exportObject(Remote,portNo) & LocateRegistry.createRegistry(portNo);
will portNo be the same?
Yes, unless you are using unequal socket factories that you are not. If there is a problem, an exception will be thrown.
I am testing it, but am I worried if there are any complications?
Not at all, this is actually a good idea, it saves you when listening to ports. You can use Registry.REGISTRY_PORT, which is reserved in IANA, and therefore should disable any arguments with netadmins.
Why should exportObject specify an object to work with?
Because it is a static method.
when I use exportObject (Remote obj), it throws a StubNotFoundException.
Because you did not create a stub. If you use> = 1.5, you do not need the generated stub, but you need to specify the port number. If you specify zero, you will get the port number assigned to the system, but if you have already exported a remote object, in this case you will share your port in the registry again if you do not use unequal socket factories.
source share