A variable of a class type – like a String – stores objects of its class differently from how variables of primitive types – like int or char – store their values.
For a variable of a primitive type, the value of the variable is stored in the memory location assigned to the variable. So, if an integer variable is declared as “int x = 3″, then when we look at the memory location of “x”, there will be a “3″ stored.
a variable of a class type only stores the memory address of where the object is located – not the values inside the object.
A value of a primitive type – like a type int – will always require the same amount of memory to store one value.
An object of a class type, like an object of the class String, can be of any size.
a variable of a class type stores an address of the object, and not the object values themselves – which are stored at that address in memory.
Class types are also reference types
class types are also reference types. But, primitive types (like ints, booleans, etc.) are not reference types since primitive type variables do not hold references (which are basically addresses).
Read full article from Java: Primitive Type vs. Class Type
For a variable of a primitive type, the value of the variable is stored in the memory location assigned to the variable. So, if an integer variable is declared as “int x = 3″, then when we look at the memory location of “x”, there will be a “3″ stored.
a variable of a class type only stores the memory address of where the object is located – not the values inside the object.
A value of a primitive type – like a type int – will always require the same amount of memory to store one value.
An object of a class type, like an object of the class String, can be of any size.
a variable of a class type stores an address of the object, and not the object values themselves – which are stored at that address in memory.
Class types are also reference types
class types are also reference types. But, primitive types (like ints, booleans, etc.) are not reference types since primitive type variables do not hold references (which are basically addresses).
Read full article from Java: Primitive Type vs. Class Type