Variable is nothing but a name to be get allocated to a memory location in-order to locate a value. Variables are used to store the values temporarily for some time till the application is getting executed. We can define one or more variables inside an application.        


           [Access Specifier] <DataType> <VariableName> [= <Value>];

Ex: integer customerCode;

string customerName;

Note:  Upon defining the variables, the required amount of memory will be getting reserved inside the application. And it will store the value as “NULL”.

Ex:    Integer productCode;

       String productName;

       String manufacturer;

       Decimal unitPrice;

       Date manufacturingDate, expiryDate

  Boolean isInStock;

Note:  We can define the multiple variables of the same datatype in a single statement as below.                  


              <DataType> <variableName1>, <variableName2>,….., <variableNameN>;

  Ex:  string customerName, customerAddress, emailId;

       Integer customerCode, customerAge;

      Date joiningDate, releivingDate, birthDate;

Assigning the Values:  Once the variable has been defined, then we can store the values inside the associated memory location with the help of “Assignment Operators” as below.


                            <variableName> = <Value>;

Ex: customerCode = 10001;

     customerName = ‘Ramesh Kumar’

       customerAddress = ‘Kukatpally, Hyderabad’;

      customerAge = 42;

Note:  Upon defining the variable, we can assign the value as below.


               <DataType> <variableName> = <Value>;

Ex: Integer productCode = 200001;

     String productName = ‘Mobile Phone;

        String manufacturerName = ‘Apple’;

        Decimal unitPrice = 53500;

        Boolean isInStock = true;