Variables store values.
In Java, variables are strongly typed, which means you have to define the type for each variable whenever you declare it. Otherwise, the compiler will throw error at compile time. Therefore, each variable has an associate data type of either :
- Primitive Type :
- Wrapper Type :
- Object Type:
We made a distinction between Wrapper Type and general Object Type for a reason - wrapper types are closely linked with their primitive counterparts via autoboxing and unboxing; but more on that later.
Typically you can declare variables using the following syntax :
//Primitive Data Type int i = 10; // Object Data Type //initiates an Float object with value 1.0 // variable myFloat now points to the object Float myFloat = new Float(1.0);