Java Parameter Passing is 'Pass By Value' Or 'Pass By Reference'
This article delves into the topic of whether java has parameter passing by value or reference.
Parameter passing basics
There are two ways in which parameter values are passed around in programming languages -
- Pass By Value: Here a copy of the parameter value is made when it is passed between methods. I.e a new variable is created in memory in the called method which has scope local to that method. Any change done to the variable value in called method has no bearing on the variable value in the original calling method.
- Pass by Reference: Here a reference to memory location where the variable is stored is passed to the called method. So, the called method and the calling method both operate on the same variable copy. I.e. any changes done on the variable in either the calling or the called method reflects in both methods.