How are primitive types treated differently than reference types in Java?
There are two types of variables in java
primitive (int,float, etc)
reference (class,interface etc)
the main difference between primitive and reference types is
primitive type has always a value
and can never be null but reference type can be null.
if you dont assign a value to primitive type it will 0 but
reference variable by default has null
if you try to access it it will throw a null pointer exception
assignment operator working on primitive and reference type
primitve values are created in the stack while reference values are created in heap.
Get Answers For Free
Most questions answered within 1 hours.