From the course: Java 8+ Essential Training: Syntax and Structure

Unlock the full course today

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

Work with boolean values

Work with boolean values - Java Tutorial

From the course: Java 8+ Essential Training: Syntax and Structure

Start my 1-month free trial

Work with boolean values

- [Instructor] A variable of the boolean data type can have a value of either true or false. In some languages, the values of true and false also could be represented as numeric values, but not in Java. In Java, true and false are the only possible boolean values. To declare a boolean variable, start off with the type boolean, then set the variable name, and then you can assign an initial value. So in this case, b1 is true. I'll declare another boolean value that I'll call b2, and I'll set it to false. True and false are key words. If you misspell them, you'll get an error. Now, if you declare a boolean variable, but you don't assign an initial value, the default will be false. I'll declare a boolean b3. I won't assign a value, and that shows the result. If you want to reverse a boolean value, use an exclamation mark, sometimes referred to by Java developers as the bang operator. So I'll say boolean reversed equals exclamation, or bang, b3. And reversed is now true. If you want to…

Contents