Booleans in Java

The Java programming language supports Boolean values as a primitive data type named boolean. It also includes Boolean keywords true and false to represent each possible value. Notice that these keywords are not capitalized, unlike some other programming languages.

To declare a Boolean variable in Java, we can use the same basic syntax that we used for other variable types:

boolean b;

We can then assign a value of true or false to that variable:

boolean b;
b = true;

We can also combine the two statements into a single statement:

boolean b = false;