Variables store data. Choose appropriate names and types (int, double, String, etc.).

int age = 25;
double height = 5.9;
String name = "Alice";

Data Types

Different data types store different kinds of values. For example:

Data TypeDescriptionExample
intInteger (whole number)int age = 25;
doubleDouble-precision floating-point numberdouble pi = 3.14159;
charSingle characterchar grade = 'A';
booleanRepresents true or falseboolean isPassed = true;
StringSequence of charactersString name = "John";
byteByte-sized integerbyte num = 127;
shortShort integershort num = 32000;
longLong integerlong population = 78563412;
floatSingle-precision floating-point numberfloat temperature = 98.6f;
charSingle characterchar grade = 'A';