aspose file tools*
The moose likes Java in General and the fly likes pass by value or passl by reference! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "pass by value or passl by reference!" Watch "pass by value or passl by reference!" New topic
Author

pass by value or passl by reference!

Manas Ahlaad
Ranch Hand

Joined: Nov 07, 2001
Posts: 165
java says all the variables are passed by value irrespective of they are objects are variables.

Why not objects passed by reference ???
TIA


Manas<br />Today If You are not Confused,You are just not thinking Clearly !<br />---------------------------------
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
Object references are passed by reference. Yes, a coopy of the reference is passed to a method, but changes made using thet copy of the reference are reflected in the calling method. In the case of primitives, they are passed by copy. i.e changes made in the called method are not reflected in teh calling method.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
manas
It is slightly confusing when you first hear it, but:
All variables are passed by value. For primitives the value passed is simply the value that the variable contains. For reference variables (objects and arrays) the value that the variable holds is a reference to the object or array, so it is a reference that is passed.
hope that helps


Dave
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1740
    
    2
Take a look at the Campfire story on pass by value in Java.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Corey McGlone has a neat Flash animation on his website in the SCJP section that is sure to help any beginner conceptualize what's going on.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: pass by value or passl by reference!
 
Similar Threads
Objects and References
Method parameters passed by reference/value
A question about passed by value
about system.in & system.out
Passed By Reference?