Variables  - A variable is a basic unit of storage in a Java Program. Variables represent memory location in which value can be stored.

Kinds of variables:
      Instance variables - Instance variables are used to define the attributes of a particular object.
      Class variables - Class Variables are similar to instance variables, except their values apply to all the instances of a class (and to the class itself) rather than having different values for each object.
      Local Variables - Local variables are declared and used inside methods, for example, for index counters in loops, temporary variables or to hold values that you need only inside the method definition itself.

Variable Declaration
      Declaring Single variable : -
            Syntax - Data_Type Variable_name;
            Ex: -    byte n;
                        char word;
                        int num;
                        boolean male;
      Declaring multiple variables : -
            Syntax – Data_Type Variable_name1, Variable_name2, ……. ; 
            Ex-      byte n, m;
                        int num, age;

      Variable name only starts with a letter, an underscore ( _ ), or a dollar sign ($).
      Variable name cannot start with a number.
      The Java language is case sensitive which implies that the variable num in lowercase is different from variable NUM in uppercase.
      In Java a variable name cannot start with a digit or hyphen.
      Variable name cannot contain any white space.

Variable Initialization
      After Declaration
Syntax : - Variable_name = Value;
    Ex: - num = 10;      
      During Declaration / Dynamic Initialization
Syntax : - Data_Type variable_name = value
Ex: - int num = 7;
              char name = ‘A’;                  

Post a Comment

Comment Rules :
1. Do not post Adult/illegal Links.
2. Try to comment in only English Language.
3. Do not post other website's links which are useless.
4. Your Comment should be based on the Topic for other queries Kindly Visit our Contact Us Page.
5. Do not use Abusive Language.
6. Respect each other.
Thank You for following the rules. Please Comment....