Java Boolean Data Types
Boolean Types
Very often in programming, you will need a data type that can only have one of two values, like:
- YES / NO
- ON / OFF
- TRUE / FALSE
For this, Java has a boolean
data type, which can only take the values true
or false
:
ExampleGet your own Java Server
boolean isJavaFun = true;
boolean isFishTasty = false;
System.out.println(isJavaFun); // Outputs true
System.out.println(isFishTasty); // Outputs false
Boolean values are mostly used for conditional testing.
You will learn much more about booleans and conditions later in this tutorial.
Exercise?What is this?
Test your skills by answering a few questions about the topics of this page
What is the correct syntax for declaring a boolean variable in Java?