Java pass by value and pass by reference.

April 29th, 2008

Pass by value means passing a copy of the value to be passed. Pass by reference means the passing the address itself. In Java the arguments are always passed by value. Java only supports pass by value. With Java objects, the object reference itself is passed by value and so both the original reference and parameter copy both refer to the same Java object. Java primitives too are passed by value.

Java is strictly ‘Pass By Value’

Abhishek Khandelwal on November 3rd, 2009 9:30 pm

For Java newbies, this explanation can be confusing. It would be
better to explain by example. The reason is because with Java
primitives, the results are different than with objects.

The problem comes in because, for primitives, the value of the
argument can be altered (in the method), but it doesn’t affect the
source variable. With an object reference being passed, that
object can be operated on (in the method) and its values changed.

Big difference.

mjt on December 17th, 2009 9:52 am





hidden and gravatar enabled.