Variable

Variable is the name of the memory location from which we store the value .This is clear in above example.A name that holds a value.We can use variable to represents data.

A Variable is a location in memory in which values can be stored.They have a name, a type, and a value

Class variableexample

{

public static void main(String aa[])

{

int a; //variable declaration

a=9; //constant value

if(a>0)     //means if a is greater than 0 then message print positive ortherwise negative.

{

System. out. print(“positive”);//message print if condition is true

}

else

{

System. out. print(“negative”);//message print if condition is false

}

}

}

Save this program…….     Variableexample.java

Run……javac variableexample.java

             Java variableexample

In this example, a is the variable of integer type means it can store 2 bytes of data because integer         ( int )Data type can store 2bytes.Data type defines the size of the variable. The size of the variableis depends upon   the data type for example we use “char” data type then it can use 1byte of data so this is clear that every variable is depends upon data type .Without datatype variable is nothing in any programming.