Skip to content
Justice Tech School

Variables and Constants

Declare a variable with its type. final makes a constant that cannot change. Names use camelCase.

Example
public class Main {
  public static void main(String[] args) {
    int age = 30;
    final double PI = 3.14159;
    String name = "Ada";
    System.out.println(name + " " + age + " " + PI);
  }
}

Result

Ada 30 3.14159

Exercise

Make a constant.

 int MAX = 10;

Quiz Test

What does final do on a variable?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.