Boolean in java

 Boolean is a primitive data type, means it can only store a single value.

Boolean data type can store true or false at a given time. 

Example bellow shows how you can store and retrieve Boolean  data type.

boolean isNight = true;

boolean isMonday = false;

The above sample code will store true and false respectfully. We usually use Boolean to evaluate conditions and make decision.

Example code bellow try's to express the usage.

class TrueFalse {

     public static void main(String[] args){

        int value1 = 1;

        int value2 = 2;

        if(value1 == value2)

            System.out.println("value1 == value2");

        if(value1 != value2)

            System.out.println("value1 != value2");

        if(value1 > value2)

            System.out.println("value1 > value2");

        if(value1 < value2)

            System.out.println("value1 < value2");

        if(value1 <= value2)

            System.out.println("value1 <= value2");

    }

}

The first condition result to false value1 is not equal to value2.

Previous Post Next Post

Welcome, New Friend!

We're excited to have you here for the first time!

Enjoy your colorful journey with us!

Welcome Back!

Great to see you Again

If you like the content share to help someone

Thanks

Contact Form