Is Java "pass-by-reference" or "pass-by-value" ?

rakeshkr2

Rakesh KR

Posted on December 14, 2022

Is Java "pass-by-reference" or "pass-by-value" ?

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.

💖 💪 🙅 🚩
rakeshkr2
Rakesh KR

Posted on December 14, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related