Variables and References

What are variables?

A Variable is an object that can hold a value. The are called variables since you can change the value it holds the value is said to vary. Java has several different types of variables. Some hold numeric data, some hold character data, and some hold references to other objects.

Variables can be of two types:
  1. Primitive – to hold numbers, characters, booleans.
    int X;
  2. Reference – hold references to objects (hold that thought for a minite)
    Dog d;

Two things are required to declare a variable:
  1. Type
  2. Name

Naming Variables