The assignment statement has the following syntax:
<variable> = <expression>
which can be read as “the destination, <variable>, gets the value of the source, <expression>”. The previous value of the destination variable is overwritten by the assignment operator =.
The destination <variable> and the source <expression> must be type compatible. The destination variable must also have been declared. Since variables can store either primitive data values or object references, <expression> evaluates to either a primitive data value or an object reference.
The following examples illustrate assignment of primitive values:
int j, k; j = 10; // j gets the value 10. j = 5; // j gets the value ...