Java is a strongly typed language, which means that every variable must declare a type.
Before we talk about variables, we must first talk about the types of variables.
In Java, variable types are divided into two categories: basic types and reference types.
Variable type | |
---|---|
basic type | Reference type |
8 types | Except for the 8 basic types, all other variable types are reference types |
Java supports the basic variable types in 8.
type name | size of space (Unit: byte or bytes) |
Representation range |
---|---|---|
byte (byte type) | 1 | |
short (short integer) | 2 | |
int (integer) | 4 | |
long (long integer) | 8 | |
float (single precision floating point type) | 4 | about (The effective number of digits is 6~7) |
double (double-precision floating-point type) | 8 | about (The effective number of digits is 15) |
char (character type) | 2 | |
boolean (Boolean) | true,false |
Among them, byte, short, int, long are the basic types that represent integers;
Float, double are the basic types that represent real numbers with decimals;
Char is the type that represents a character. Characters in Java are encoded in Unicode and are two bytes (2 bytes, 16 bits) long;
boolean is a type that indicates that the truth value is correct or incorrect.
tips: These 8 types can be selected reasonably according to the form of the data in the program.