JAVA 中的几种基本数据类型是什么,各自占用多少字节。
2016-08-20 17:55
441 查看
先了解2个单词先:
1、bit --位:位是计算机中存储数据的最小单位,指二进制数中的一个位数,其值为“0”或“1”。
2、byte --字节:字节是计算机存储容量的基本单位,一个字节由8位二进制数组成。在计算机内部,一个字节可以表示一个数据,也可以表示一个英文字母,两个字节可以表示一个汉字。
1B=8bit
1Byte=8bit
1KB=1024Byte(字节)=8*1024bit
1MB=1024KB
1GB=1024MB
1TB=1024GB
Java基本数据类型
int 32bit
short 16bit
long 64bit
byte 8bit
char 16bit
float 32bit
double 64bit
boolean 1bit
(boolean 的备注+翻译)
This data type represents one bit of information, but its "size" isn't something that's precisely defined.(ref)
这种数据类型代表一个比特的信息,但它的“大小”没有明确的定义。(参考)
测试代码如下:
以 Integer类为例如下:
1、bit --位:位是计算机中存储数据的最小单位,指二进制数中的一个位数,其值为“0”或“1”。
2、byte --字节:字节是计算机存储容量的基本单位,一个字节由8位二进制数组成。在计算机内部,一个字节可以表示一个数据,也可以表示一个英文字母,两个字节可以表示一个汉字。
1B=8bit
1Byte=8bit
1KB=1024Byte(字节)=8*1024bit
1MB=1024KB
1GB=1024MB
1TB=1024GB
Java基本数据类型
int 32bit
short 16bit
long 64bit
byte 8bit
char 16bit
float 32bit
double 64bit
boolean 1bit
(boolean 的备注+翻译)
This data type represents one bit of information, but its "size" isn't something that's precisely defined.(ref)
这种数据类型代表一个比特的信息,但它的“大小”没有明确的定义。(参考)
测试代码如下:
/** * 输出各种基础类型的bit大小,也就是所占二进制的位数,1Byte=8bit */ private static void getBit() { //The number of bits used to represent a {@code byte} value in two's complement binary form. //用来表示Byte类型的值的位数,说到底,就是bit的个数,也就是二进制的位数。 System.out.println("Byte: " + Byte.SIZE); System.out.println("Short: " + Short.SIZE); System.out.println("Character: " + Character.SIZE); System.out.println("Integer: " + Integer.SIZE); System.out.println("Float: " + Float.SIZE); System.out.println("Long: " + Long.SIZE); System.out.println("Double: " + Double.SIZE); System.out.println("Boolean: " + Boolean.toString(false)); }执行结果如图:
以 Integer类为例如下:
/** * The number of bits used to represent an {@code int} value in two's * complement binary form. * * @since 1.5 */ @Native public static final int SIZE = 32; /** * The number of bytes used to represent a {@code int} value in two's * complement binary form. * * @since 1.8 */ public static final int BYTES = SIZE / Byte.SIZE;//这个我加的注释 Byte.SIZE = 8;
相关文章推荐
- java c++ 基本数据类型占用字节空间
- Java中八种基本数据类型占用字节空间总结
- Java基本数据类型占用字节和范围
- Java中boolean数据类型占用多少个字节
- Java 中八种基本数据类型占用字节空间总结
- java中的基本数据类型?各占多少位?多少字节?取值范围?
- java基本数据类型占用字节长度
- Java中八种基本数据类型占用字节空间总结
- Java的基本数据类型各占多少个字节
- java中8中基本数据类型占用字节空间
- Java中八种基本数据类型占用字节空间总结和数据类型之间的转换
- java基础:八种基本数据类型占用字节空间总结
- java中的基本数据类型?各占多少位?多少字节?取值范围?
- 八种基本数据类型占用字节空间总结
- Java基础小知识——基本数据类型和字符串以及字节数组的转换
- Java中的八种基本数据类型所占字节的求法
- Java基本数据类型占用空间的查看
- Java中的基本数据类型在内存所占字节
- Java中的基本数据类型在内存所占字节
- java中各种数据类型占用字节数