Boolean Data Type
A boolean
can store one of two values, either true
or false
.
- Occupies
1
bytes. - The default value is
false
. - There is no min or max for
boolean
data type.
public class BooleanType {
public static void main(String[] args) {
boolean a = true; // true
boolean b = false; // false
boolean notA = !a; // false (opposite of boolean `a` value)
boolean notB = !b; // true (opposite of boolean `b` value)
boolean aAndB = a && b; // false (are both `a`, `b` true?)
boolean aOrB = a || b; // true (either `a` or `b` true?)
boolean aXorB =a ^ b; // true (either of them should be true)
}
}
!
, &&
, ||
, and ^
are operators. The next chapter covers operators in detail.