Description
The boolean type represents a logical quantity
with two possible values, indicated by the literals true and false.
Boolean literals can be used to test a positive or negative state, or to declare the only
possible values for a boolean variable.
The boolean operators are:
- the relational operators == and !=
- the logical complement operator !
- the logical operators &, ^, and |
- the conditional-and and conditional-or operators && and ||
- the conditional operator ? :
- the string concatenation operator +
The string concatenation operator + converts the boolean operand to a String (either "true" or "false"), and then produce a newly created String that is the concatenation of the two strings.
Boolean expressions determine the control flow in several kinds of statements: if,
while, do, and for. A boolean expression also
determines which subexpression is evaluated in the conditional ? : operator.
A cast of a boolean value to type boolean is allowed; no other casts on type boolean
are allowed.
Examples
You can declare a boolean variable, and give it an initial value when you declare it:
boolean okToContinue = true;
You can use a boolean expression to determine control flow:
if (okToContinue && (a < b)) { ... }
Java types
do keyword
for keyword
if keyword
while keyword
Source: The Java Language Specification. Copyright (C) 1996 Sun Microsystems, Inc.