Java Variable

Last modified on April 1st, 2014 by Joe.

Java variables can be categorized into the following seven types:

  1. Class Variable
  2. Instance Variable
  3. Array Component Variable
  4. Method Parameter Variable
  5. Constructor Parameter Variable
  6. Exception Handler Parameter Variable
  7. Local Variable

1) Class Variable
A java class variable is a field declared using the keyword static within a java class, or with or without the keyword static within a java interface declaration.

2) Instance Variable
Java variables that are declared without static keyword are instance variables.

3) Array Component
Array components are unnamed java variables that are created and initialized to default values whenever a new java array object is created.

4) Method Parameter
Java variables declared in the method declaration signature are method parameter variables. Whenever a java method is invoked a variable is created in the same name as it is declared.

5) Constructor Parameter
This is similar to the java method parameter variable. The same way, for all the java variables declared in the constructor a variable is created whenever it is invoked.

6) Exception Handler Parameter
Java variables that are declared in the catch clause of a java exception handling mechanism. Whenever a java exception is caught, exception handler parameter variable is created.

7) Local Variable
Java variables that are declared in a block inside a java method or for loop is called a java local variable.

Reference: Java Language Specification 4.12.3

Comments on "Java Variable"

  1. guru says:

    is good and more information aout topic it is better i think

  2. CVU says:


  3. Ganesh says:

    its very interesting


    Very Good Information For all Students Of Programing Language.


  5. Java Array says:

    […] example, imagine if you had to store the list of countries in individual java variables and manipulate them. You will have more than hundred variables to manage. Can’t imagine, it […]

  6. Java Learner says:

    I have my Java functions test tomorrow. Thanks for the help.

  7. Imthiaz says:

    Vey good and easily understandable information


  8. Abhi says:

    Thanx alot it’s very helpful

  9. […] in java. You can store and retrieve a ‘value’ using a ‘key’ and it is an identifier of the value stored. It is obvious that the ‘key’ should be […]

  10. RaMesh says:

    Please provide the thread safety information for all the variables in multi threaded environment

  11. akash says:

    please provide a java script for g-five n90

  12. Aziz says:

    I like it.
    continue it.

  13. ajai kumar gaur says:

    thank you sir for giving my answer

  14. Anonymous says:

    is so good.. . . now i understand it very will keep it up. . more power to you

  15. Rua says:

    Can you please explain different scope of java variables?

    Thanks for the website.Its lovely and very understanding!!


  16. Anonymous says:

    very nice

  17. prince says:


  18. poojamanick says:

    thank you each and every topic is well explained.especially serialization nice……..

  19. maddy says:

    good and interesting topics…

  20. milin modi says:

    Mr. joe i appriciate ur valuable thoughts on variable type and i told in interview all this types but he got angry on me said there are only two type variable in java static and non static.
    so will u pls elobrate with example……..m waiting

  21. sunny says:

    hi, useful info but ur missing reference variables

  22. krutika says:

    nice …i like your tutorial

  23. […] a primitive type, determining the equality is simple. We all know an int value of 10 is always equal to 10. But this […]

  24. Ajay Srivastava says:

    Hi Joy,
    Can you make is clear….
    what is difference betwleen java method parameter variable and local variable ?

    for eg.

    public class A{

    public static int k; // this is class variable
    public int j; // this is instance variable

    public void show (int m, String name){

    int j = 34;
    String title = ” Java book”;
    //… something

    now my question is what difference between variable m and variable j ? since scope of both variable with in a method.

  25. Ajay Srivastava says:

    sorry ! your name is “Joe” not “Joy”.
    its by mistake, hope you won’t mind

  26. saleem says:

    good one but,i want how to declare a variable in java.
    difference declaring a variable in c and java can explain it.

  27. Shashank says:

    Nice I liked it very much !!

  28. Java This says:

    […] To specifically denote that the instance variable is used instead of static or local variable.That […]

Comments are closed for "Java Variable".