Boolean Literals in java

Java Programming Language Variables in java (Article) Variables in java (Program)

1830

This is a Java program that demonstrates the use of boolean literals. In Java, a boolean literal can only take two values: true or false.

The program declares two boolean variables named boolFalse and boolTrue, and assigns them the values false and true, respectively.

The program then prints the values of these variables to the console using the System.out.println method. When run, the program will output the values of boolFalse and boolTrue, which are false and true, respectively.

Program:

 //Java literals are fixed or constant values in a program's source code.

public class BooleanLiteral {

  public static void main(String[] a) {

    boolean boolFalse = false;
    boolean boolTrue = true;
    System.out.println(boolFalse);
    System.out.println(boolTrue);

  }
}


/*
Boolean literals have only two possible values those are true and false.
*/

Output:

false
true
Press any key to continue . . .

Explanation:

In summary, this program demonstrates how to use boolean literals to assign values to boolean variables in Java, and also shows how to print their values to the console.


This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.