tags:

views:

1246

answers:

7

Why aren't Java primitive data types just called "Java data types"?

+4  A: 

To distinguish between them and Objects.

Pool
+1  A: 

To distinguish them from object data types.

Bill the Lizard
+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
Of course, you can do:Integer i2 = 10;
Joshua
@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
And, of course: * Object
Bert F
@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
Although the Java Language Specification does not mention it, I believe "void" is also a primitive type.
Julien Chastang
+1  A: 

Because reference types can also be considered data types. Primitives are considered value types. Both can be considered a data type.

yx
+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 the boolean type and the numeric types. The numeric types are the integral types byte, short, int, long, and char, and the floating-point types float and double. 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 class Object (§4.3.2). String literals are represented by String objects (§4.3.3).
Adam Jaskiewicz
+4  A: 
Julien Chastang
A: 

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.