From the course: Java 8 Essential Training

Unlock the full course today

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

Working with Boolean values and expressions

Working with Boolean values and expressions - Java Tutorial

From the course: Java 8 Essential Training

Start my 1-month free trial

Working with Boolean values and expressions

- A variable marked with the boolean data type can have a value of either true or false. I'll demonstrate this in the booleans project. Within the main method, I'll declare two variables, and I'll start with the keyword boolean, all lower case. That means this is a primitive variable, not an object. I'll name the variable b1, and I'll assign it a value of true. Then, I'll create another boolean variable, and I'll say that one is false. Now, I'm going to shrink down my project window to eliminate some flickering that's happening, then I'll add some output to the console. I'll start with a string of "The value of b1 is" and then I'll append the value b1. I'll duplicate that line of code, and change both the label and the value, and then I'll run the class. And I get the expected output. The values of the primitive variables, b1 and b2, have been translated to equivalent strengths. So, true gets a string of true, and false gets a string of false. All primitive variables, as I've…

Contents