Java基本資料型別
1. 整型
- byte
占1位元組空間,取值范圍-2^7~(2^7)-1,二進制首位為符號位,二進制表示0_000_0000~1_111_1111,1_000_0000記為-128,
/**
* A constant holding the minimum value a {@code byte} can
* have, -2^7.
*/
public static final byte MIN_VALUE = https://www.cnblogs.com/fire-cat/p/-128;
/**
* A constant holding the maximum value a {@code byte} can
* have, (2^7)-1.
*/
public static final byte MAX_VALUE = 127;

- short
占2位元組空間,取值范圍-2^15~(2^15)-1,二進制首位為符號位,二進制表示0_000_0000_0000_0000~1_111_1111_1111_1111,
/**
* A constant holding the minimum value a {@code short} can
* have, -2^15.
*/
public static final short MIN_VALUE = https://www.cnblogs.com/fire-cat/p/-32768;
/**
* A constant holding the maximum value a {@code short} can
* have, (2^15)-1.
*/
public static final short MAX_VALUE = 32767;

- int(整數無后綴時默認)
占4位元組空間,取值范圍-2^31~2^31-1,二進制首位為符號位,
/**
* A constant holding the minimum value an {@code int} can
* have, -2^31.
*/
@Native public static final int MIN_VALUE = https://www.cnblogs.com/fire-cat/p/0x80000000;
/**
* A constant holding the maximum value an {@code int} can
* have, (2^31)-1.
*/
@Native public static final int MAX_VALUE = 0x7fffffff;
- long
占8位元組空間,取值范圍-2^63~(2^63)-1,二進制首位為符號位,
/**
* A constant holding the minimum value a {@code long} can
* have, -2^63.
*/
@Native public static final long MIN_VALUE = https://www.cnblogs.com/fire-cat/p/0x8000000000000000L;
/**
* A constant holding the maximum value a {@code long} can
* have, (2^63)-1.
*/
@Native public static final long MAX_VALUE = 0x7fffffffffffffffL;
2. 浮點型 (Java中浮點數采用的是IEEE 754標準)
- 具體參考Java中float/double取值范圍與精度
- float
占4位元組空間,取值范圍+/-3.4E+38F(6~7 個有效位) - double(浮點數無后綴時默認)
占8位元組空間,取值范圍+/-1.8E+308 (15 個有效位)
3. char (Java采用的是16位的Unicode字符集)
占2位元組空間,表示范圍\u0000~\uffff
/**
* The constant value of this field is the smallest value of type
* {@code char}, {@code '\u005Cu0000'}.
*
* @since 1.0.2
*/
public static final char MIN_VALUE = 'https://www.cnblogs.com/u0000';
/**
* The constant value of this field is the largest value of type
* {@code char}, {@code '\u005CuFFFF'}.
*
* @since 1.0.2
*/
public static final char MAX_VALUE = 'https://www.cnblogs.com/uFFFF';
4. boolean
2.3.4. The Type boolean
Although the Java Virtual Machine defines a type, it only provides very limited support for it. There are no Java Virtual Machine instructions solely dedicated to operations on values. Instead, expressions in the Java programming language that operate on values are compiled to use values of the Java Virtual Machine data type. booleanbooleanbooleanint
The Java Virtual Machine does directly support arrays. Its newarray instruction (§newarray) enables creation of arrays. Arrays of type are accessed and modified using the array instructions baload and bastore (§baload, §bastore). booleanbooleanbooleanbyte
In Oracle’s Java Virtual Machine implementation, arrays in the Java programming language are encoded as Java Virtual Machine arrays, using 8 bits per element. booleanbyteboolean
The Java Virtual Machine encodes array components using to represent and to represent . Where Java programming language values are mapped by compilers to values of Java Virtual Machine type , the compilers must use the same encoding. boolean1true0falsebooleanint
以上是Oracle發布的《Java虛擬機規范》中關于boolean的解釋原文
意思大概是:
- JVM沒有提供boolean型別專用的位元組指令,而是使用int相關指令來代替,
- 對boolean陣列的訪問與修改,會共用byte陣列的baload和bastore指令,
- 簡單來說就是:單boolean值占
4位元組空間,boolean陣列則是每個元素占1位元組空間,(boolean實際只需要1位空間)
待續,,,
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/538336.html
標籤:Java
上一篇:Java學習六
下一篇:函式式介面的案例詳解
