We refer to int, float, double, boolean, and so on as the basic type (primitive type), which is the special class. We can interpret an integer as an object of type int. The int type can have an assignment, addition, subtraction and other operation interfaces. The normal type can be seen as an extension of the basic type. We've seen the basic type as a data member, a parameter to a method, a method's return value, and an automatic variable inside a method. Naturally, ordinary types of objects, such as battery and torch, can also be used in these places.
In the C language, the available data types (basically) are already preset, such as int, float. In Java, in addition to using these preset data types, we can customize the type of data we want by using a class, and then use it through a combination. But the basic type and the normal type are still different. Basic types are often used and occupy little memory space, so in Java, for efficiency, these basic types differ from the memory management of ordinary types (that is, custom classes). For example, once the base type is declared, the memory space is allocated, and the normal type needs to allocate memory space using the New keyword.
Java provides the appropriate generic type for each base type. For example, an int primitive type corresponds to an integer type. If you turn an object of the base type into a corresponding normal type variable, the so-called basic type becomes a generic type (no more memory-management differences).
In this way, we have a deeper understanding of the concept of "all objects" in Java.
- This article is from: Linux Tutorial Network
Java notes--data types