«^»
2.4. Expressions

Java's operators are similar to those of C. For example, Java has the operators +, -, *, /, and % for performing arithmetic. Each of these has an associated assignment operator. For example, the statement: a += b; has the same meaning as the statement: a = a + b;

The operator ++ is a unary operator that is used to increment its operand which must be a variable. If it is used as a prefix operator, the value of the expression is the value of the variable after it has been incremented, whereas if it is used as a postfix operator, the value of the expression is the value of the variable before it has been incremented. The operator -- behaves like the operator ++ except that the variable is decremented instead of incremented.

Java also has the relational operators ==, !=, <, <=, >, >=. It has the two operators && and ||, that can be used to and and or boolean values. Like C, these two operators do short-circuit evaluation. Unlike C, full evaluation can be performed by using the operators & and | instead.

An expression that is preceded by the name of a type enclosed in parentheses is called a cast expression. The value of the expression is converted to a value of the type. Here are two examples:

0062: double speedOfLight = ...;
0063: int roughSpeedOfLight = (int)speedOfLight;
0064: int someInt = ...;
0065: char someChar = (char)someInt;