DEV Community 👩‍💻👨‍💻

Cover image for Is Java "pass-by-reference" or "pass-by-value" ?
Rakesh KR
Rakesh KR

Posted on

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.

Top comments (0)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.