---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 12 Edition"
java_version: 12
chapter: "Chapter 4. Types, Values, and Variables"
section: "4.2.5"
heading: "4.2.5. The boolean Type and boolean Values"
parent: "4.2. Primitive Types and Values"
source: https://docs.oracle.com/javase/specs/jls/se12/html/jls-4.html#jls-4.2.5
id: "4.2.5"
url: https://jvm.obfuscated.software/jls/se12/4.2.5.html
raw: https://jvm.obfuscated.software/jls/se12/4.2.5.md
---

# 4.2.5. The `boolean` Type and boolean Values

The `boolean` type represents a logical quantity with two possible values, indicated by the literals `true` and `false` ([§3.10.3](3.10.3.md)).

The boolean operators are:

- The relational operators `==` and `!=` ([§15.21.2](15.21.2.md))
- The logical complement operator `!` ([§15.15.6](15.15.6.md))
- The logical operators `&`, `^`, and `|` ([§15.22.2](15.22.2.md))
- The conditional-and and conditional-or operators `&&` ([§15.23](15.23.md)) and `||` ([§15.24](15.24.md))
- The conditional operator `? :` ([§15.25](15.25.md))
- The string concatenation operator `+` ([§15.18.1](15.18.1.md)), 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

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

- The `if` statement ([§14.9](14.9.md))
- The `while` statement ([§14.12](14.12.md))
- The `do` statement ([§14.13](14.13.md))
- The `for` statement ([§14.14](14.14.md))

A `boolean` expression also determines which subexpression is evaluated in the conditional `? :` operator ([§15.25](15.25.md)).

Only `boolean` and `Boolean` expressions can be used in control flow statements and as the first operand of the conditional operator `? :`.

An integer or floating-point expression `x` can be converted to a `boolean` value, 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` value, following the C language convention that any reference other than `null` is `true`, by the expression `obj!=null`.

A `boolean` value can be converted to a `String` by string conversion ([§5.4](5.4.md)).

A `boolean` value may be cast to type `boolean`, `Boolean`, or `Object` ([§5.5](5.5.md)). No other casts on type `boolean` are allowed.
