Iv. data Types for Java
Basic data type: 8 kinds of Primitive.
1. Integral type
BYTE 1b 8-bit-128 to 127
Short 2b 16-bit -2^15 to (2^15)-1
INT 4b 32-bit -2^31 to (2^31)-1
Long 8b 64-bit -2^63 to (2^63)-1
2, floating-point type
FLOAT 4b 32-bit
Double 8b 64-bit
3. Character type
Char 2b 16-bit
4. Boolean type
Boolean flase/true
Note:
1. Automatic type promotion problem in Java
Forward procedure: From low to high bytes can be automatically converted.
Byte-->short-->int-->long-->float-->double
Reverse process: Convert from high byte to low byte with coercion type.
Note: Reverse conversion will lose precision
2. Boolean: Only True and False
3, Char:java with "\u four hexadecimal digits (even if \u appear in the note, followed by an error if not 4 digits)" means converting characters to their corresponding Unicode encodings, and character types enclosed in single quotes.
4. The default floating-point type has a suffix of "f" or "F" for the Double,float data type.
5. The long type has a suffix of "l" or "L".
Class, interface, array
Reference type variable name = new reference type name (parameter);//new half followed by the constructor of the class
Member: Written in parentheses inside the body of the class
Automatic type promotion:
BYTE A=1;
BYTE b=2;
A=a+b; Compilation error automatic type promoted to int
A+=b; Z Self-add no automatic type promotion
Type automatic promotion rules:
A and B do some sort of arithmetic:
A and B have double, the result is double
A and B have float, the result is float
A and B have a long, the result is long
In addition, the result is int.
Converting a high byte to a low byte requires a forced type conversion;
byte c= (byte) a+b;
Java Fundamentals (ii)