411 REFERENCE · Wikibooks
Java Programming/Keywords/boolean
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
is a keyword which designates the primitive type. There are only two possible values: and . The default value for fields is .
The following is a declaration of a field named initialized, and its use in a method named synchronizeConnection.
Code section 1: Connection synchronization.
private boolean initialized = false;
public void synchronizeConnection() {
if (!initialized) {
connection = connect();
initialized = true;
}
}
The previous code only creates a connection once (at the first method call). Note that there is no automatic conversion between integer types (such as ) to as is possible in some languages like C. Instead, one must use an equivalent expression such as (i != 0) which evaluates to if i is not zero.
deep