Why aren't Java primitive data types just called "Java data types"?
+13
A:
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
.
coobird
2009-06-09 13:21:03
Of course, you can do:Integer i2 = 10;
Joshua
2009-06-09 13:35:41
@Joshua: True, but that is because of autoboxing coming into play. Behind the covers, there is an conversion between a primitive and its wrapper class occuring.
coobird
2009-06-09 13:38:09
And, of course: * Object
Bert F
2009-06-09 14:01:07
@Bert F: You're right, I missed the most obvious one! (I think I'll leave the list as it is for now, but that was definitely a good call!)
coobird
2009-06-09 14:04:57
Although the Java Language Specification does not mention it, I believe "void" is also a primitive type.
Julien Chastang
2009-06-09 16:17:57
+1
A:
Because reference types can also be considered data types. Primitives are considered value types. Both can be considered a data type.
yx
2009-06-09 13:21:26
+2
A:
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).
Adam Jaskiewicz
2009-06-09 14:18:43