01-11-2012, 02:28 PM
Variable Scope & Lifetime
Variable Scope.ppt (Size: 110 KB / Downloads: 24)
Program #3
Some Changes
Draw half bar may be special case of drawing full bar
Some Clarification
Methods are required
Documentation for methods are required
Some Removals
Do not turn in JavaDoc generated files
Software Development
Software Engineering
Documentation
Documentation is hard to keep accurate & up to date
The source code is the best source of documentation
Java to the Rescue
Well, a program included with the Java Development Kit (JDK) JavaDoc
Reads Java source code and produces documentation
JavaDoc
JavaDoc is a command line program which extracts comments from Java source code and formats them into HTML pages
Works on public
packages, classes, interfaces, methods & variables
Also protected methods & variables
Extracts comments which begin with /*
And Special Keywords
Variable Lifetime
The lifetime of a variable describes the time
A variable is created
Through the time that it is destroyed
And that storage is available for re-use
When an object is constructed (instantiated)
All instance variables are created
They are initialized according to their declaration statements
The position in the Java source code is relatively unimportant
It does start at the top and go to the bottom
Static Variables
When a class with static variables is referenced for the first time
All static variables are created
Any initialization is performed
When the object which loaded the static class is no longer needed
(which is hard to tell)
The static variables of that class are destroyed
Parameter Variables
Parameter variables are the variables based on the formal arguments to a method
These are always copies of the value of primitive values declared elsewhere
Or values from expressions
These remain 'in scope' throughout the lifetime of that method call
They are recreated with each method call
Initialization
All instance variables are automatically initialized
0 for numbers
false for boolean
null for objects
unless we specify otherwise
Parameter variables are initialized with copies of their actual arguments