menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Reference ...
source image

Dev

7d

read

373

img
dot

Image Credit: Dev

Reference Types vs Primitive Types - Java

  • Java has both Reference and Primitive types, which handle data storage differently.
  • Primitive types store both variable and value on the stack, resulting in a direct copy of values when assigned to another variable.
  • Reference types, however, hold references to objects stored on the heap.
  • When a reference variable is assigned to another, it copies the reference, not the actual object, leading both variables to point to the same object.
  • Changing the object through one variable reflects the change in the other due to the shared reference.
  • To create a new object distinct from the original, a new instance must be instantiated, assigning it to the variable.
  • This distinction helps understand why changes to one reference variable affect another pointing to the same object.

Read Full Article

like

22 Likes

For uninterrupted reading, download the app