File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes HFE - Arguments and return types!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "HFE - Arguments and return types!!!" Watch "HFE - Arguments and return types!!!" New topic
Author

HFE - Arguments and return types!!!

Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
hi folks, in page 68 and 69 in HF EJB,it's mentioned that when you invoke a local method, a copy of reference is passed. whereas when a method invocation is remote, then a serialized copy of actual object is passed as opposed to a copy of a reference to the object. WHY? i don't get what would be the differences in passing a copy of reference to an object and a copy of an object itself? could you please explain it?
thanks.
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Namaste,
If you know languages which have pointers (like C, C++, Pascal), it's easy to understand. A pointer owns some address in memory. You can see a reference to an object like a sort of pointer. A variable which carries an object's address on the heap. Such an address is local to the heap it's defined for.
When you pass a copy of a reference to a *local* method, the address is still meaningful because you're still in the same heap. But if you had to pass a reference (from one JVM / one heap) to a *remote* method (other JVM / other heap), the address received wouldn't be of any use : the referenced object doesn't exist in the remote heap (and even if it did exist, its "address" would be different).
That's why a copy of the object itself must be passed to a remote method.
Best,
Phil.
Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
thanks Phil for the prompt response. but i still have some difficulties in understanding what you just said:
Originally posted by Philippe Maquet:
Hi Namaste,
When you pass a copy of a reference to a *local* method, the address is still meaningful because you're still in the same heap.

how does being in the same heap make the address that is refereneced by a copy of a reference of an object meaningful?What is *meaningful* mean here?

But if you had to pass a reference (from one JVM / one heap) to a *remote* method (other JVM / other heap), the address received wouldn't be of any use : the referenced object doesn't exist in the remote heap (and even if it did exist, its "address" would be different).

how would that address be different even if the object did exit there? or what is the point whether the object exits or not? sorry for not being able to understand this simple but fundamental concept.
i would appreciate if you could explain it in layman terms.
thanks again.
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Namaste,
how does being in the same heap make the address that is refereneced by a copy of a reference of an object meaningful?What is *meaningful* mean here?

It's not "the address that is refereneced by a copy of a reference", a reference (to an object) *is* an address (or sort of).
how would that address be different even if the object did exit there?

Let's say that you receive someone's address : Main Street 499 (address) in Santa Rosa (heap). But you're in another town (another heap). How will you find the house at Main Street 499 if you are in Brussels for instance. Maybe there is no Main Street in Brussels, or no #499, but even if this address exists there it will be another house, right ?
or what is the point whether the object exits or not?

The aim of passing a reference is to give access to the referenced object. If the latter doesn't exist, well you simply missed your goal.
Best,
Phil.
Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
Originally posted by Philippe Maquet:
Hi Namaste,
Let's say that you receive someone's address : Main Street 499 (address) in Santa Rosa (heap). But you're in another town (another heap). How will you find the house at Main Street 499 if you are in Brussels for instance. Maybe there is no Main Street in Brussels, or no #499, but even if this address exists there it will be another house, right ?

Of course we can't find the Maint Street 499 in Satan Rosa (heap) in Brussels (another heap). then there has to be the same Stanta Rosa in Brussels there so that we can find the same the Maint Street 499 ? in another words, we need to pass the whole place (object) to find that same address?
thanks.
Vladas Razas
Ranch Hand

Joined: Dec 02, 2003
Posts: 385
Namaste,
whereas when a method invocation is remote, then a serialized copy of actual object is passed as opposed to a copy of a reference to the object.
There is no remote and local methods. Only remote and local bean interfaces. Ok. You can have bean with both local and remote interfaces but Kathy and Bert say it's not what you want to do.
WHY? i don't get what would be the differences in passing a copy of reference to an object and a copy of an object itself? could you please explain it?
Because when you pass reference you pass something like address of object on your machine. The remote machine can not look into your address space. That is why object is passed as whole.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: HFE - Arguments and return types!!!