BEST SITE FOR WEB DEVELOPERS
Java programming language. Lessons for beginners

Ua

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:

Example

boolean isJavaFun = true;
boolean isFishTasty = false;
System.out.println(isJavaFun);     // Outputs true
System.out.println(isFishTasty);   // Outputs false
Try it Yourself »

Boolean values are mostly used for conditional testing.

You will learn much more about booleans and conditions later in this tutorial.