Boolean Logical AND (&) and Boolean Logical Inclusive OR (|) Operators

The boolean logical AND (&) and boolean logical inclusive OR (|) operators are identical to the && and || operators, except that the & and | operators always evaluate both of their operands (i.e., they do not perform short-circuit evaluation). So, the expression

(gender == 1) & (age >= 65)

evaluates age >= 65 regardless of whether gender is equal to 1. This is useful if the right operand has a required side effect—a modification of a variable’s value. For example, the expression

(birthday == true) | (++age >= 65)

guarantees that the condition ++age >= 65 will be evaluated. Thus, the variable age is incremented, ...

Get Java™ How To Program (Early Objects), Tenth 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.