Home > Java > javaTutorial > There are several types of Java packaging

There are several types of Java packaging

coldplay.xixi
Release: 2020-08-25 13:21:56
Original
3165 people have browsed it

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.

There are several types of Java packaging

[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                                                                                                                                                                                                                    with

A. Create a wrapper class object:

Integer    i = new Integer(4);
Copy after login

//Create an Integer object to represent the specified int value.

Integer    s = new Integer("8");
Copy after login

//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

2. After being converted into a packaging class, it can be treated as an object. Some methods allow basic types to be stored, but only objects can be stored~


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. There are several types of Java packaging

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template