Boolean Expressions

The first point to stress is that Java requires expressions that evaluate to a boolean primitive result in flow control statements. C programmers who are used to using integer values of zero for false and nonzero for true will have to watch out for this.

Another important point has to do with the sequence of evaluation in complex logical expressions. Although you can control the sequence with parentheses, you should also study the precedence of the various arithmetic and logical operators (as shown in Chapter 3, Tables 3.2 and 3.4). For example, given the following statement

if( a + b > aMax | c + d < cMin )

you should recognize that operator precedence causes the compiler to evaluate the additions first, followed by the ...

Get Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) 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.