第二章: Everything is an Object:
1、Where storage lives:
- Registers.
- The stack.
- The heap.
- Static storage.
- Constant storage.
- Non-RAM storage.
2、Special case: primitive types
Primitive type | Size | Minimum | Maximum | Wrapper type |
boolean | — | — | — | Boolean |
char | 16-bit | Unicode 0 | Unicode 216- 1 | Character |
byte | 8-bit | -128 | +127 | Byte |
short | 16-bit | -215 | +215—1 | Short |
int | 32-bit | -231 | +231—1 | Integer |
long | 64-bit | -263 | +263—1 | Long |
float | 32-bit | IEEE754 | IEEE754 | Float |
double | 64-bit | IEEE754 | IEEE754 | Double |
void | — | — | — | Void |
3、Arrays in Java
When you create an array of objects, you are really creating an array of references, and each of those references is automatically initialized to a special value with its own keyword: null.
You can also create an array of primitives. Again, the compiler guarantees initialization because it zeroes the memory for that array.
4、Creating new data types: class
When a primitive data type is a member of a class, it is guaranteed to get a default value if you do not initialize it:
Primitive type | Default |
boolean | false |
char | ‘/u 0000’ (null) |
byte | (byte)0 |
short | (short)0 |
int | 0 |
long | 0L |
float | 0.0f |
double | 0.0d |
This guarantee doesn’t apply to “local” variables—those that are not fields of a class. Thus
5、Comments and embedded documentation
There are two primary ways to use javadoc: embed HTML or use “doc tags.” Standalone doc tags are commands that start with a ‘@’ and are placed at the beginning of a comment line.
There are three “types” of comment documentation, which correspond to the element the comment precedes: class, variable, or method.