next up previous
Next: Variables and shoe-boxes Up: Unit 02 Previous: Variables

Variables: main properties

Variables are used to denote the data inside a program.

A variable is characterized by the following properties:

  1. Name: it is necessary in order to identify the variable; for example: line. Such a name must be a Java identifier, i.e.:

  2. Type: specifies the type of the data that the variable can store; for example: a variable of type String can store a reference to a string.

  3. Address of the memory location containing the stored data:

  4. Value: the data denoted by the variable at a certain point during the execution of the program; for example: the reference to the object "JAVA".

During program execution, the name, type, and address of a variable cannot change, while the value can.

Note: even if a variable contains the reference to an object, often we abuse terminology and say that the value of the variable "is the object" which the variable refers to.


next up previous
Next: Variables and shoe-boxes Up: Unit 02 Previous: Variables