A variable is nothing but a cup.A container.It holds something.Variables must have a type and a name.
Variables come in two flavors in java.
- Primitive Variables
- Reference Variables
Primitives Variables hold the fundamental values which includes booleans, integers, characters and floating point numbers. There are 8 types of primitive variables (data types) in java.
- byte(8 bits)
- short(16 bits)
- int(32 bits)
- long(64 bits)
Reference Variables are special type of data types in java which hold reference to the objects. As we all know Java is an object-oriented programming language, these reference variables play a vital role in every application. Reference variable is just like a remote control pointing to a television. Likewise a reference variable is pointed(referenced) to an object to invoke its methods and instance variables. The bits hold by reference variable are of JVM specific. Every reference variable of that particular JVM is of same size irrespective of the object size.