Java Tutorial-Java Booleans

Java Booleans


Java has a boolean data type which can take the values true or false.

 

Boolean Values


A Boolean type is declared with the boolean keyword.


Example

boolean isTrue = true;
boolean isFalse = false;
             
System.out.println(isTrue);
System.out.println(isFalse);

Output

true
false

Boolean Expression


A Boolean expression in Java returns Boolean values (true or false). The comparison operator always return Boolean values.


Example

System.out.println(5>9);

Output

false