Java Data Types 数据的类型
详细请参考: https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html
原始类型 vs 引用类型: http://pages.cs.wisc.edu/~bahls/cs302/PrimitiveVsReference.html
Type:
PrimitiveType
ReferenceType
ReferenceType:
ClassOrInterfaceType
TypeVariable
ArrayType: 即 Type []
- Primitive Data Types: 8个原始的数据类型
boolean
: true / falsechar
(16-bit): 16位Unicode character- 整形integral:
byte
(8-bit signed),short
(16-bit signed),int
(32-bit signed),long
(64-bit) - 浮点型floating-point:
float
(32-bit),double
(64-bit) - 参考: http://cs.fit.edu/~ryan/java/language/java-data.html 和 https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
- Reference Data Types
- class等
- 数组: Type[]
- 说明: reference variables store addresses. 引用变量里面是object的地址, 而非object本身. object本身放在heap里. 参考:https://docstore.mik.ua/orelly/java-ent/jnut/ch02_10.htm
Primitive 类型
类型 | 宽度 |
---|---|
byte | 8-bit signed,-128~127 |
char | single 16-bit Unicode character,例’A’ |
… | … |
Reference 类型
- 用于访问对象物体(Reference variables are created using defined constructors of the classes. They are used to access objects.)
- 对象和数组 就是引用(Class objects, and various type of array variables come under reference data type.)
Animal myAnimal = new Animal("giraffe");
char[] greet = { 'h','e','l','l','o' }; // greet holds an array reference