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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.