我有一个问题,为什么Java原语数据类型不仅仅称为“ Java数据类型”或类似的东西?
Because Java has more data types than just primitives . The primitive data types are:
byte
short
int
long
float
double
boolean
char
A data type that is a non-primitive is a reference data type, which are references to objects .
Some examples are:
String
Integer
ArrayList
Random
JFrame
Here is a simple example of the difference between the two types:
int i1 = 10;
Integer i2 = Integer.valueOf(10);
int i1
is a variable of the primitive data type int
, with the primitive int
value of 10.
Integer i2
is a variable with a reference data type of Integer
, referencing an Integer
object which contains the value 10
.
区分它们和对象 。
Because there are two categories of types in Java.
From the Java Language Specification, CHAPTER 4: Types, Values, and Variables :
The types of the Java programming language are divided into two categories: primitive types and reference types. The primitive types (§4.2) are theboolean
type and the numeric types. The numeric types are the integral typesbyte
,short
,int
,long
, andchar
, and the floating-point typesfloat
anddouble
. The reference types (§4.3) are class types, interface types, and array types. There is also a special null type. An object (§4.3.1) is a dynamically created instance of a class type or a dynamically created array. The values of a reference type are references to objects. All objects, including arrays, support the methods of classObject
(§4.3.2) . String literals are represented byString
objects (§4.3.3) .
To understand why, I think you need to look at programming languages other than Java. For example:
In C++ there are, primitive data types ( int
, double
, etc), constructed data types ( struct
, etc) and object / reference types.
In Ada there are primitive data types, and other data types that are derived from the primitive types; eg range types.
So, my understanding is that Java data types are described as "primitive data types" to put them into the context of other languages. They are "data types" in the sense that they have no object identity, and they are "primitive" in the sense that the specific types are defined by (and fundamental to) the Java language.
对象也是变量,因此术语“原始”用来区分那些类型。
区分对象数据类型。
Because reference types can also be considered data types. Primitives are considered value types. Both can be considered a data type.
Non primitive types are called java reference types and they have name starting with capital letter. Eg: Integer, Float etc. For non primitives we can create the instances.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.