Which arguments pass by value and which pass by reference in Java?
<p>I am starting to learn Java with the Java Trails tutorials offered by Oracle. I am in the section where it talks about passing arguments to methods (http://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html).</p>

<p>It says that primitive types are passed by value, which makes sense to me. Right after that it says:</p>

<blockquote>
  <p>Reference data type parameters, such as objects, are also passed into
  methods by value. This means that when the method returns, the
  passed-in reference still references the same object as before.
  However, the values of the object's fields can be changed in the
  method, if they have the proper access level.</p>
</blockquote>

<p>Now this doesn't make sense to me. If an object is passed by value, then changing the fields of that object will change the fields of the copy inside the method, not the original one. </p>

<p>When testing with the program below:</p>

<pre><code>class Point{
        int x;
        int y;

        public static void movePoint(Point p, int x, int y){
                p.x+=x;
                p.y+=y;
        }
}

class App{
        public static void main(String argv[]){
                Point p1;

                p1 = new Point();
                p1.x = 2;
                p1.y = 3;

                p1.movePoint(p1,2,2);

                System.out.println("x = " + p1.x +  " y = " + p1.y);
        }
}
</code></pre>

<p>It worked as if the object was being passed by reference (it prints out x = 4 y = 5 after all).</p>

<p>So what exactly did Oracle mean in the passage above? Also, can anyone summarize what's passed by value and what's passed by reference in Java?</p>
