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 ...

Get Java Garage 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.