Motivation: the information need of computer programs

  • A computer program processes information (data)

  • Information (data) used in computer programs can be broadly categorized in the following 2 categories:

      1. Long term information that are used by multiple functions/methods

        Example:

          • The StackTop for a stack data structure is used by push( ) and pop( )

      2. Short term information that are used by one function/method

        Example:

          • A loop index i in a for-loop inside a function/method

              for ( int i = 0; i < 10; i++ ) ....
            

Concepts to support the information need of computer programs

  • Programming languages provide different kinds of variables to accommodate the information need of computer programs

  • Java:

      • Long term:   (variables used by multiple methods)

          • Static variables

          • Instance variables (in objects)

      • Short term:   (variables used by one method):

          • Parameter variables

          • Local variables

        (You must have learned this in CS170 and CS171
        I will not repeat this in CS255)

Review concept:   life time and scope of variables

  • Variables in a high level programming language always have the following 2 properties:

      1. a life time

      2. a scope

  • The life time of a variable the the (time) period between:

      • When the variable created (= allocated) (i.e.: begins to exist)

      • When is a variable destroyed (= de-allocated) (i.e.: ends to exist)

  • The scope of a variable:

      • Scope = the portion of the computer program where a variable can be accessed (= used in expressions)

  • Note:

    • You should have learned about the life time and scope of the 4 kinds of variables of Java in CS170 and CS171