Java primitive types are stored by
value, and that's important to understand because it affects the behaviour
applications when we assign values from one variable to another. Let's look
here. If I declare an initial variable called firstValue and I assign the value
100 to it, what's happening under the covers is that an area of memory is being
allocated that's named firstValue and the value 100 is stored inside that
memory. So now if I declare another variable, in this case, other value when I
assign first value to it, again, I'm looking in an area of storage, I'm giving
it a name otherValue, and when I make the assignment, the value 100 is being
copied from firstValue into otherValue. And what that means is that there is a
distinctly separate copy of that value 100 being moved over into otherValue.
What that allows me to do then is that if I make modifications to firstValue,
for example, assign the value 50 to it, that 50 replaces what's in firstValue,
but it leaves the very well called other value completely untouched, right, and
that's what I mean by being stored by value so that each primitive type
variable has its own separate copy of the data.
Comments
Post a Comment
We appreciate your valuable Suggestions/Feedback