Lesson 3 of 518 minModule progress 0%

Module 2: Output, Input, Variables, and Types

Primitive Data Types: `int`, `double`, `boolean`, and `char`

Work with the most common primitive types before you worry about the full list of Java primitives.

Author

Java Learner Editorial Team

Reviewer

Technical review by Java Learner

Last reviewed

2026-04-16

Java version

Java 25 LTS

How this lesson was prepared: AI-assisted draft, edited by hand, and checked against current Java 25 documentation and runnable examples.

Learning goals

  • Choose the right basic type for common beginner examples
  • Recognize when to use `int`, `double`, `boolean`, and `char`
  • Read primitive variable declarations comfortably

int: Use int for whole numbers such as ages, counts, and menu choices.

double: Use double for decimal numbers such as prices or averages.

boolean: Use boolean when the answer is only true or false.

char: Use char for a single character such as A or y. Use single quotes for a char, not double quotes.

Runnable examples

Four common primitive types

public class Main {
    public static void main(String[] args) {
        int score = 95;
        double price = 12.5;
        boolean loggedIn = true;
        char grade = 'A';

        System.out.println(score);
        System.out.println(price);
        System.out.println(loggedIn);
        System.out.println(grade);
    }
}

Expected output

95
12.5
true
A

Booleans help later with conditions

public class Main {
    public static void main(String[] args) {
        boolean isAdult = true;
        System.out.println("Adult status: " + isAdult);
    }
}

Expected output

Adult status: true

Common mistakes

Using double quotes for a `char`

Use single quotes like `'A'` for a single character.

Using `double` when a whole-number count is enough

Use `int` for counts and `double` for decimal values.

Mini exercise

Create one variable of each type shown in this lesson and print them.

Summary

  • `int` is for whole numbers.
  • `double` is for decimals.
  • `boolean` stores true/false.
  • `char` stores one character.

Next step

After storing fixed values, let the user type something into the program.

Sources used

Advertisement

Lesson check

Which type is the best fit for storing `19.99`?

Next lesson →