Java is a "pass-by-value" language, which means that when an argument is passed to a method, the value of the argument is copied and passed to the method, rather than a reference to the original object. This means that any changes made to the argument within the method have no effect on the original object outside of the method.
In contrast, a "pass-by-reference" language would pass a reference to the original object, rather than a copy of the value, so any changes made to the object within the method would be reflected in the original object outside of the method.
The "pass-by-value" behavior of Java can be counterintuitive at times, especially for programmers who are accustomed to languages that use "pass-by-reference." However, it is a fundamental aspect of the language and is important to understand in order to write correct and effective Java code.
Latest comments (2)
Yes, Java is "pass-by-value" language.
But the value of the argument can be a reference to an object (the argument can be a variable defined for a primitive or an object). And, the argument can be used to modify the original referenced object.