Pass-by-value Semantics in Java Applications
By Peter Haggar2003-11-24
The key point
After reading all of the comments, it became clear that there is at least one major point of confusion. Some comments said that my excerpt is wrong because objects are passed by reference. It is true that objects are passed by reference; the excerpt was not contradicting that. The excerpt said that all parameters are passed by value -- a different argument. It is correct that you never pass an object in a Java application, only an object reference. Therefore, you are passing objects by reference. However, it is important to distinguish how parameters are passed, and that was the intent of the excerpt. The fact that a Java application passes objects by reference does not mean that a Java application passes parameters by reference. Parameters can be object references, and a Java application passes object references by value.
Tutorial Pages:
» Pass-by-value semantics in Java applications
» The key point
» Parameter passing in C++ and Java applications
» Examples
» Writing a swap method
» Resources
First published by IBM DeveloperWorks
