0

Possible Duplicate:
Is Java pass by reference?

In java are the parameters passed by reference or by value

Community
  • 1
  • 1
billu
  • 2,415
  • 3
  • 23
  • 31
  • 1
    And other duplicates or near-dups: http://stackoverflow.com/questions/498747/java-pass-by-value-reference-variables http://stackoverflow.com/questions/589919/does-java-pass-by-reference – T.J. Crowder May 27 '10 at 12:11
  • Are these preparing-for-interview questions? – shinynewbike May 27 '10 at 12:17

4 Answers4

6

All parameters in Java are passed by value. However, for reference types those values are references.

There are plenty of articles on this, including this one and my own one.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
5

There is exactly one parameter passing mode in Java -- pass by value -- and that helps keep things simple. -- James Gosling, "The Java Programming Language, Second Edition" (James Gosling being the father of Java)

Java is pass by value - always, for everything.

duffymo
  • 305,152
  • 44
  • 369
  • 561
5

Short answer: by value, where the value is sometimes a reference.

Longer answer: Any primitive type will be simply passed by value. For non-primitives, you don't hold the object, but only a reference to it. This reference is passed by value.

unbeli
  • 29,501
  • 5
  • 55
  • 57
0

Required reading on this subject (taken from javabot on irc://chat.freenode.net/##java):

http://javachannel.net/wiki/pmwiki.php/FAQ/PassingVariables

http://www.javaworld.com/javaworld/javaqa/2000-05/03-qa-0526-pass.html

http://javadude.com/articles/passbyvalue.htm

whaley
  • 16,075
  • 10
  • 57
  • 68