java data type:
In Java, data types are divided into two types: basic data types (value types) and wrapper types (reference data types). The basic data type is not an object, and methods such as toString(), hashCode(), getClass(), equals() cannot be called.
8 basic data types-----8 packaging types
Integer:
byte Byte [-128, 127] 1 byte ([-2 to the 7th power, 2 to the 7th power -1]) One byte has 8-bit short Short [-32768, 32767] 2 bytes ([-2 to the 15th power, 2 to the 15th power -1]) 2*8-1 int Integer [-2147483648, 2147483647] 4 bytes ([-2 to the 31th power, 2 to the 31th power]) 4*8-1 long Long [-9223372036854774808, 9223372036854774807] 8 bytes ([-2 to the 63th power, 2 to the 63th power]) 8*8-1
You can see that the value range of byte and short is relatively small, while the value range of long is too large and takes up a lot of space. Basically, int can meet our daily calculations, and int is also the most used integer type.
Under normal circumstances, if an integer number such as 35 appears in JAVA, then this number is int type. If we want it to be byte type, we can add capital B:35B after the data, which means it is byte type. The same 35S represents short type, and 35L represents long type, which means int we can add nothing, but if we want to represent long type, we must add "L" after the data.
Floating point type:
float Float 4 bytes
double Double 8 bytes
The difference is their accuracy
The double type has a larger storage range and higher accuracy than the float type, so the usual floating-point data are double without declaration. If you want to indicate that a data is float type, you can add "F" after the data.
Floating point data cannot be completely accurate, so sometimes it may float at the last few decimal places during calculations, which is normal.
Character type:
char Character 2 bytes
The data type used to store characters, occupy 2 bytes, is unicode encoding, its first 128 byte encoding is compatible with ASCII
The storage range of characters is /u0000~/uFFFF. When defining character-type data, please pay attention to adding '', for example, '1' means character '1' instead of the value 1.
Boolean type:
boolean boolean
There are only two values, true and false
Thank you for reading, I hope it can help you. Thank you for your support for this site!