The boolean Primitive

The simplest data type available to you in Java is the primitive type boolean. A boolean variable has only two possible values, true or false, which are represented with reserved words. In some other languages, Boolean types take on values of 0 or 1; or, as in C/C++, 0 represents false and all other numbers are interpreted as true. Java treats boolean in a strict and type-safe manner by tightly restricting its allowed values. A boolean can never be treated as an integer or vice versa.

boolean variables are often used when you want to keep track of the state of a simple object attribute. For instance, if you are writing a flight scheduling application, whether a given flight is on time is important to you. You might declare ...

Get Special Edition Using Java 2 Standard Edition 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.