Java is strictly pass by value..I am still confused with this concept. I have gone through many websites to get an answer for this but I am not able to find any good reason. Is there any proper reason why Java is not pass by reference?
Asked
Active
Viewed 144 times
0
-
3On what level are you expecting an answer ? Is that a theoretical question ? Do you want to know the reasoning behind this design ? – Denys Séguret Jul 05 '13 at 09:58
-
1This question has been asked before: http://stackoverflow.com/questions/5298421/why-doesnt-java-support-pass-by-reference-like-c – JREN Jul 05 '13 at 09:58
-
Pointers and dereferencing where by far the least intuitive part of C++, java's pass a reference by value solves almost all the usage cases for C++'s pass by reference while avoid all the confusion. – Richard Tingle Jul 05 '13 at 10:01
1 Answers
2
The value of a reference variable
is an "address" in Java. When you pass a reference variable to a method, a new reference variable is placed on the stack and a copy of the passed reference variable's value is used to initialize the new local reference varaible's value, just like any primitive type.
That is the classic definition of pass by value
.
NOTE: While you can think of the reference as a memory address, it's not. The underlying mechanism makes it act logically as if it were though.
SHORT VERSION: references are simple variables just like the other primitive types for purposes of passing arguments to methods. What you can do with them once passed is obviously different.

Suresh Atta
- 120,458
- 37
- 198
- 307