By Value or By Reference : Method Parameters « Class Definition « Java Tutorial

  1. Primitive variables are passed by value.
  2. reference variables are passed by reference.
  3. When you pass a primitive variable, the JVM will copy the value of the passed-in variable to a new local variable.
  4. If you change the value of the local variable, the change will not affect the passed in primitive variable.
  5. If you pass a reference variable, the local variable will refer to the same object as the passed in reference variable.
  6. If you change the object referenced within your method, the change will also be reflected in the calling code.
5.7.Method Parameters
5.7.1.By Value or By Reference
5.7.2.Reference Passing Test
5.7.3.Passing objects to methods
5.7.4.Use an array to pass a variable number of arguments to a method. This is the old-style approach to variable-length arguments.