if (x == true || y == false) {
// ...
}
The && ("conditional AND") and || ("conditional OR") operators perform the same logical function as the
simple & and | operators, but they avoid evaluating their right operand if the truth of the expression is
determined by the left operandfor this reason they are sometimes referred to as "short-circuit operators." For
example, consider:
if (w && x) { // outer "if"
if (y || z) { // inner "if"
// ... inner "if" body
}
}
The inner if is executed only if both w and x are TRue. If w is false then x will not be evaluated because
the expression is already guaranteed to be false. The body of the inner if is executed if either y or z is
TRue. If y is TRue, then z will not be evaluated because the expression is already guaranteed to be TRue.
A lot of code relies on this rule for program correctness or efficiency. For example, the evaluation shortcuts
make the following code safe:
if (0 <= ix && ix < array.length && array[ix] != 0) {
// ...
}
The range checks are done first. The value array[ix] will be accessed only if ix is within bounds. There
is no "conditional XOR" because the truth of XOR always depends on the value of both operands.
9.2.4. instanceof
The instanceof operator evaluates whether a reference refers to an object that is an instance of a particular
class or interface. The left-hand side is a reference to an object, and the right-hand side is a class or interface
name. You learned about instanceof on page 92.
9.2.5. Bit Manipulation Operators
The binary bitwise operators are:
& bitwise AND
| bitwise inclusive OR
^ bitwise exclusive or (XOR)
The bitwise operators apply only to integer types (including char) and perform their operation on each pair
of bits in the two operands. The AND of two bits yields a 1 if both bits are 1, the OR of two bits yields a 1 if