variables

A simple introduction to the variables in a programming language


Today i will write about the variables in a programming language.

There are two types of variables
          1.Primitive variables
          2.Reference Variables

1.Primitive Variables
  • byte                   
  • short
  • int
  • long
  • float
  • double
  • boolean
  • char

a simple programme to get an idea about primitive variables.

Example 1 -

public class Test1{
       public static void main(String args[]){
           int x; // declare a int type variable(variable name is x)

           x=10; // initialize the variable x to value 10
           System.out.println("The value of the x :"+x);

           x=20; // reinitialize the variable
           System.out.println("The value of the x :"+x);
       }
}

Out put of the programme -
                             The value of the x :10
                             The value of the x :20

I think you get a simple idea about variables by the use of above programme.
Then let's we a see a another simple java programme based on variables.

Example 2-

public class Test2{
       public static void main(String args[]){
           int x=20;
           int y=5;
           System.out.println("Addition :"+(x+y));
           System.out.println("Subtraction :"+(x-y));
           System.out.println("Multiplication :"+(x*y));
           System.out.println("Division :"+(x/y));
       }
}

Out put of the programme -
                     Addition :25
                     Subtraction :15
                     Multiplication :100
                     Division :4

I think you get a some knowledge about Variables.
I will introduce reference Variables using a another post. 


For your more knowledge -
           Compile errors are that occur during the compile time.
           There are also two types
                 1.Syntax Errors
                 2.Grammar Errors

Hope you are enjoy my post.
see you soon.
Thank you. 

Comments

Popular posts from this blog

Algorithm I

love java programming

Loops