boolean (Java)

boolean is the Java primitive type that holds one of two values: true or false. Booleans come from comparisons and conditions and control if-statements and loops.

Java

Unlike some languages, Java is strict: a condition must evaluate to a true boolean — you cannot use a number or a String where a boolean is expected. The values true and false are written in lowercase.

Comparison operators (>, <, ==, !=) and logical operators (&&, ||, !) all produce booleans.

Examples

Java

boolean isOpen = true;
System.out.println(5 > 3);
System.out.println(isOpen && false);

Output:

true
false

Learn it in a lesson

See also

Back to the Dictionary