Java passes a reference by value, this gives it the feel of being pass by reference despite actually being pass by value.
public class Main{
public static void main(String[] args) {
Vector3d vectorTest=new Vector3d(1,2,3);
System.out.println(vectorTest.x); //prints 1
affectVector(vectorTest);
System.out.println(vectorTest.x); //prints 100
replaceVector(vectorTest);
System.out.println(vectorTest.x); //still prints 100
}
public static void affectVector(Vector3d vectorIn){
vectorIn.x=100;
}
public static void replaceVector(Vector3d vectorIn){
//this method has no external effect because the reference vectorIn is immediately overrwritten
vectorIn=new Vector3d(0,0,0); //the reference vectorIn is completely changed
}
}
You can see that because a reference is passed by value you can still access the object that it refers to but if you replace the reference then you are 'refering' to a different object and that has no effect outside the method.
The analogy I use when trying to describe this is that of postal addresses. A reference is a postal address that you use to send letters (instructions) to objects. You can copy that address onto many pieces of paper but it still sends letters to the same house. It is the postal address that is copied, not the 'house'