I'm wondering can both the
UnicastRemoteObject.exportObject(Remote,portNo) &
LocateRegistry.createRegistry(portNo);
portNo be the same?
Yes, unless you are using unequal socket factories, which you aren't. If there is a problem an exception will be thrown.
I test it works but I'm worrid if there is any complication?
Not at all, in fact it's a good idea, saves on listening ports. You can use Registry.REGISTRY_PORT which is reserved at IANA, and should therefore shut down any arguments with netadmins too.
Why does exportObject need to specify an object to work?
Because it is a static method.
when I use exportObject(Remote obj) it throws an
StubNotFoundException.
Because you haven't generated a stub. If you are using >= 1.5, you don't need a generated stub, but you do need to specify a port number. If you specify zero you will get a system-allocated port number but if you have already exported a remote object, in this case the Registry, you will share its port, again unless you are using unequal socket factories.