I'm trying to understand parameter passing in Java. There are some answers on Stackoverflow but they are not clear. The Evaluation Strategy page is very technical, so I don't understand it. This answer is helpful, but I don't understand the implications: Is Java “pass-by-reference” or “pass-by-value”?
I understand the Java uses Call by Sharing, but I'm not sure how its different from Call by Reference. I'm not sure if this is correct, can you check my answers?
Shared Steps
1) The main program calls a method and passes it an argument.
2) The expression in the argument is evaluated and its type is determined. The result is assigned to the Argument variable.
Call by Value
3) Without regard for type, a COPY of the Argument's VALUE is made and passed to the method.
4) The Formal Argument receives a variable containing a COPY of the Argument.
5) The Formal Argument makes changes to the copy.
6) The Actual Argument is UNCHANGED.
Call by Reference
3) Without regard for type, a COPY of the Argument's ADDRESS is made and passed to the method.
4) The Formal Argument receives an REFERENCE to the memory location of the Argument.
5) The Formal Argument and Actual Argument point to the same value. Both can modify the Value/Object.
6) The Method can mutate the Formal Argument WITHOUT LIMITATION. When the method ends, these changes will be seen in the Argument.
Call by Sharing (Java)
3) Without regard for type, a COPY of the Argument's ADDRESS is made and passed to the method.
4) ?
5) ?
6) ?
I know there is a difference between how Java treats primitive types and objects in parameter passing, can someone fill in these blanks by explaining why?