Generally in Java if u pass a object to a method its consider as call by reference. It means the actual memory location is being passed instead of copy of the object.
No, that's not what happens at all. Maybe if 'u' does it with some weird version of Java that's not compatible with the official standard it works like that, but if you (or anyone else) does it with a standards compliant JVM what gets passed is a copy of the reference to the original data, thus pass by value.
Originally posted by senthil rajan: [QB] My question is, when we use RMC, that is when we pass the object to the remote method, will it consider as call by reference? how it shares the same object?
In that case a copy of the original object will be passed to the remote JVM which will then pass a reference to that copy to the remote method. More insidious as now any changes to the object made through its reference are not reflected in the object on the other side of the connection (as would have been the case in a local call).
So effectively a local call is the equivalent of using "const classname&" as a parameter in C++ while a remote call would be equivalent to "const classname& const".
Note that how RMI parameters are treated depends on the type of the parameters.
Primitives are pass by value, of course. Instances of classes are copied over the wire, so the value of the formal argument is a reference to a copy of the original parameter object (just as has been explained above.)
But if, in JVM #1, I call a remote method in JVM #2, and I pass as an argument a reference to an object in JVM#1 that implements java.rmi.Remote, then a copy of the remote reference is passed -- i.e., the object itself remains in JVM#1; so this situation is like a normal Java method call, in which a copy of a reference is passed.