Java always passes arguments by value. The method receives a copy of the variable, not the original. Changing the copy inside the method has no effect on the caller's variable.
public static void tryToChange(int x) {
x = 99;
}
public static void main(String[] args) {
int num = 10;
tryToChange(num);
System.out.println(num); // still 10
}
The value is copied into x. Setting x = 99 only changes the local copy. After the method returns, num is still .
This applies to object references too, but with a twist you'll see in the OOP section. The reference is copied, so you cannot reassign the original. But you can modify the object's internal state through the copied reference.