1 基本數(shù)據(jù)類型
整數(shù)類型
浮點類型
布爾類型
根據(jù)官方文檔描述,boolean類型經過編譯之后采用int來定義(所以此時boolean占4字節(jié),32bits)。如果是boolean數(shù)組則占1字節(jié)(8 bits)。詳見下面紅色標注。
Although the Java Virtual Machine defines a boolean type, it only provides very limited support for it. There are no Java Virtual Machine instructions solely dedicated to operations on boolean values. Instead, expressions in the Java programming language that operate on boolean values are compiled to use values of the Java Virtual Machine int data type.
The Java Virtual Machine does directly support boolean arrays. Its newarray instruction (§newarray) enables creation of boolean arrays. Arrays of type boolean are accessed and modified using the byte array instructions baload and bastore (§baload, §bastore).
In Oracle’s Java Virtual Machine implementation, boolean arrays in the Java programming language are encoded as Java Virtual Machine byte arrays, using 8 bits per boolean element.
The Java Virtual Machine encodes boolean array components using 1 to represent true and 0 to represent false. Where Java programming language boolean values are mapped by compilers to values of Java Virtual Machine type int, the compilers must use the same encoding.
字符類型
代碼演示
數(shù)據(jù)類型細節(jié)
long類型數(shù)據(jù)需要在最后添加L
float類型數(shù)據(jù)需要在最后添加F
字符必須使用''表示,字符串必須要使用""
轉義字符
轉義字符:轉變字符原有含義
常見的轉義字符
轉義字符
注意:在java代碼注釋中不能出現(xiàn) \
2 引用數(shù)據(jù)類型
String表示引用數(shù)據(jù)類型
在Java中一切用""包裹起來的類型都是String類型