aspose file tools*
The moose likes Beginning Java and the fly likes definition of call by reference and call by value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "definition of call by reference and call by value" Watch "definition of call by reference and call by value" New topic
Author

definition of call by reference and call by value

Praveen Pagi
Greenhorn

Joined: Feb 17, 2009
Posts: 6
Dear all,

I am a new bie to java.
i want to know the difference between call by reference and call by value definition.

Thanks & Regards.
rakesh kumar nampally
Ranch Hand

Joined: Feb 03, 2007
Posts: 46
In both the cases you will send the copies to the calling method as arguments. But the difference is when you pass the reference to method if that method changes the (primitive, reference)values of the reference then the original values wil get reflected, which is not the same in case of primitive values.


thanks & regards, Rakesh
Benjamin Winterberg
Ranch Hand

Joined: Sep 19, 2007
Posts: 36
Call by Value means that method arguments are the values of the original objects. This means a "copy" of the object will be given to the method. You cannot change the state of the original object from inside the method.
Call by Reference means, that methods arguments are just references to the original objects. This means you can change the state of the original object from inside the method.

Java does only provide call by value. Primitive values (e.g. int, long) are copied, so does references! The consequence is that you can change the object state from inside a method but you cannot change the reference itself (because its a copy of the original reference).


Hibernate DAOs with Spring | Separation of Concerns | Eclipse Code Templates | more...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39833
    
  28
Welcome to JavaRanch

Thank you for replying, both of you, but your replies were confusing, and I am not convinced you have understood pass-by-value and pass-by-reference.

This question has come up several times; look at this thread where I replied only a few minutes ago. Note the links to older threads and a JavaRanch FAQ. See whether any of those is helpful. There is one link in the old thread where it describes what happens in Pascal, which does support pass-by-reference.

The post again and see whether you have understood the problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: definition of call by reference and call by value