java基础类型的字节长度:
类型 | byte数/位数 | 最大/最小值 |
byte | 1/8 | 127/-128 |
short | 2/16 | 32767/-32768 |
int | 4/32 | 2147483647/-2147483648 |
long | 8/64 | 9223372036854775807/-9223372036854775808 |
float | 4/32 | 3.4028235E38/1.4E-45 |
double | 8/64 | 1.7976931348623157E308/4.9E-324 |
char | 2/16 | |
boolean | 1/8 | |
其中,float和double的最小值是能表示的最小精度值,不是最小负数值。
在java中查看byte长度和最大最小值的方式:
import org.junit.Test;
public class AnyTest {
@Test
public void test01() {
System.out.println("Byte: "+Byte.MAX_VALUE+"###"+Byte.MIN_VALUE+" byte_number: "+Byte.SIZE);
System.out.println("Short: "+Short.MAX_VALUE+"###"+Short.MIN_VALUE+" byte_number: "+Short.SIZE);
System.out.println("Integer: "+Integer.MAX_VALUE+"###"+Integer.MIN_VALUE+" byte_number: "+Integer.SIZE);
System.out.println("Long: "+Long.MAX_VALUE+"###"+Long.MIN_VALUE+" byte_number: "+Long.SIZE);
System.out.println("Float: "+Float.MAX_VALUE+"###"+Float.MIN_VALUE+" byte_number: "+Float.SIZE);
System.out.println("Double: "+Double.MAX_VALUE+"###"+Double.MIN_VALUE+" byte_number: "+Double.SIZE);
System.out.println("Char: "+" byte_number: "+Character.SIZE);
}
}
输出:
Byte: 127###-128 byte_number: 8
Short: 32767###-32768 byte_number: 16
Integer: 2147483647###-2147483648 byte_number: 32
Long: 9223372036854775807###-9223372036854775808 byte_number: 64
Float: 3.4028235E38###1.4E-45 byte_number: 32
Double: 1.7976931348623157E308###4.9E-324 byte_number: 64
Char: byte_number: 16