Skip to content
Veltoryx Technologies
ProLesson 2.1Beginner3 min readUpdated 30 October 2026

Variables and primitive types

Store values in variables, meet Java's eight primitive types, and learn when to use int, long, double, boolean and char.

A variable is a named box that holds a value. In Java every box has a type, which decides what can go inside and how much memory it uses.

01Declaring a variable

Variables.java
public class Variables {
    public static void main(String[] args) {
        int age = 25;              // type, name, value
        double price = 499.99;
        boolean isMember = true;
        char grade = 'A';

        age = age + 1;             // change the value later
        System.out.println(age);
        System.out.println(price);
        System.out.println(isMember);
        System.out.println(grade);
    }
}
Expected output
26
499.99
true
A

The pattern is always type name = value;. Once a variable has a type, it keeps it: you can't put text into an int.

Loading the rest of the lesson…