Let's see what memory situation this corresponds to.
Before studying in detail the notion of fixed-size arrays in Java,
and as we are beginning to manipulate advanced types of data, it is
important to understand that in Java, the basic types of data and the
composed, advanced types of data, aren't stored the same way
in memory. For example, if I declare a variable "x" of elementary
type, you must know that when I manipulate a variable of a basic type,
well, that variable will directly store that value. What we can observe
in this little diagram, the variable "x" directly stores the value associated
with it. This isn't the case when I begin manipulating data
of advanced types.
Data of advanced types, like arrays or strings of
characters, which we'll see in future episodes, are in fact
stored by using references, indirections, addresses.
For example, if I declare a variable of type "string of characters", we'll
see that there exists a type for that, called String, so the memory
situation is the following: the variable "v" doesn't directly store the associated
sequence of characters value, but it stores a reference, an address, to the
sequence of characters in question. And this has a strong incidence on
the semantic of assignments in Java. Imagine, for example, that I assign
a variable "v2" to a variable "v1", what does this concretely
mean? Am I modifying the stored reference in "v1"?
Or am I modifying the object referenced by "v1"?
In the same way, the "==" operator's semantic is also
impacted. What does comparing "v1" and "v2" mean? Am I comparing
references? Am I comparing the pointed sequences of characters?
We'll see that there also exists an incidence on the printing.
For example, if I print an object of composed type. What am I trying
to print? An address? Or the [content of the] referenced object? So all these questions
will arise when I manipulate composed type objects in a
Java program.
In Java, an array is an advanced type data, it is therefore manipulated
through an indirection, a reference. So if I declare-initialize
for example a variable "score" of fixed-size array of
integers type in this manner here, the memory situation will be the following:
the variable "score" doesn't directly contain the array's values,
it contains an indirection, a reference, an address to the array.
We suppose that the array's address is here. In the variable "score"
I only store the reference to this array. In jargon terms,
we'll say that the variable "score" "references" or "points to" an array of int.