10

In java, int, byte and boolean are primitives, while String is not.

This can be contrasted with c where string is a primitive (essentially an array of chars).

What is the term for types that aren't primitive?

3
  • meta.programmers.stackexchange.com/questions/6582/… Commented Apr 9, 2015 at 4:55
  • 2
    C does not use the term primitive. A C string is a derived type, comprised of a basic type Commented Aug 14, 2020 at 8:01
  • 1
    In Java, everything that's not a primitive type is a reference type: "There are two kinds of types in the Java programming language: primitive types (§4.2) and reference types (§4.3)." JLS paragraph 4.1 Commented Aug 14, 2020 at 13:34

2 Answers 2

14

The most general term (language agnostic) is a composite data type.

In Java there are several types of composite data type, the most obvious is a Class but an Enum would be another example.

A boxed type is another related term, which is a primitive wrapped in a class to provide an object oriented interface. Examples of this in Java are an int vs. an Integer or a char vs. a Character.

In java, int, byte and boolean are primitives, while String is not.

A String is actually a boxed type. Under the hood it's implemented as a char array just like C and you could use a char array too if you wanted. Obviously most people don't do this as you won't have any of the convenient abstractions provided by the String class.

Here's how the java.lang.String class is implemented in openjdk:

/** The value is used for character storage. */ private final char value[]; 

As you can see, there's nothing special about a string in Java.

2
  • 2
    Depending on the language, there may be abstract non-primitive datatypes that aren't composite (the implementation uses a primitive type, but the type system ensures you can't rely on that.) Additionally, wrapped primitive types are only "composite" in a rather degenerate way. The best way to describe the opposite is primitive is probably just "non-primitive", or perhaps "user-defined". Commented Apr 9, 2015 at 11:39
  • I don't think you can consider String a boxed type, since the underlying character array is actually a reference type. In C# though you can consider it a boxes type, I believe, because it wraps a pointer to a character array. Commented Apr 15, 2015 at 15:07
2

Composite Data Types (CDTs)

One answer to this question may be CDTs, but I don't think that is a general enough response. CDTs only account for a subset of non-primitive types: the definition of CDTs does not account for types that include methods. In fact, CDT is further misleading as they are expected to aggregate data, i.e., include fields. It is not a requirement for non-primitives to have fields.

User Defined Types (UDT)

There are ample examples of non-primitive non-UDTs, e.g., String in Java.

Reference Types

This doesn't help either. Consider that a pointer in C may point to anything, including primitive types.

Summary

As far as I am aware there is no general term for non-primitive types. Maybe except, as mentioned by @Doval, "non-primitive type".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.