Java Boolean Example Program

Chapter: Data Types Last Updated: 28-03-2017 17:30:02 UTC

Program:

            /* ............... START ............... */
                
public class JavaBooleanExample {
	public static void main(String args[]) {
		boolean b;
		b = false;
		System.out.println("b is " + b);
		b = true;
		System.out.println("b is " + b);
		// a boolean value can control the if statement
		if (b)
			System.out.println("This is executed.");
		b = false;

		if (b)
			System.out.println("This is not executed.");
		// outcome of a relational operator is a boolean value
		System.out.println("10 > 9 is " + (10 > 9));
	}
}
                /* ............... END ............... */
        

Output

b is false
b is true
This is executed.
10 > 9 is true

Notes:

  • A Boolean type has two values true or false, yes or no, 1 or 0.
  • eg : boolean value = true;
  • The Boolean class wraps a value of the primitive type boolean in an object.
  • Default value of a boolean is false.
  • Boolean is the type required by the conditional expressions used in control statements such as if and for.

Tags

Java, Boolean

Similar Programs Chapter Last Updated
Java String Example Program Data Types 19-06-2016
Primitive Datatypes In Java Example Data Types 17-06-2016
Enum In Java Example Data Types 28-04-2016
Java Short Example Program Data Types 10-06-2016
Java Long Example Program Data Types 15-07-2016
Java Int Example Program Data Types 06-07-2016
Int Array In Java Example Program Data Types 09-06-2016
Java Float Program Example Data Types 28-03-2017
Java Double Example Program Data Types 28-03-2017
Java Char Example Program Data Types 28-03-2017
Java Byte Example Program Data Types 28-03-2017

1