Variable

Variables are labels that express a particular position in memory and connect it with a data type. The first way to declare a variable: This specifies its data type, and reserves memory for it. It assigns zero to primitive types and null to objects. .

dataType variableName;

The second way to declare a variable: This specifies its data type, reserves memory for it, and puts an initial value into that memory. The initial value must be of the correct data type.

dataType variableName = initialValue;

var

The first way to declare two variables: all of the same data type, reserves memory for each.

dataType variableName1,variableName2;

The second way to declare two variables: both of the same data type, reserves memory, and puts an initial value in each variable.

dataType variableNameI =initialValueI; variableNameII=initialValueII;

Variable Name

  • Use only the characters ‘a’ through ‘z’, ‘A’ through ‘Z’, ‘0’ through ‘9’, character _‘, and character ‘$’.
  • A name cannot include the space character.
  • Do not begin with a digit.
  • A name can be of any realistic length.
  • Upper and lower case count as different characters.
  • A name cannot be a reserved word (keyword).
  • A name must not previously be in utilized in this block of the program.