What is Variables?
Variables are containers for storing data values.
- String - stores text, such as "Hello". String values are surrounded by double quotes
- int - stores integers (whole numbers), without decimals, such as 123 or -123
- float - stores floating point numbers, with decimals, such as 19.99 or -19.99
- char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
- boolean - stores values with two states: true or false
What is Datatypes ?
As explained in the previous chapter, a variable in Java must be a specified data type:
Data Type Description
byte Stores whole numbers from -128 to 127
int Stores whole numbers from -2,147,483,648 to 2,147,483,647
long Stores whole numbers from -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
float Stores fractional numbers. Sufficient for storing 6 to 7
decimal digits
double Stores fractional numbers. Sufficient for storing 15 to 16
decimal digits
boolean Stores true or false values
char Stores a single character/letter or ASCII values
Top comments (0)