File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes it's about Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "it Watch "it New topic
Author

it's about "Argument Passing"

Nakul P. Patel
Greenhorn

Joined: May 31, 2011
Posts: 25
I am new to java,preparing for exam.
I am confused in Argument Passing.My question is....
What is "Pass by Reference" and "Pass by Value"?

please give me suitable example....
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

read this story !
Javin Paul
Ranch Hand

Joined: Oct 15, 2010
Posts: 281


In Short pass by value means you directly pass the value of argument while in case of pass by reference you pass the address where value is stored (usually passing pointers in C/C++)


http://javarevisited.blogspot.com - java classpath - Java67 - java hashmap - java logging tips java interview questions Java Enum Tutorial
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

it is sort of like the difference between mailing someone a word document and mailing them a url to a file.

pass by value makes a copy of the data and sends it over. if you make changes to what you get, it has no affect on the original.

pass by reference tells you where the file lives, so if you then go there and edit it, it is changed for everyone.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Javin Paul
Ranch Hand

Joined: Oct 15, 2010
Posts: 281


+1 for good analogy
Nakul P. Patel
Greenhorn

Joined: May 31, 2011
Posts: 25
I got it,thanks to all
John Stark
Ranch Hand

Joined: Jul 19, 2011
Posts: 185
I think it is important that in Java there is only pass by value. If you pass a reference variable pointing to some object then it is still a copy of that variable which is passes to the method. If you make changes to that object by using the variable then the changes are also done outside the method:



But if you change the variable itself inside the method then this change is local to the method as you work with a copy:



In pass by reference you pass the address where the value of the variable is stored (which cannot be done in Java). If you pass a reference variable in Java then you pass a variable containing the address of some object. The variable is pass by value and you cannot change the stored address.

John
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: it's about "Argument Passing"
 
Similar Threads
How to use XML method argument when using SOAP RPC
How to pass Java vector to a web service using Apache AXIS
CallableStatement
array ref. confusion
reading string from a Writer object