Variable (Java)
A variable in Java is a named container that stores a value. Because Java is statically typed, you must declare a variable's type when you create it, and it can only hold values of that type.
Java
You declare a variable by writing its type, then its name, then optionally an initial value: int age = 25;. Once a variable has a type, that type cannot change.
Variable names use lowerCamelCase by convention, such as totalScore or userName.
Examples
Java
int age = 25;
String name = "Maya";
age = age + 1;
System.out.println(name + " " + age);Output:
Maya 26