Java boolean Keyword

Last Updated : 18 Feb 2026

In Java, the boolean keyword is a primitive data type. It is used to store only two possible values, either true or false. It specifies 1-bit of information and its "size" can't be defined precisely.

The boolean keyword is used with variables and methods. Its default value is false. It is generally associated with conditional statements.

Examples of Java boolean keyword

Example 1: Simple boolean example

Output:

Example 2: Comparing the variables of boolean type

Output:

Example 3: Method of boolean type

Output:

Example 4: Comparing objects

Output:

Is objects are equal : false

Example 5: Finding a prime number

Output: