boolean Keyword Java

boolean Keyword Java

boolean keyword is a primitive data type. It is used to store only two possible values, either true or false.

It is default value is false.It is generally associated with conditional statements.

Example 1: boolean keyword

public class BooleanExample1 {  
  
    public static void main(String[] args) {  
      
        int number1=20;  
        int number2=30;  
          
        boolean bool1=true;  
        boolean bool2=false;  
  
    if(num1<num2)  
    {  
        System.out.println(bool1);  
    }  
    else  
    {  
        System.out.println(bool2);  
    }  
          
 }         
}  

Output

true

Example 1: boolean keyword

public class BooleanKeywordExample {  
  
    public static void main(String[] args) {  
      
    boolean bool1=true;  
    boolean bool2=false;  
    boolean bool3=(bool1==bool2);  
      
    System.out.println(bool1);  
    System.out.println(bool2);  
    System.out.println(bool3);  
          
    }         
}  

Output

true
false
false

What is keyword in java?

Keyword is any one of 51 reserved words that have a predefined meaning in the language; because of this, programmers cannot use keywords as names for variables, methods, classes, or as any other identifier.

Operators Java
Data Types Java
Variable Java
Second Short Program Java
Install and Setup Path Java
Hello World Java