There are 8 types of Java packaging types, namely: 1. Byte; 2. Integer; 3. Short; 4. Long; 5. Float; 6. Double; 7. Boolean; 8. Character.
[Related learning recommendations: java basic tutorial]
There are 8 types of Java packaging types, respectively Yes:
The basic types in Java have simple functions and do not have the characteristics of objects. In order to make the basic types have the characteristics of objects, wrapper classes have appeared, and basic type data can be manipulated like objects. .
1. The packaging class corresponding to the basic type
Basic type use using using using -
1. The packaging class corresponding to the basic type ##short withA. Create a wrapper class object:
Integer i = new Integer(4);
Integer s = new Integer("8");
//An Integer object is created, representing the int value specified by the String parameter "8".
The commonly used methods of packaging classes are as follows:With basic data types, why do we need packaging types?
1. For example, if a piece of data in the business is judged by ID to exist in the database, the benefits of the packaging class come out. Integer can be used to represent the storage ID to determine whether it is empty. That’s it
3,
3.1 In Java, everything is an object, but the eight basic types are not objects.
3.2 Differences in declaration methods. Basic types do not need to be created through the new keyword, while encapsulated types require the new keyword.
3.3 Differences in storage methods and locations. The basic type directly stores the value of the variable and saves it on the stack for efficient access. The encapsulated type needs to point to the instance through a reference, and the specific instance is saved in the heap.3.4 Differences in initial values. The initial value of the encapsulated type is null, and the initial value of the basic type depends on the specific type. For example, the initial value of the int type is 0, and the boolean type is false;
3.5 Differences in usage: If used in conjunction with collection classes, only packaging types can be used.The above is the detailed content of There are several types of Java packaging. For more information, please follow other related articles on the PHP Chinese website!