Home » Java Boolean Keyword

Java Boolean Keyword

by Online Tutorials Library

Java boolean Keyword

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

Test it Now

Output:

true  

Example 2: Comparing the variables of boolean type

Test it Now

Output:

true  false  false  

Example 3: Method of boolean type

Test it Now

Output:

true  

Example 4: Comparing objects

Test it Now

Output:

Is objects are equal : false  

Example 5: Finding a prime number

Test it Now

Output:

prime  
Next TopicJava Byte Keyword

You may also like