O'Reilly logo

Java Garage by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Logical Representations

The boolean is the only logical primitive type in Java, meaning it is capable of helping you perform logical operations.

boolean

The only type used to represent true and false values in Java is boolean. The word is written out completely, not shortened to bool as in C++, C#, and other languages.

Possible values are true or false.

Default value is false.

Note that in Java, the boolean values are literals: you may not substitute a 0 for false or a 1 for true as in other languages. If you are in the habit of using 0 and 1 in this way, break it quick. As a side note, if you are in the habit of returning -1 from a method to indicate a non-standard state, break that habit too. Java has a robust exception handling facility for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required