Variables:

  1. Each variable in modern programming languages has:

  2. Variable names in Java:

  3. Defining variables in Java:

  4. Examples:

       int a, b, c;			// 3 uninitialzied integer variables
       float r1 = 0.25, r2 = 10.0;	// 2 initialized float variables
    
    (NOTE: semi-colon is used to terminate a variable definition)


    Technical Details on variable definition...

  5. Variable definitions will cause the compiler to obtain (reserve) some unused memory space for the variable.


    The compiler must make sure that it can find the variable back...

  6. The compiler must remember the following 2 pieces of information to locate a variable in memory:

  7. The following will happen when we define a variable of primitive type in Java:


    Recall objects in Java are stored indirectly: click here.

  8. How does the Java compiler obtain the size and location information of a variable:

    ....size information is conveyed in the type of the variable.

    ....location information is obtained when the compiler found unused memory space for a variable


    Recall that the compiler is a program that translate a program written in a high level programming language into computer instructions: click here

  9. I will use the following picture to represent these fact: