Review of Identifiers and Variables

An identifier is a name for something. A variable is a name for a location in memory used to hold a data value. When you declare a variable, you are instructing the compiler to reserve a portion of main memory space large enough to hold a particular type of value and indicating the name by which you will refer to that location.

Example 1: These are valid variable declarations:
   int x, y, z;
   double n;
   boolean myState;    
   String myName;
   char sayYes;
Exercise 4: What are the types and what are the variables in the above declarations? Which of the above variables represent primitive types? Which represent objects? How are their memory locations represented?

Ans: The name of the type has to come before the variable name. The types represented in the above declarations are: int, double, boolean, String, and char, respectively. Only String represents an object type. The primitive types are listed in the next section. By convention object types start with an uppercase letter. Variable names should always start with a lowercase letter. The memory location for a variable of primitive type directly holds its value, while the memory location for a variable representing an object, holds the memory location of the object. (Draw a picture.)

To summarize:

Note: For now you only need to understand variables for primitive types.