This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Local call involves pass-by-reference 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 "Local call involves pass-by-reference" Watch "Local call involves pass-by-reference" New topic
Author

Local call involves pass-by-reference

Parvathi G
Greenhorn

Joined: Dec 17, 2005
Posts: 28
Hi,
When I am going through EJB 2.0 specs, it is specified that when we are using Remote interface the the argument are passed by value ( Copy of the object), this is fine. But when we are using the Local interface then it is pass-by-reference.
Is it mean that a copy of the reference is passed, which we call as pass-by-value. Bcoz there is no pass-by-reference in Java ( It is only a copy of the reference value).
Please correct me if I am wrong

Thanks & Regards,
Parvathi.
Kai Witte
Ranch Hand

Joined: Jul 17, 2004
Posts: 356
hello Parvathi,

well observed. You are right, and the spec is wrong. With "pass-by-reference" they mean "pass-by-value", and with "pass-by-value" they mean that the passed object is copied before it is being passed.

You will find this nonstandard phrasing in common EJB literature.

Kai


Kai Witte's business website Kai Witte's private homepage
Rajan Murugan
Ranch Hand

Joined: Jun 24, 2006
Posts: 182
hi parvathi,you are probably trying to corelate java with c/c++ which is stopping you to see what it is conveying.

when we make a call to a method meth1(10); value 10 is passed but
when i make a call with say

int i=10;
meth1(10); it still is "passing by value"

as long as it is primitive all is fine.

if it is a object

person p1=new person();
meth1(p1);

Here the actual object is not passed to meth1() rather copy of reference for the same person object is passed.


so if the method declaration is meth1(int somearg)

then p1 and somearg both point to the same person object.

This would be pass by reference.


the above explanation holds true for objects/references in the same JVM.
things will be different when remote method calls are involved.


With Regards,<br /> Rajan<br />"Java Rocks"
Kai Witte
Ranch Hand

Joined: Jul 17, 2004
Posts: 356
hello,

no, Rajan, there is no pass-by-reference in Java at all. Parvathi is right, and the EJB specification uses the term in an unusual way.

Kai
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
When will this pass-by-reference myth stop? Unfortunately, I postulate never (reasons withheld). Ultimately, one must think for oneself in order to derive any form of truth.


Tony Morris
Java Q&A (FAQ, Trivia)
Rajan Murugan
Ranch Hand

Joined: Jun 24, 2006
Posts: 182
hi kai,

can you point out what you mean by pass-by-reference.It will ok even if need to explain with C/C++ examples.
Kai Witte
Ranch Hand

Joined: Jul 17, 2004
Posts: 356
hello Rajan,

I'm sure that has been discussed in the beginner forum many, many times.

Kai
Rajan Murugan
Ranch Hand

Joined: Jun 24, 2006
Posts: 182
hi kai,

In my explanation I have in fact told the copy of reference is passed.

Irrespective of how the things happen internally/actually the spec says this is pass by reference.

Still the link that you showed does not convey the advantage/disadvantage of pass by reference and what it actually means. :roll:
S Thiyanesh
Ranch Hand

Joined: Mar 19, 2006
Posts: 142
Pass by Reference in C / C++:

In C/C++ the new object assigned in the called method is reflected in the original calling method. This is pass by reference.


But in java there is only pass by value:

Here the new object allocated in the called method is not reflected in the original calling method. This is pass by value.

Hope this is clear.
[ November 02, 2006: Message edited by: S Thiyanesh ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Local call involves pass-by-reference