In Java, every variable has a type declared in the source code. There are two kinds of types: reference types and primitive types. Reference types are references to objects. Primitive types directly contain values. There are 8 primitive types:

  • byte
  • short
  • int
  • long
  • char
  • float
  • double
  • boolean
Answer from Michael Borgwardt on Stack Overflow
🌐
W3Schools
w3schools.com › java › java_data_types.asp
Java Data Types
... int myNum = 5; // myNum is an int // myNum = "Hello"; // Error: cannot assign a String to an int String myText = "Hi"; // myText is a String // myText = 123; // Error: cannot assign a number to a String ...
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › datatypes.html
Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)
In addition to the eight primitive data types listed above, the Java programming language also provides special support for character strings via the java.lang.String class. Enclosing your character string within double quotes will automatically create a new String object; for example, String s = "this is a string";. String objects are immutable, which means that once created, their values cannot be changed.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-data-types
Java Data Types - GeeksforGeeks
Primitive data types store simple values directly in memory. Java provides eight primitive data types, each with a fixed size and range, which are summarized below:
Published   November 7, 2016
🌐
GeeksforGeeks
geeksforgeeks.org › java › primitive-data-type-vs-object-data-type-in-java-with-examples
Primitive data type vs. Object data type in Java with Examples - GeeksforGeeks
July 12, 2025 - When a variable is copied then another copy of the variable is created and changes made to the copied variable will not reflect changes in the original variable. Here is a Java program to demonstrate all the primitive data types in Java. Integer: This group includes byte, short, int, long · byte : It is 1 byte(8-bits) integer data type. Value range from -128 to 127. Default value zero. example: byte b=10;
🌐
DataCamp
datacamp.com › doc › java › java-data-types
Java Data Types
Unlike primitive data types, reference data types do not store the value directly. public class ReferenceExample { public static void main(String[] args) { String str = "Hello, World!"; // Class type int[] numbers = {1, 2, 3, 4, 5}; // Array type System.out.println(str); for (int num : numbers) { System.out.println(num); } } } In this example, str is a reference variable of type String, and numbers is an array of integers.
🌐
Edureka
edureka.co › blog › data-types-in-java
Data Types in Java | Primitive and Non-Primitive Data Types | Edureka
July 5, 2024 - The difference between primitive and non-primitive data types are as follows: Primitive types are predefined in Java. Non-primitive types are created by the programmer and is not defined by Java. Non Primitive types can be used to call methods to perform certain operations, while primitive types cannot. A primitive type always has a value, whereas non-primitive types can be null. A primitive type starts with a lowercase letter, while non-primitive types start with an uppercase letter.
Top answer
1 of 14
55

In Java, every variable has a type declared in the source code. There are two kinds of types: reference types and primitive types. Reference types are references to objects. Primitive types directly contain values. There are 8 primitive types:

  • byte
  • short
  • int
  • long
  • char
  • float
  • double
  • boolean
2 of 14
8

What do people mean by "Types"?

In the real world there are different "types" of things. e.g. There are many different "types" of vehicles: "sports cars" for driving fast, "utes" for carrying tools, "trucks" for transporting lots of goods, and limousines for traveling in luxury.

In the same way, in Java, you can have different "types" of data which serve different purposes: e.g. numbers (are used to add/subtract etc), "strings" are used to communicate words and letters. You cannot use letters to add - that just does not make sense, nor could you use numbers to write a sentence.

Primitives vs reference types - what does it mean? What's the difference?

Now there are some "types" of data which are basic. These are already created by the boffins at Redmond/Sun. These are called "primitive" java types, and they store the values within themselves. What does that mean? It's best explained by example:

Example of a primitive type

If I gave you a $50 note, then the note in and of itself is worth $50. The value is stored in the note itself.

Primitives Juxtaposed with Reference Types

Imagine that instead of giving you $50 I gave you an piece of paper which has on it an address to a safe deposit box. The piece of paper i gave you is not worth $50 in and of itself, but it points to an address where you can get your $50. This piece of paper is basically a "reference" type, because it doesn't store any values within and in and of itself, it merely points to certain addresses.

But I can give you an address to anything: planes, castles, rainforrests: anything!

Summary

You can't just hand someone a plane or a Shinkansen train from your back pocket: you just hand them an address to it. Juxtapose this with having $50, or any type of currency: the actual substance is in your back pocket.

That in an nutshell is the difference between primitive and reference types.

(Corny analogy used to help you understand and remember.)

🌐
Wikipedia
en.wikipedia.org › wiki › Primitive_data_type
Primitive data type - Wikipedia
2 weeks ago - The basic types of Java are similar to that of C. The Java virtual machine's set of primitive data types consists of: byte, short, int, long, char (integer types with a variety of ranges)
Find elsewhere
🌐
Programiz
programiz.com › java-programming › variables-primitive-data-types
Java Data Types (Primitive Types)
The long data type can have values from -263 to 263-1 (64-bit signed two's complement integer). If you are using Java 8 or later, you can use an unsigned 64-bit integer with a minimum value of 0 and a maximum value of 264-1.
🌐
Oxford University
mathcenter.oxford.emory.edu › site › cs170 › variables
Variables and the 8 Primitive Data Types
The amount of memory allocated ... its type. There are 8 primitive types of data built into the Java language. These include: int, byte, short, long, float, double, boolean, and char....
🌐
Great Learning
mygreatlearning.com › blog › it/software development › data types in java – primitive and non-primitive data types
Data Types in Java – Primitive and Non-Primitive Data Types
January 27, 2025 - Java has 8 primitive data types, and each one has its own characteristics, size, range, and use cases. ... Common Use Cases: byte is typically used to save memory in large arrays, primarily when storing data that doesn’t require a large range, such as image processing or file I/O operations. ... Common Use Cases: The short data type is used when memory savings are critical, and the range of values doesn't need to be large, for example ...
🌐
Wikibooks
en.wikibooks.org › wiki › Java_Programming › Primitive_Types
Primitive Types - Wikibooks, open books for an open world
January 28, 2006 - Primitive types are the most basic data types available within the Java language. There are 8: boolean, byte, char, short, int, long, float and double. These types serve as the building blocks of data manipulation in Java. Such types serve only one purpose — containing pure, simple values ...
🌐
DataFlair
data-flair.training › blogs › java-data-types
Java Data Types - Primitive & Non-Primitive Data types with Examples - DataFlair
April 17, 2024 - There are 8 types of Java primitive data types namely: a. Int b. Float c. Char d. Boolean e. Byte f. Short g. long h. Double. int is used for storing integer values. Its size is 4 bytes and has a default value of 0. The maximum values of integer is 2^31 and the minimum value is -2^31. It can be used to store integer values unless there is a need for storing numbers larger or smaller than the limits
🌐
Masai School
masaischool.com › blog › java-data-types
Exploring Java Data Types: Primitive and Reference Types
October 11, 2023 - There are eight primitive data types in Java, each tailored for specific kinds of values: • byte: This type stores small whole numbers, usually ranging from -128 to 127. For example, ... • short: Ideal for larger whole numbers, typically within the range of -32,768 to 32,767.
🌐
Medium
medium.com › @AlexanderObregon › java-data-types-primitive-vs-non-primitive-417925cee746
Java Data Types: Primitive & Non-Primitive | Medium
November 16, 2023 - Non-primitive data types, also known as reference types, represent complex data and more sophisticated structures than primitive types. They include classes, arrays, interfaces, and more. Unlike primitive types that store actual values, non-primitive types store references to the objects in memory. Classes: The building block of object-oriented programming in Java. Examples include String, Integer, System, and user-defined classes like Person, Car, etc.
🌐
HWS Math
math.hws.edu › javanotes › c2 › s2.html
Javanotes 9, Section 2.2 -- Variables and the Primitive Types
For example, if test is a variable of type boolean, then both of the following assignment statements are legal: ... Java has other types in addition to the primitive types, but all the other types represent objects rather than "primitive" data values. For the most part, we are not concerned with objects for the time being.
🌐
Baeldung
baeldung.com › home › java › core java › introduction to java primitives
Introduction to Java Primitives | Baeldung
January 8, 2024 - In this tutorial, we’ll look at what these primitives are and go over each type. The eight primitives defined in Java are int, byte, short, long, float, double, boolean and char. These aren’t considered objects and represent raw values.
Top answer
1 of 8
33

It kind of depends on the language.

For example, in languages like C and C++, you have a number of built-in scalar types - int, float, double, char, etc. These are "primitive" in the sense that they cannot be decomposed into simpler components. From these basic types you can define new types - pointer types, array types, struct types, union types, etc.

Then you have a language like old-school Lisp, where everything is either an atom or a list. Again, by the above definition, an atom is "primitive" in the sense that it cannot be decomposed into something simpler.

Edit

As far as I'm concerned, the terms "primitive", "basic", and "built-in" are pretty much interchangeable. If you want to get really pedantic, though, you can distinguish between types that are "built-in" (those explicitly provided by the language definition) and types derived from the built-in types that are still "primitive" or "basic" in that they cannot be decomposed into simpler elements. C's typedef facility allows you to create new type names for existing types. Ada allows you to create new scalar types that have constraints on them. For example, you can derive a Latitude type from the built-in floating type, with the constraint that it can't take on values outside the range [-90.0, 90.0]. It's still a primitive or basic type in that it cannot be broken down into any simpler components, but since it's user-defined, it's not considered a "built-in" type.

Again, these concepts are a little fuzzy, and it really depends on context. For example, the notion of a "built-in" type is meaningless for a typeless language like BLISS.

2 of 8
20

From the Java perspective:

In Java, there is a very clear distinction between primitive and non-primitive types.

A variable of a primitive type directly contains the value of that type (in other words, they are value types).

A variable of a non-primitive type doesn't contain the value directly; instead, it is a reference (similar to a pointer) to an object. (It is not possible in Java to create user-defined value types).

Java has eight primitive types: byte, short, int, long, char, boolean, float and double. Anything else is a non-primitive type.

🌐
Geekster
geekster.in › home › data types java – primitive and non-primitive
Data Types Java - Primetive and Non-Primetive (with Example)
June 27, 2024 - Let’s look at each type of integer. The byte data type is an example of primitive data type. It isan 8-bit signed two’s complement integer. Its value-range lies between -128 to 127 (inclusive).