Java variables can be categorized into the following seven types:
- Class Variable
- Instance Variable
- Array Component Variable
- Method Parameter Variable
- Constructor Parameter Variable
- Exception Handler Parameter Variable
- 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
This Core Java tutorial was added on 02/06/2008.