I can see what is confusing you, let me show you an exmaple.
MyClass.java
public class MyClass {
private int i;
private int[] a;
public void setI(int i){
this.i = i;
}
public void setA(int a[]){
this.a = a;
}
public int getI(){
return i;
}
public int[] getA(){
return a;
}
}
Test.java
public class Test {
public static void main(String[] args)
{
int a[] = {1,2};
MyClass myClass = new MyClass();
myClass.setI(5);
myClass.setA(a);
int i = myClass.getI();
int b[] = myClass.getA();
System.out.println(myClass.getI());
System.out.println(myClass.getA()[0] + " " +myClass.getA()[1]);
i = 10;
b[0] = 3;
b[1] = 4;
System.out.println(myClass.getI());
System.out.println(myClass.getA()[0] + " " +myClass.getA()[1]);
}
}
When you see output of the above code you'll realize, primitive types like integer are always passed by value in Java. But when you pass arrays or other objects, like an object of Calendar class, it will be passed by reference.
Therefore changing value of array will be reflected at both the places while of an integer, wont.
This answer is acceptable to any suggestions. If anybody finds any inaccuracy, feel free to suggest edits.