2.3 Expressions and Arithmetic Operators
2.3.1 The Assignment Operator and Expressions
In a previous section, we mentioned using the assignment operator to assign initial values to variables and constants. Now let’s look at the assignment operator in more detail.
The syntax for the assignment operator is:
target = expression;
An expression consists of operators and operands that evaluate to a single value. The value of the expression is then assigned to target (target gets expression), which must be a variable or a constant having a data type compatible with the value of the expression.
If target is a variable, the value of the expression replaces any previous value the variable was holding. For example, let’s look at these instructions: ...
Get Java Illuminated, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.