Boolean
It has a simple type, known as boolean, for logical values. Java can have only one of two possible values that are true or false. This is the category returned by all relational operations, like as a<b. A Boolean is also the type through the conditional expressions which given the control statements such as if and for.
// Demonstrate boolean values.
class booltest {
public static void main (string args [ ] ) {
boolean b;
b=false;
System.out.print1n("b is + b ) ;
b=true;
System.out.print1n ("b is" + b);
// a boolean value could control if statement
if (b) system.out.print1n("This is executed.");
b=false;
if (b) system.out.print1n("This is not executed.");
// outcome of a relational operator
System.out.print1n ("10>9 is" + (10>9));
}
}
The output produced through this program is display here:
B is false
B is true
This is executed.
10> 9 is true
There are only three interesting things to remember about this program. First, as you could see, when a Boolean value is output through print1n ( ), "true" or "false" is shown. Second, the value of a Boolean variable is sufficient, through itself, to control the if statement. There is no need of writing an if statement such as this:
If(b= =true) ....
Third, the outcome of a relational operator, like as <, is a boolean value. This is why expression 10>9 shows the value "true". In additional, the extra set of parentheses around 10>9 is necessary since the + operator has a higher precedence than the>.