SCJP Study Guide:
Fundamentals


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend


Previous Next vertical dots separating previous/next from contents/index/pdf Contents
XyzWs SCJP Study Guide: Boolean or Logical Operators

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 && B is evaluated as A ? 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 || B is evaluated as A ? 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

Previous Next vertical dots separating previous/next from contents/index/pdf Contents

  |   |