Due to the limitations of mobile device memory in mobile development, it is often necessary to consider the number of bytes consumed by the data type used. Below is a brief introduction to some basic data types in Java to deepen your memory.
There are 8 basic data types in Java, including 4 integers, 2 floating-point types, 1 character types used to represent Unicode-encoded character cells, and 1 Boolean types that represent truth values. (one byte equals 8 bit)
1. Integral type
Type storage requirement bit number value range remark
int 4 byte 4*8
Short 2 byte 2*8-32768~32767
Long 8 byte 8*8
BYTE 1 byte 1*8-128~127
2. Floating-point type
Type storage requirement bit number value range remark
Float 4 byte 4*8 float type has a suffix f (for example: 3.14F)
Double 8 byte 8*8 floating-point value with no suffix f (for example, 3.14) defaults to double type
3.char type
Type storage Requirements
Char English byte, Chinese 2 bytes (not necessarily under other encodings)
4.boolean type
Type storage requirement bit number value range remark
Boolean 1 byte 1*8 false, True
Add: Java has a schoolbag that can represent any precision, often called a "big number". Although it is called a large value, it is not a Java type, but a Java object.
If the basic integer and floating-point precision are not sufficient, then two useful classes in the Java.math package can be used: Bigintegerbigdecimal (also included in the Android SDK Java.math package and these two classes) These two classes can handle numeric values that contain a sequence of arbitrary lengths. The BigInteger class realizes the integer operation of arbitrary precision, and BigDecimal realizes the floating-point number operation with arbitrary precision. Specific usage can be found in the Java API.
Basic types in Java consume bytes