Summary of java basic interview questions (3): What are the basic data types in Java? What are their sizes?

In Java, the basic data types are as follows:
1Integer type:

byte:1字节,在内存中范围为-128到127
short:2字节,在内存中范围为-32768到32767
int:4字节,在内存中范围为约-21亿到21亿
long:8字节,在内存中范围为约-922亿亿到922亿亿


2Floating point number types:

float:4字节,在内存中约范围为±3.40282347E+38F(有效位数为6-7位)
double:8字节,在内存中约范围为±1.79769313486231570E+308(有效位数为15位)


3 character types:

char:2字节,在内存中范围为0到65535,表示一个Unicode字符


4 Boolean types:

boolean:1位,在内存中只能表示true或false


The above sizes are the standard sizes defined in the Java Language Specification and represent the number of bytes they occupy in memory. Note that there may be slight differences between compilers and platforms, but generally these standard sizes apply.

Guess you like

Origin blog.csdn.net/xiao___zhu/article/details/134745984