Java Variables
A variable stores a value. In Java you must say what type of value it holds. The common types are int (whole numbers), double (decimals), boolean (true or false), char (one character) and String (text).
ExampleJava
public class Main {
public static void main(String[] args) {
String name = "Ada";
int age = 36;
double height = 1.68;
boolean student = false;
System.out.println(name + " is " + age + " years old.");
System.out.println("Height: " + height + ", student: " + student);
age = 37; // change the value
final int YEAR = 2026; // final: cannot be changed
System.out.println("Next year: " + age + " in " + YEAR);
}
}Output
Ada is 36 years old. Height: 1.68, student: false Next year: 37 in 2026
final makes a variable a constant. You can also let Java work out the type with var: var count = 10; is an int.
Quick check
Which type stores whole numbers?
Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.
Tip: use the left and right arrow keys to move between lessons.