We are going to take a look at java variables today.
What is a variable?
In a Java program variable acts like a container that holds a certain value. Each variable must have it’s own data type.
8 primitive data types are as follows:
- byte : Byte is an an 8-bit signed two’s complement integer. It holds value from -128 to 127.
- short: Short is a 16-bit signed two’s complement integer. It’s value ranges from -32,768 to32,767.
- int: Int is 32 bit.
- long: Long is 64 bit. It has minimum value of -2^31 and a maximum value of 2^31-1.
- float: 32 bit. It is used for floating point i.e fractional numbers.
- double: 64 bit. Double is used for fractional numbers. It is used way more than float in Java.
- char: It is a single 16 bit unicode character. It holds a single character value.
- boolean: A boolean is either true or false. Nothing more.