Presentation is loading. Please wait.

Presentation is loading. Please wait.

The different types of variables in a Java program.

Similar presentations


Presentation on theme: "The different types of variables in a Java program."— Presentation transcript:

1 The different types of variables in a Java program

2 Different types of information Computer program needs information to operate correctly The information used by computer programs are stored inside variables We can divide the information broadly into: As a result, computer programs use different kinds of variables specialized to store short term and long term information Short term information Long(er) term information

3 Different types of information (cont.) Furthermore, because variables can take up a lot of RAM memory, we organize the storage of the different kinds of variable in the RAM memory.

4 The different types of variables in the Java program Java has 4 different kinds of variables (See: http://download.oracle.com/javase/tutorial/java/nutsandbol ts/variables.html) Class variables Instance variables Local variables Parameter variables

5 The different types of variables in the Java program (cont.) General information on variables: Each type of variable has it's own characteristics (properties) The type of variable is determined by: Where the variable is defined Whether the keyword static was used in the variable definition.

6 Properties of variables Every variable has 2 properties: life time = the duration that a variable exists scope = the region in the program where the variable is accessible (can be used)

7 Properties of variables (cont.) Note: The different kinds of variables (class, instance, local and parameter variables) have different life time durations and different scopes

8 Why do programs have different kinds of variables The reason is to accommodate different needs: Short term information: Long term information: Some information need only be retained within a (one) method (We call this kind of information local information) Some information must be retained across several methods

9 Why do programs have different kinds of variables (cont.) Local variables and parameter variables are used to store local (or short term) information Class variables and instance variables are used to store longer term information


Download ppt "The different types of variables in a Java program."

Similar presentations


Ads by Google