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,8079,223,372,036,854,775,8079,223,372,036,854,775,807
Enter fullscreen mode Exit fullscreen mode
float Stores fractional numbers. Sufficient for storing 6 to 7
decimal digitsdecimal digitsdecimal digits
Enter fullscreen mode Exit fullscreen mode
double Stores fractional numbers. Sufficient for storing 15 to 16
decimal digitsdecimal digitsdecimal digits
Enter fullscreen mode Exit fullscreen mode
boolean Stores true or false values
char Stores a single character/letter or ASCII values
暂无评论内容