Variable vs Object vs Reference

This post was originally posted at https://agrawalsuneet.github.io/blogs/variable-vs-object-vs-reference/ and reposted on Medium on 4th Dec 2020.

Variables

Variables are named storage of any primitive data type.

int age = 5;
float pi = 3.14;

Objects

Objects are variables of non-primitive data types or user-defined classes.
An object can’t exist without its class.
It is created by the new keyword which calls the constructor of that class which ultimately assigns some memory to that object.
Its size depends on the properties defined in that class.
In java, an object is created on the heap.

Please continue reading at https://agrawalsuneet.github.io/blogs/variable-vs-object-vs-reference/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store