What is the difference between pass by value and pass by reference in Java?
Printable View
What is the difference between pass by value and pass by reference in Java?
Try searching in bing or google for "What is the difference between pass by value and pass by reference in Java?".
There are no references in java
The parameter passing mechanism in Java is always by_value. The by_reference passing mechanism doesn't exist in Java. It means whatever you pass (a primitive or a reference) to a method it will be copied before it is available in the method.
It's important to understand that objects are always represented/handled indirectly by so called references in Java. A reference can be thought of as a "pointer" to an object. Therefore you could claim that "in Java an object is passed by its reference" but that doesn't mean the passing mechanism is by_reference (in the computer science sense of the term). So a reference is passed indeed but it is by_value, hence the confusion.