Boolean Data Type In Java

Boolean Data Type ?

Boolean type is used to when we want to test a particular condition during the execution of the program. Boolean can stroe only True or False value. The "boolean" data type is used to represent boolean values that returns either "true" or "false". Where in, value '1' returns true and value '0' returns false.

Boolean data type :

Boolean variables are variables that can have only two possible values: true, and false.

To declare a Boolean variable, we use the keyword bool.

         bool b;

To initialize or assign a true or false value to a Boolean variable, we use the keywords true and false.

         bool b1 { true };
       bool b2 { false };
       b1 = false;

Boolean values are not actually stored in Boolean variables as the words “true” or “false”. Instead, they are stored as integers: true becomes the integer 1, and false becomes the integer 0.

Example 1:

Output :


Example 2:

Output :

b1 is false
b1 is true
This is executed.
100 > 90 is true