I have a question, why aren't Java primitive data types just called "Java data types" or something similar?
9 Answers
Because Java has more data types than just primitives. The primitive data types are:
byteshortintlongfloatdoublebooleanchar
A data type that is a non-primitive is a reference data type, which are references to objects.
Some examples are:
StringIntegerArrayListRandomJFrame
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.
3 Comments
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 thebooleantype and the numeric types. The numeric types are the integral typesbyte,short,int,long, andchar, and the floating-point typesfloatanddouble. 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 byStringobjects (§4.3.3).
Comments
Because reference types can also be considered data types. Primitives are considered value types. Both can be considered a data type.
Comments
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; e.g. 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.
