The primitive type and complex type differ from each other mainly in how the data is stored. Are you really looking at the differences between a primitive type and a class type
1. Each variable is stored as a place in the computer's memory.
The above statement applies to both primitive types and class types.
Differences:
2. For the primitive type: the value of the variable is stored in the memory cell assigned to the variable .
This means that if we set int x = 10 , the value of x will be stored in where the value of 10 is stored, that is, in the memory cell. This means when we "look" at x, "10" is stored there. Maybe this will help, think that this is more like a “job” where you indicate that x is equal to 10.
3. For the class type: it only stores the memory address of the object that stores the value. He is not the object itself.
The integer x = 10 will have a memory address pointing to an object of type int, which will then hold the value 10. This is called a reference . Think of it as a directory that says go to the shelf in order to really get the value.
AND
Class types are also known as reference types or object types, that is, they all mean a class object (whether it be an Integer class or a MyPerson class).
Primitive types are not reference types because they do not contain a reference (memory address).
This difference is the reason for “wrapper classes” in everyday use, and types such as Integer are considered as wrapper classes for int , which allows you to manipulate data, such as storing integers in a data structure, such as an ArrayList. Since ints primitive data type, it is not an object , but Integer is. Since primitive types are not objects , we must put them in a class so that we can add them to Lists, Dictionaries, etc. Thus, we have a List of objects (which indicate primitive types), but they are not a bare primitive data type in and of themselves. See this SO question for further details.
Additional reading about the difference between primitive and non-primitive (aka Class / reference / object type) is described in detail here . They have a good diagram illustrating this too.