What are Boolean literals in Java?



Boolean literals represent only two values true or false. And in Java the value of 1 is assumed as true and the value of 0 is assumed as false.

Example

Live Demo

public class Test{
   public static void main(String args[]) throws Exception{
      boolean bool1 = true;
      boolean bool2 = false;
      boolean bool = (25==(100/4));

      System.out.println(bool1);
      System.out.println(bool2);
      System.out.println(bool);
   }
}

Output

true
false
true

Advertisements