Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing Argument in RMI is by copy or by reference?

 
walter wang
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All
passing argument in RMI is by copy or by reference?
thanks
 
Devrim Turker
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When invoking a method using RMI-IIOP, all parameters to the remote method are passed by value. This means that when client calls
a server, all parameters are copied from one machine to the other.
When you call a method in java and pass an object as a parameter, that is passed by reference.
Java introduces the concept of object serialization to handle passing by value problem.
Serialization is the conversion of a Java object into a bit-blob representation of that object
Your class must implement java.io.serializable and transient variables are not serialized
From "MasteringEJB2" by Ed Roman
Have Fun
 
Craig Demyanovich
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Devrim is correct in that object parameters passed in an RMI call are passed by value (copy) via a serialized form. However, object parameters passed in a local method call are also passed by value: a copy of the object reference is passed. For example, consider the following code:

The output is "less filling." setDescription() changed only its copy of the reference, not the reference itself.
Now, String is immutable. If we pass a mutable parameter, such as a StringBuffer instance, the logic above is still correct. However, you could change the object via one of its public mutators. Let's repeat the example above:

This time, the output is "tastes great." setDescription() used its copy of the reference to change the internal state of the reference. Again, though, changing the reference itself has no effect on the reference held by the caller.
Craig
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!