From the course: Java 11+ Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Manage true and false Boolean values

Manage true and false Boolean values - Java Tutorial

From the course: Java 11+ Essential Training

Start my 1-month free trial

Manage true and false Boolean values

- [Instructor] A variable with a primitive data type of Boolean can have a value of either true or false. In some languages, the values true or false can also be represented as numeric values, but in Java, that's not the case. The key words true and false are the only possible Boolean values. To create a Boolean variable explicitly, start with the type name Boolean, then set the variable name or identifier, and assign either true or false. You can also use inferred typing. I'll create a variable starting with var. I'll call this one B1 and I'll set it to true. And I'll create another one called B2 and set it to false. So those are also variables with a primitive data of Boolean. If you declare a Boolean value without setting its initial value, it'll default to false. So if I create Boolean B3, I see that it's false. You can reverse a Boolean value, set it from true to false or false to true using the negation operator,…

Contents