Variables
Variables are, technically, named typed storage locations. What this means is that you can create variables to hold values of a specific type, and you can give these variables names. For example, you can declare:
General format for data type
Type anyName = yourValue;
Example:
int myAge; // declare an integer variable
myAge = 25; // assign a value to the variable
Here you’ve created a variable named myAge and you’ve declared that it will hold an int. An int is an integer variable. You then, subsequently assigned the value 25 to that variable.
Declare, Assign, Initialize
When you allocate space for the variable, you are said to declare the variable. When you give that variable a value, you are said to assign to it. You can combine these two steps into one; this is known as initializing the variable.
int myAge; // declare an integer variable
myAge = 25; // assign a value to the variable
You can combine these steps into a single initialization:
int myAge = 25; // initialize an integer variable
You can declare more than one variable on a line at a time, as long as they all have the same type:
int myFirstVar, mySecondVar, myThirdVar;
Data Type
§ A data type can be described as being either:
§ A built-in data type, such as an int or char, or
§ A user-defined data type, such as a class or interface.
Data types can also be defined as being either: