Java Boolean operators : boolean Operators « Operators « SCJP






The AND Operation

Op1           Op2            Op1 AND Op2

0             0              0

0             1              0

1             0              0

1             1              1


The XOR Operation
Op1           Op2            Op1 XOR Op2

0             0              0

0             1              1

1             0              1

1             1              0


The OR Operation
Op1           Op2            Op1 OR Op2

0             0              0

0             1              1

1             0              1

1             1              1


The AND Operation on boolean Values
Op1           Op2            Op1 AND Op2

false         false          false

false         true           false

true          false          false

true          true           true



The XOR Operation on boolean Values
Op1           Op2            Op1 XOR Op2

false         false          false

false         true           true

true          false          true

true          true           false


The OR Operation on boolean Values
Op1             Op2          Op1 OR Op2

false           false        false

false           true         true

true            false        true

true            true         true

public class MainClass {
  public static void main(String[] argv) {
    System.out.println(true & true);
    System.out.println(true && true);
  }
}
true
true








2.8.boolean Operators
2.8.1.Java Boolean operators
2.8.2.Short-Circuit Logical Operators
2.8.3.Using the Boolean and Logical Short-Circuit Operators
2.8.4.Logical Operators (Not Short-Circuit)
2.8.5.Java does not permit you to cast any type to boolean
2.8.6.Involve calculation in the short-circuit logical operators