java的基础类型和字节大小_java的基础类型和字节大小
學習c語言的時候,這些個東西起碼還是很明確的,因為上課的時候,老師經常問,現在時間久了,見的語言多了,也就有點亂了,也沒怎么在意過。
(武藏) ? ? 既然你誠心誠意的發問了,
(小次郎) 我們就大發慈悲的告訴你!
(武藏) ? ? 為了防止世界被破壞,
(小次郎) 為了守護世界的和平;
(武藏) ? ? 貫徹愛與真實的邪惡,
(小次郎) 可愛又迷人的反派角色~~
(武藏) ? ? 武藏!
(小次郎) 小次郎!
(合) ? ? ? ? 我們是穿梭在銀河的火箭隊!白洞,白色的明天在等著我們!!
(喵喵) ? ? 就是這樣~喵~~~~
(阿伯怪) So~nansi~~~
先了解2個單詞先:
1、bit 位:位是計算機中存儲數據的最小單位,指二進制數中的一個位數,其值為“0”或“1”。
2、byte 字節:字節是計算機存儲容量的基本單位,一個字節由8位二進制數組成。在計算機內部,一個字節可以表示一個數據,也可以表示一個英文字母,兩個字節可以表示一個漢字。
1B=8bit
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)
這種數據類型代表一個比特的信息,但它的“大小”沒有明確的定義。(參考)
測試代碼如下:
class ClassForNameAndClassLoaderTest {
public static void main(String[] args) {
System.out.println("Integer: " + Integer.SIZE/8); // 4
System.out.println("Short: " + Short.SIZE/8); // 2
System.out.println("Long: " + Long.SIZE/8); // 8
System.out.println("Byte: " + Byte.SIZE/8); // 1
System.out.println("Character: " + Character.SIZE/8); // 2
System.out.println("Float: " + Float.SIZE/8); // 4
System.out.println("Double: " + Double.SIZE/8); // 8
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的基础类型和字节大小_java的基础类型和字节大小的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 造出中国第一台等离子电视 彩电巨头A股退
- 下一篇: 业务异常 java_谈谈RxJava处理