- Home
- Objectives

- XyzWs Study Guides
- Study Guides
- Study Notes
- Resources

- Mock Exams
SCJP Study Guide:
Fundamentals
Printer-friendly version |
Mail this to a friend
Boolean or Logical Operators
The && and || operators are called the conditional logical operators. They are also called the "short-circuiting" logical operators.
| NOT | ! |
| AND | && |
| OR | || |
| EXCLUSIVE OR | ^ |
Conditional Boolean Operator (&&, ||)
The operation is processed as follows:
-
The operation
A && Bis evaluated asA ? B : false. In other words, Java evaluates A first. If A is true, then Java evaluates B and this becomes the result of the operation. If A is false, then Java does not evaluate B and the result of the operation is false. -
The operation
A || Bis evaluated asA ? true : B. In other words, Java evaluates A first. If A is true, then Java does not evaluate B and the result of the operation is true. If A is false, then Java does evaluate B and this becomes the result of the operation.
Logical Complement Operator !
The type of the operand expression of the unary ! operator must be boolean or Boolean, or a compile-time error occurs. The type of the unary logical complement expression is boolean.
At run time, the operand is subject to unboxing conversion if necessary. This operator computes the logical negation of the operand: If the operand is true, the result is false. If the operand is false, the result is true.
Truth Table for NOT
| A | !A |
| F | T |
| T | F |
Truth Table for AND
| A | B | A && B |
| F | F | F |
| F | T | F |
| T | F | F |
| T | T | T |
Truth Table for OR
| A | B | A || B |
| F | F | F |
| F | T | T |
| T | F | T |
| T | T | T |
Truth Table for EXCLUSIVE OR
| A | B | A ^ B |
| F | F | F |
| F | T | T |
| T | F | T |
| T | T | F |