Java is 8 basic data types correspond prepared eight kinds of packaging types. 8 kinds of reference data belonging to four packaging types.
Why again provide eight kinds of packaging it? When a method of parameter type is a reference type, but requires the use of a basic types of data packaging on stage this time. (Eight basic types because not enough)
sun packaging company gave these 8 packed, so directly.
Eight basic types of data corresponding to the type of packaging: basic data types ------- packaging type byte ------------- java.lang.Byte Short -------- java.lang.Short ---- int ---------------- java.lang.Integer Long ------------ - java.lang.Long -------------- java.lang.Float float boolean --------- java.lang.Boolean char -------------- java.lang.Character summary: only Integer, Character, memorize it, other initial capital letters. Their parent is Number (abstract). In turn, may convert the reference data to the base data type (unboxing) converting the basic data types of reference data types into a packing.
By accessing constants wrapper class to obtain maximum and minimum values.
System.out.println ( "int maximum value of:" + Integer.Max_VALUE); minimum: Integer.MIN_VAlUE; other packaging, by painting gourd gourd.
After JDK1.5, supports auto-boxing and auto-unboxing. Such as: Integer x = 100; // autoboxing (basic data types automatically converted into packaging) int Y = X; // automatically unpacking additionally performed when the entry box will automatically trigger the arithmetic operation.
String class has a byte [] array, the final modification, because the array length immutable once created (String immutable objects, not the reference), and the final point can not be modified other reference types.
Java in order to improve the efficiency of the program, when the Integer class loader will initialize integer constant (static statement block), Integer will be in [-128,127] All wrapper object is created in advance, put on a method zone " integer constant pool "(cache, caching mechanism), when used directly taken out like, so you will find: integer = 128 a; integer B = 128; System.out.println (ab); // false output is false and X = 127 Integer; Integer Y = 127; System.out.println (Xy) // true output is true because the reference x, y stored in the same address.
Integer commonly used method.
parseInt (String s) method to a digital numeric characters.
Digitally formatted Exception: For example: the data package is not Int Integer
toBinaryString () method to convert decimal to binary form.
toHexString () method to convert decimal to hexadecimal.
toOctalString () method decimal loaded into octal.