1. First, eight basic data types are: int, short, float, double, long, Boolean, Byte, char;
Their encapsulation classes are: Integer, short, Float, Double, Long, Boolean, Byte, Character.
Data Type |
Wrapper class |
byte length |
Default Value |
int |
Integer |
4 |
0 |
Short |
short |
2 |
0 |
long |
long |
8 |
0l or 0L |
byte |
byte |
1 |
0 |
float |
float |
4 |
0.0F or 0.0f |
double |
double |
8 |
0.0 |
Char |
Character |
2 |
u0000 |
Boolean |
boolean |
1 |
false |
The values in 2.Java are signed, there are no unsigned numbers, their range is fixed and will not change with the hardware environment or the operating system.
3. The original data type is passed by value when the parameter is passed, and the encapsulated class is passed by reference.
In 4.Java languages, the default declaration of decimals is a double type, so a type conversion is required to initialize a variable of type float.
There are two types of initialization methods for float type variables: float f = 1.0f or float f = (float) 1.0.
5. "= =" and "Equal ()" Methods:
1) The basic type and the basic type of package for the "= =" operator comparison, the basic package type will be automatically removed to the basic type and then compare, so the integer (0) will automatically unboxing to the int type and then compare, obviously return true.
2) Two integer type "= =" comparison, if its value is 128 to 127, then return True, otherwise return false, this is related to the buffer object of integer.valueof (), here does not repeat.
3) Two basic type of package for equals () comparison, first Equals () compares the type, and if the type is the same, continues to compare values, and returns True if the values are the same.
4) The basic package type calls Equals (), but the parameter is the basic type, at which point it is automatically boxed, the base type is converted to its package type, and then the comparison is made in 3.
int i=0; Integer J=new integer (0); System.out.println (i= =j); System.out.println (J.equals (j)); double d=0.5; Double b=new double (0.5); System.out.println (d= =b); System.out.println (B.equals (d)); Integer AA=-100; Integer BB=-100; SYSTEM.OUT.PRINTLN (aa= =bb); Integer AAA=129; Integer BBB=129; System.out.println (AAA==BBB);
Program Run Result:
true true true true true false
Java eight basic types and basic types encapsulation classes