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
Joined: Feb 03, 2007
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
Joined: Sep 19, 2007
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).
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.