Java boolean default value

In this tutorial we will see what is java boolean default value . In this example we will write a java program that creates unassigned boolean variable / Boolean variable and check default value of boolean in java .

Note : The Default value of boolean is false and wrapper class Boolean is null.

Java Program To Find Java boolean default value

Now we will write a program to check default boolean value in java.

public class DefaultBooleanValue {

	boolean defaultBoolean;
	Boolean defaultBooleanWrapper;

	public static void main(String[] args) {
		DefaultBooleanValue defaultBooleanValue = new DefaultBooleanValue();
		defaultBooleanValue.printBooleanDefaultValues();
	}

	public void printBooleanDefaultValues() {
		//print value of boolean
		System.out.println("Default value of boolean: " + defaultBoolean);
		//print value of Boolean
		System.out.println("Default value of Boolean(Wrapper): "
				+ defaultBooleanWrapper);
	}

}

Output :

Default value of boolean: false
Default value of Boolean(Wrapper): null

The output of this example makes clear that The Default value of boolean is false and wrapper class Boolean is null .

Lets be sure about it. We will now create few more boolean and Boolean variables and we will print java boolean default value and see the output.

public class DefaultBooleanValue2 {
	boolean defaultBoolean1;
	Boolean defaultBooleanWrapper1;
	boolean defaultBoolean2;
	Boolean defaultBooleanWrapper2;

	public static void main(String[] args) {
		DefaultBooleanValue2 jbd = new DefaultBooleanValue2();
		jbd.printBooleanDefaultValues();
	}

	public void printBooleanDefaultValues() {
		//print value of boolean
		System.out.println("Default value of boolean: " + defaultBoolean1);
		System.out.println("Default value of boolean: " + defaultBoolean2);
		
		//print value of Boolean
		System.out.println("Default value of Boolean(Wrapper): "
				+ defaultBooleanWrapper1);
		System.out.println("Default value of Boolean(Wrapper): "
				+ defaultBooleanWrapper2);
	}

}

Output :

Default value of boolean: false
Default value of boolean: false
Default value of Boolean(Wrapper): null
Default value of Boolean(Wrapper): null

Now it is sure that The Default value of boolean is false and wrapper class Boolean is null .

In this tutorial we learned about default value of boolean in java . We have written two program to check default boolean value java . You can learn more interesting java program for practice .

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 34 = 36