Java Variable
A variable is a location in memory (storage area) to hold data.. Each variable should be given a unique name (identifier). Variables play a significant role in our program computation. They are used to store value before and after a computation.
Creating Variables
in the creation of variable, there are two phases
- Declaration
- Initialization
of course, variable creation requires a usage of data types. The data type determines what sort of data that the variable is going to store in the storage area of the memory. the data type could be integer, character, strings, decimal – flow or double, set of value -array, object and so forth.
Declaration of Variables
Declaring is creating a variable to store data in a. temporary storage area. Declaration requires a data type and variable name. The declaration of a variable can be performed following the syntax structure stated below
int age;
float score;
double percentage;
char grade;
String firstName;
figure 1.1 – Variable Declaration
Initialization of Variables
It is an assignment of values to a variable. The initialization requires as assignment operator along with values. The values depends or has to be compatible to the datatype. The initialization can be performed during the declaration time or at run time. The initialization of variable will be as follow
Examples
int age=34;
float score=35.34f;
double percentage=56.32;
char grade ='A';
String firstName="Degu";
figure 1.2 – Variable initialization