Boolean is a primitive data type, means it can only store a single value.
Boolean data type can store true or false at a given time.
Example bellow shows how you can store and retrieve Boolean data type.
boolean isNight = true;
boolean isMonday = false;
The above sample code will store true and false respectfully. We usually use Boolean to evaluate conditions and make decision.
Example code bellow try's to express the usage.
class TrueFalse {
public static void main(String[] args){
int value1 = 1;
int value2 = 2;
if(value1 == value2)
System.out.println("value1 == value2");
if(value1 != value2)
System.out.println("value1 != value2");
if(value1 > value2)
System.out.println("value1 > value2");
if(value1 < value2)
System.out.println("value1 < value2");
if(value1 <= value2)
System.out.println("value1 <= value2");
}
}
The first condition result to false value1 is not equal to value2.