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

Due Monday, September 19, 2005

Name: Pat Moss

I.  Definitions:  Please explain the following terms:

 1. statement     -- An individual instruction in a given
    (p. 657)         programming language.
 2. casting       -- A Java operation expressed using a type or class
    (p. 642)         name in parentheses to explicitly convert and 
                     return a value of one data type into another.
 3. concatenation -- The process of attaching the beginning of one 
    (p. 660)         character string to the end of another, resulting
                     in one longer string.
 4. string        -- A series of ordered characters. Represented in
    (p. 643)         Java using the String class and string literals
                     such as "hello".
 5. assignment statement -- A statement of the form x = expression;
    (p. 72)                 when the expression on the right side is
                            evaluated, and the result is copied to the
                            variable on the left side.
                            If the left side variable is a primitive 
                            data type, then the actual value is copied
                            to the memory location of the variable. If 
                            the left side is an object, then the address
                            of the resulting object is copied to the 
                            memory location of the variable.
 6. pixel         -- A picture element. A digitized picture is made up
    (p. 656)         of many pixels.
 7. expression    -- A combination of operators and operands that produce
    (p. 647)         a result.
 8. constant      -- An identifier that contains a value that cannot be
    (p. 644)         modified. Used to make code more readable and to
                     facilitate changes. Defined in Java using the final
                     modifier.
 9. html          -- The notation used to define Web pages. This is a
    (p. 649)         markup language; HTML a subset of SGML. The latest
                     version of 4.01.
10. escape sequence -- In Java, a sequence of characters beginning with 
    (p. 647)           the backslash character (\), used to indicate a
                       special situation when printing values. For
                       example, the escape sequence \t specifies that a
                       horizontal tab should be printed.

II. Question or short essay

 1. What is operator precedence?
    The order in which operators are evaluated in an expression as
    specified by a well-defined hierarchy, such as:
    parentheses, casts, unary +-, */, +-. (p. 655)
 2. What is the purpose of the import statement?
    A Java reserved word that is used to specify the packages and
    classes that are used in a particular Java source code file.
    as well as other programmers, to understand the code. (p. 649)
 3. What is the difference between print() and println() methods?
    a. print() prints the raw data stream (as 16-bit Unicode characters).
    b. println() = same as a. print() plus add a CRLF (aka "new line")
    output sequence at end of line.
 4. What are the eight primitive data types?
    byte, short, int, long, float, double, char, boolean. (p. 74-77)
 5. What does the new operator accomplish?
    A Java reserved word that is also an operator, used to instantiate
    an object from a class.
 
III. Programming Exercises  

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

  1. Write an application that reads from the keyboard a value that represents a total number of seconds.
    Print the equivalent amount of time in hours, minutes, and seconds.

  2. Write an application that reads the radius of a sphere from the keyboard and prints its volume and surface area.
    Use the following formulas, r represents the radius:
    Volume = 4/3 π r3
    Surface Area = 4 π r2