Expressions and Operators

An expression is a statement that can convey a value. Some of the most common expressions are mathematical, such as in the following source code example:

int x = 3;
int y = x;
int z = x * y;

All three of these statements can be considered expressions—they convey values that can be assigned to variables. The first assigns the literal 3 to the variable x. The second assigns the value of the variable x to the variable y. The multiplication operator * is used to multiply the x and y integers, and the expression produces the result of the multiplication. This result is stored in the z integer.

An expression can be any combination of variables, literals, and operators. They also can be method calls, because methods can ...

Get Sams Teach Yourself Java 2 in 21 Days, Second 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.