Boolean Values

The Boolean type represents a logical quantity with two possible values, indicated by the case insensitive literals true and false.

The Boolean operators are:

  • Boolean Equality Operators (== and != )

  • Logical Complement Operator (!)

  • Boolean Logical Operators (&, ^, and |)

  • Conditional-And Operator (&&) and Integer/Boolean Conditional-Or Operator (||), and Escalation Operator (|| )

  • Conditional Operator (? :)

  • Field access, using either a qualified name or a field access expression

  • Method invocation

  • The String Concatenation Operator (+) which, when given a String operand and a Boolean operand, will convert 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

These operations are the same as those in Java. For descriptions of the operations you can have on expressions, see: http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#44393.

Boolean expressions determine the control flow in several kinds of statements:

  • if Statement

  • while Statement

  • do Statement

  • for Statement

A Boolean expression also determines which subexpression is evaluated in the conditional ?: operator.

Only Boolean expressions can be used in control flow statements and as the first operand of the conditional operator ?:. An integer x can be converted to a Boolean, following the C language convention that any nonzero value is true, by the expression x!=0. An object reference obj can be converted to a Boolean, following the C language convention that any reference other than null is true, by the expression obj!=null.

A cast of a Boolean value to type Boolean is allowed; no other casts on type Boolean are allowed. A Boolean can be converted to a string by string conversion.