• Post Reply Bookmark Topic Watch Topic
  • New Topic

call by reference  RSS feed

 
senthil rajan
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frnds,

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.

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?

Thanks in Advance,
Senthil.
 
chanduacb chanduacb
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that is also call by value
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by senthil rajan:
Hi Frnds,

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.

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?

Thanks in Advance,
Senthil.


No. Java is always pass by value.
http://jqa.tmorris.net/GetQAndA.action?qids=37&showAnswers=true
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by senthil rajan:

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?

[QB]


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".
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!