It's common practice in computer programming to work with data types that accept only binary values, such as:
On/off
True/False
YES/NO
Java provides a boolean data type for this purpose, which can store either true or false.
A boolean type is declared with the boolean keyword and can only take the values true or false:
Boolean expressions are special Java expressions that always return one of two values, true or false. This is helpful for solving problems that require comparing values. To test if an expression (or a variable) evaluates to true, you can use a comparison operator like the greater than (>) operator, for instance.
In the examples below, we use the equal to (==) operator to evaluate an expression:
In a "real life example," we would need to determine if a person is of voting age. Using the >= comparison operator, we can determine if the given age (25) is higher than OR equal to the minimum voting age (in this case, 18):