CIS163AA - Java Prog I - Sect 5811 - Worksheet #3 - by Pat Moss

Due Monday, October 3, 2005

Name: Pat Moss

I.  Definitions:  Please explain the following terms:

 1. parameter     -- (1) A value passed from a method invocation to its
    (p. 655)             definition.
                     (2) The identifier in a method definition that
                         accepts the value passed to it when the method
                         is invoked.
    (p. 639)         (3) actual parameter: The value passed to a method
                         as a parameter.
    (p. 648)         (4) formal parameter: An identifier that serves as
                         a parameter name in a method. It receives its
                         initial value from the actual parameter passed
                         to it.
 2. dot operator  -- After an object has been instantiated, we use the
    (p. 115)         dot operator to access its methods. For example, to
                     invoke the length method defined in the String class,
                     we use the dot operator on the name reference variable:
                                    int count = name.length();
 3. alias         -- A reference to an object that is currently also
    (p. 116-7,639)   referred to by another reference. Each reference
                     is an alias of the other. Aliases can produce
                     undesirable effects unless thay are managed carefully.
 4. legacy system -- Older software that still has value is called a
    (p. 135)         legacy system.
 5. Autoboxing    -- Autoboxing is the automatic conversion between a
    (p. 141)         primitive data value and a corresponding wrapper
                     object. For example, in the following code, an int
                     value is assigned to an Integer object reference
                     varable:
                              Integer obj1;
                              int num1 = 69;
                              obj1 = num1;   // create an Integer object
 6. component     -- Any portion of a software system that performs a
    (p. 644)         specified task, transforming input to output.
    (p. 648)         GUI component: A visual element, such as a button or
                     text field, that is used to make up a GUI.
 7. label         -- (1) A graphicsl user interface component that displays
    (p. 652)             text, an image, or both.
                     (2) An identifier in Java used to specify a particular
                         line of code. The break and continue statements can
                         jump to a specific, labeled line in the program.
 8. layout manager-- An object that specifies the presentation of graphical
    (p. 652)         user interface components. Each container is governed
                     by a particular layout manager.

II. Question or short essay

 1. What happens when Java performs automatic garbage collection?
    (p. 648)
    The process of reclaiming unneeded, dynamically allocated memory.
    Java performs automatic garbage collection of objects that no
    longer have any valid references to them.
 2. What does the String method toLowerCase() do?
    (p. 119)
    Returns a new string identical to this string except all uppercase
    characters are converted to their lowercase equivalent.
 3. What is the purpose of the Java swing class?
    (p. 660)
    The package in the Java API (javax.swing) that contains classes related
    to graphical user interfaces. Swing provides alternative components
    to the Abstract Windowing Toolkit package (AWT), but does not replace
    AWT.
 4. What is the purpose of the setPreferredSize() method of a panel?
    (p. 143, 144, 181)
    The setPreferredSize method accepts a Dimension object as a parameter,
    which is used to indicate the width and height of the component in
    pixels.
 5. What is the purpose of the add() method of a container?
    (p. 143, 776)
    Containers can have an add method that allows other components to be
    added to them. The order in which components are added to a container
    often matters, such as determining which label appears above another.
 6. What is the purpose of the pack() method of a frame?
    (p. 143)
    The pack method of a frame sets its size appropriately based on its
    contents.
 7. How do you format a decimal value to 2 decimal places when you print it?
    (p. 133-134)
    Instantiate an object from the DecimalFormat class.
    Them use its format method to format an output value.
    For example:
                 // Round the output to two decimal places
                 DecimalFormat fmt = new DecimalFormat ("0.##");
                 System.out.println ("The formatted value is " +
                                      fmt.format(value));
 
III. Programming Exercises  

     Write source code for the following.
     Hand in a printed copy of your source code.

     Modify the LabelDemo program on page 149-150 so that it displays a
     fourth label, with the text of the label centered above the image.