This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Local call involves pass-by-reference

 
Parvathi G
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rajan Murugan
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kai Witte
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rajan Murugan
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello Rajan,

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

Kai
 
Rajan Murugan
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic