A primitive data type is a basic type that a programming language defines itself, along with the values it can hold and the operations allowed on them. It is not built from other types by the programmer. The exact meaning, and the list of types that qualify, depends on the language. Java and JavaScript both use the term, but they don’t agree on every type. The clearest example is the string.
The definition, broken down
Two ideas make up the definition.
- A type is values plus operations. Robert Sedgewick and Kevin Wayne put it this way in Algorithms: “A data type is a set of values and a set of operations on those values.” Dev.java, Oracle’s Java learning site, says much the same: “A variable’s data type determines the values it may contain, plus the operations that may be performed on it.”
- Primitive means the language supplies it. Dev.java states: “A primitive type is predefined by the language and is named by a reserved keyword.” You don’t declare a class to get an
int. The language already provides it.
This is a working definition, not a universal formal one. Each language’s documentation decides what it calls primitive.
Primitive types in Java
Java divides its types into primitive types and reference types. Dev.java lists eight primitive types in the source language:
| Category | Types |
|---|---|
| Integer | byte, short, int, long |
| Floating-point | float, double |
| Character | char |
| Truth value | boolean |
A simple example is int count = 3;. The int type limits count to integer values and to the operations Java defines for integers.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
The Java Virtual Machine specification also defines an internal returnAddress type. It has no matching type in the Java programming language, so it isn’t one of the eight you write in source code.
Representation details are part of the language, not the term
A type’s name doesn’t fix its size or arithmetic by itself. Those details come from the language specification. In Java, int is a 32-bit signed two’s-complement integer. According to the Java SE 24 JVM specification, float and double use the 32-bit and 64-bit IEEE 754 formats. These are Java facts. Don’t assume another language’s “integer” or “number” has the same size or behavior.
Rank #2
Primitive doesn’t mean exact for money
Floating-point types approximate many decimal fractions. Dev.java advises against using float or double for precise values such as currency and points to BigDecimal instead.
Is String a primitive data type?
It depends on the language.
- Java: No.
Stringis a class. Dev.java says it “is not technically a primitive data type, but considering the special support given to it by the language, you will probably tend to think of it as such.” - JavaScript: Yes. MDN lists
stringamong its primitive types.
So “always primitive” and “never primitive” are both wrong. Name the language first.
Primitive types in JavaScript
MDN defines a primitive in JavaScript as “data that is not an object and has no methods or properties.” It lists seven:
stringnumberbigintbooleanundefinedsymbolnull
MDN also notes that primitives are immutable. You can still write something like "hello".toUpperCase(), because property access on a primitive behaves as if it were wrapped in an object (automatic boxing). The primitive itself stays a primitive. This definition is specific to JavaScript, and Java’s wording differs.
Rank #4
Java and JavaScript side by side
| Question | Java | JavaScript |
|---|---|---|
| Is a string primitive? | No, String is a class |
Yes, string is primitive |
| How many primitive types? | Eight in the source language | Seven |
| How is “primitive” characterized? | Predefined by the language, named by a reserved keyword | Data that is not an object and has no methods or properties |
| Numeric variety | Several integer and floating-point types with specified formats | Separate number and bigint types |
Compare memory sizes only after stating the language and the implementation layer. The size facts above apply to Java.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Other languages
The same caution applies to every language. Check that language’s own documentation to see whether it uses the word “primitive” and which types it includes. This article doesn’t classify the built-in types of languages other than Java and JavaScript.
Recommended Free Tools
Best Value
Further reading
Algorithms, 4th Edition, by Sedgewick and Wayne, covers primitive data types in Java and their values and operations. It is optional study material. The definition above doesn’t depend on it.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




