Variables store data. Choose appropriate names and types (int, double, String, etc.).
int age = 25;
double height = 5.9;
String name = "Alice";
Different data types store different kinds of values. For example:
int
for integersdouble
for floating-point numbersboolean
for true/false valuesString
for text
Data Type | Description | Example |
---|---|---|
int | Integer (whole number) | int age = 25; |
double | Double-precision floating-point number | double pi = 3.14159; |
char | Single character | char grade = 'A'; |
boolean | Represents true or false | boolean isPassed = true; |
String | Sequence of characters | String name = "John"; |
byte | Byte-sized integer | byte num = 127; |
short | Short integer | short num = 32000; |
long | Long integer | long population = 78563412; |
float | Single-precision floating-point number | float temperature = 98.6f; |
char | Single character | char grade = 'A'; |