Understanding Boolean Type in Java with examples

Java has 8 Primitive types, including Boolean type. Possible values are TRUE and FALSE. Default is FALSE. Use this to track TRUE/ FALSE record.

Following are some examples to work with Boolean Type in Java:

Example 1

public class Main {

  public static void main(String[] args) {
   
    boolean p;
    
    p = false;
   
    if(p) 
      System.out.println("FALSE");
      
    else 
      System.out.println("TRUE");
     }
}

Output

TRUE

Example 2

public class Main {

  public static void main(String[] args) {
   
    boolean p;
    
    p = true;
   
    if(p) 
      System.out.println("TRUE");
      
    else 
      System.out.println("FALSE");
     }
}

Output

TRUE

Example 3

public class Main {

    static boolean a;

    public static void main(String[] args) {    

       System.out.println("Default value of boolean Type = " + a);
  }
}

Output

Default value of boolean Type = false
When Overflow of DataTypes occur in Java
Java Program to parse string to a Boolean object
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment