Primitive type vs. Reference type

Primitive vs Reference Type Java

Primitive type

  • Basic types for characters, different kinds of integers, and different kinds of floating point numbers (numbers with a decimal point), and also types for the values true and false – char, int, float, and bool. All of these basic types are known as primitive types.
  • The value of the variable is stored in the memory location assigned to the variable. For example, if an integer variable is declared as “int a = 5″, then when we look at the memory location of “a”, there will be a “5” stored there just as expected.

Reference type

  • You might be confused by all the different terminology used. However, class types, object types, and reference types all mean the exact same thing.
  • A variable of a reference type only stores the memory address of where the object is located. For example, “SomeClass anObject”, then when we look at “anObject” in memory, it just stores an address of another place in memory where all the details of “anObject” reside. This memory address is called a reference to the object.



Leave A Comment

Your email address will not be published. Required fields are marked *