Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the third boolean state in java?

While I know that by definition a boolean consists of only two states, true or false. I was wondering what value does a boolean have before it is initialized with one of these states.

like image 757
Bobby Avatar asked Jun 04 '09 18:06

Bobby


People also ask

What is boolean types in Java?

A Boolean expression is a Java expression that returns a Boolean value: true or false .

What is a boolean statement in Java?

In Java, the boolean keyword is a primitive data type. It is used to store only two possible values, either true or false. It specifies 1-bit of information and its "size" can't be defined precisely. The boolean keyword is used with variables and methods. Its default value is false.

How do you declare a boolean in Java?

To display Boolean type, firstly take two variables and declare them as boolean. val1 = true; Now, use if statement to check and display the Boolean true value. if(val1) System.

Is bool true 1 or 0?

C does not have boolean data types, and normally uses integers for boolean testing. Zero is used to represent false, and One is used to represent true. For interpretation, Zero is interpreted as false and anything non-zero is interpreted as true.


2 Answers

It defaults to false.

Edit: By popular demand:

unless you're using the wrapped Boolean, which defaults to null. – sudhir.j

like image 157
Adam Paynter Avatar answered Sep 23 '22 08:09

Adam Paynter


If it is a local variable, it is a compiler error to reference it before it was initialized. If it is a field, it is initialized to false.

like image 24
Yishai Avatar answered Sep 25 '22 08:09

Yishai