boolean Data Type

A boolean type can have one of two values: true or false. A boolean is used to perform logical operations, most commonly to determine whether some condition is true. For example:

boolean enrolled = true;

boolean credited = false;

Here, a variable named enrolled of type boolean is declared and initialized to a value of true, and another boolean named credited is declared and initialized to false.

Warning.eps In some languages, such as C or C++, integer values can be treated as a boolean, with 0 equal to false and any other value equal to true. Not so in Java. In Java, you can’t convert between an integer type and a boolean type.

Get Java For Dummies Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.