Tsallaka zuwa abun ciki
Justice Tech School

Variables

A variable has a type, a name and a value: int count = 5;. Use final for a constant that cannot change. Since Java 10 you can write var and let the compiler infer the type. Names use camelCase.

Example
int age = 21;
double price = 19.99;
char grade = 'A';
boolean active = true;
String name = "Ada";
final int MAX = 100;
var city = "Lagos";
System.out.println(name + " " + age + " " + grade + " " + price + " " + active + " " + MAX + " " + city);

Result

Ada 21 A 19.99 true 100 Lagos

Exercise

Declare a whole number.

 count = 5;

Quiz Test

Which keyword makes a variable constant?

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