Next: Variables and shoe-boxes
Up: Unit 02
Previous: Variables
Variables are used to denote the data inside a program.
A variable is characterized by the following properties:
- Name: it is necessary in order to identify the variable; for
example: line. Such a name must be a Java identifier,
i.e.:
- a sequence of letters, digits, or the '_' character,
starting with a letter or with '_' (but not with a digit)
- it can be of any length
- lowercase and uppercase letters are considered to be different
- some identifiers, called keywords, are reserved:
class, public, if, while, etc.
- 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.
- Address of the memory location containing the stored data:
- each variable has an associated memory location
- the size of the memory location depends on the type of the variable
- in Java there is no way to know the address of a memory location!!!
This solves several problems related to security, such as attacks by
viruses, etc.
- 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: Variables and shoe-boxes
Up: Unit 02
Previous: Variables