3.2 The Type boolean

He who would distinguish the true from the false must have an adequate idea of what is true and false.

—BENEDICT SPINOZA, Ethics

Truth is truth

To the end of reckoning.

—WILLIAM SHAKESPEARE, Measure for Measure

The type boolean is a primitive type, just like the types int, double, and char. As with these other types, you can have values of type boolean, constants of type boolean, variables of type boolean, and expressions of type boolean. However, the type boolean specifies only two values: true and false. You can use the two values true and false in a program, just as you use numeric constants, such as 2 and 3.45, and character constants, such as ‘A’.

Boolean Variables

Boolean variables can be used, among other things, ...

Get Java: An Introduction to Problem Solving and Programming, 8th 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.