Menu
Coddy logo textTech

Boolean

Part of the Fundamentals section of Coddy's Java journey — lesson 7 of 73.

A boolean type has only 2 possible values: true or false.

To assign a boolean value to a variable, use the keyword boolean followed by the variable name:

boolean variable_true = true;
boolean variable_false = false;

In the above example, two boolean variables named variable_true and variable_false are initialized with the values true and false, respectively.

Booleans are the building blocks for creating logic in the programs we write. We have a whole chapter about logic and conditions.

challenge icon

Challenge

Beginner

Declare a variable named isLoggedIn and assign it the value true.

Cheat sheet

A boolean type has only 2 possible values: true or false.

To declare a boolean variable, use the keyword boolean followed by the variable name:

boolean variable_true = true;
boolean variable_false = false;

Try it yourself

public class Main {
    public static void main(String[] args) {
        // Type your code below
        boolean isLoggedIn = ?
        
        // Don't change the line below
        System.out.println("isLoggedIn = " + isLoggedIn);
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals