Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




Java - Boolean


Boolean represents just two values, i.e. True or False.


Boolean Data Type


A bool Data Type can accept only true or false.


Example :



public class MyApplication
{
    public static void main(String[] args)
    {
     	boolean x = true;
        boolean y = false;
        System.out.println(x);
        System.out.println(y);
    }
}


Output :



  true
  false

So, in the above code, we have created a variable named x of Boolean data type and initialised it with value True.


boolean x = true;
Spring_Boot


And created one more variable called y of Boolean data type and initialised it with value False.


boolean y = false;
Spring_Boot


But if we want to initialise a Boolean type variable with anything other than true/false, it would end up with an error.