What is Variable?
A variable is a named memory location that can hold a value. In java all variables must be declared before they can be used. A variable declaration tells the compiler what type of variable is being used.
Java supports eight different basic data types as shown below.
Type | Description | Keyword |
Character | 16 bit unicode character data | char |
boolean | true or false value | boolean |
byte | 8 bit signed integer numbers | byte |
short | 16 bit signed integer numbers | short |
integer | 32 bit signed integer numbers | int |
long | 64 bit signed integer numbers | long |
float | 32 bit signed floating point numbers | float |
double | 64 bit signed floating point numbers | double |
To declare a variable use below form.
type variable_name;
char type is 16 bit long and is used to hold a single unicode character.
boolean type is used t store either true or false.
byte, short, int and long type variables holds signed whole numbers.
float and double type variables holds signed floating point values, which may have fractional components. The difference between float and double is that double provides about twice the precision as does float.