Types of java variables.

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.

Advertisements
This entry was posted in Just 4 Knowledge. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s