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 - Java Tutorial
From the course: Java 8+ Essential Training: Syntax and Structure
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Work with primitive variables6m 35s
-
Declare and modify primitive values4m 48s
-
(Locked)
Store currency values with BigDecimal3m 32s
-
(Locked)
Convert values between numeric types3m 19s
-
(Locked)
Math operators and the Math class3m 11s
-
(Locked)
Work with boolean values2m 51s
-
(Locked)
Work with character values4m 12s
-
(Locked)
More about Java operators4m 48s
-
(Locked)
-
-
-