JMU JMU - Department of Computer Science
Help Tools
Written Portion of Exam 1 - Sample


Answer all of the following questions. This is an "open book" exam, but you must work entirely on your own.
  1. (10 points) Choose the best answer to each of the following:
    (1) _____ In Java, < is
    1. A relational operator
    2. A unary operator
    3. A distributed operator
    4. All of the above
    5. None of the above
    (2) _____ In Java, &&
    1. Is a logical operator
    2. Is a binary operator
    3. Has boolean operands
    4. All of the above
    5. None of the above
    (3) _____ In Java, 'J'
    1. Is a String literal
    2. Is a String variable
    3. Is a char literal
    4. Is a char variable
    5. None of the above
    (4) _____ In Java, a variable is
    1. The implicit loss of precision in arithemtic operations
    2. The way the decrement operator changes
    3. A named space for holding a value
    4. All of the above
    5. None of the above
    (5) _____ In the Java statement i = (int)d; the operator = is a/an:
    1. Assignment operator
    2. Relational operator
    3. Typecast operator
    4. All of the above
    5. None of the above
    (6) _____ In the Java statement i = (int)d; the (int) operator is a/an:
    1. Assignment operator
    2. Relational operator
    3. Typecast operator
    4. All of the above
    5. None of the above
    (7) _____ In the Java statement i = (int)4.0; the operand of the (int) operator is a/an:
    1. Assignment operator
    2. Literal
    3. Typecast operator
    4. All of the above
    5. None of the above
    (8) _____ In Java, what kind of statement is int i;?
    1. Assignment statement
    2. Declaration statement
    3. Typecast statement
    4. All of the above
    5. None of the above
    (9) _____ In Java, an if statement must syntactically (not according to the style guide) contain which of the following?
    1. Curly brackets
    2. A boolean expression in parentheses
    3. An else clause
    4. All of the above
    5. None of the above
    (10) _____ In Java, the main() method of the "main class" must have what return type?
    1. double
    2. int
    3. String
    4. void
    5. None of the above
  2. (20 points) Consider the following fragment (written in Java):
          public class Calculator {
    
             public static final int MAX_SIZE = 100;
          
             public static double circumference(double radius) {
                double result;
          
                result =  2.0 * Math.PI * radius;
                return result;
             }
          }
          

    Identify the best description of each of the following as it is used in this fragment. You may use a description more than once.

    _____ Calculator
    _____ circumference()
    _____ Math
    _____ Math.PI
    _____ MAX_SIZE
    _____ radius
    _____ result
    _____ 2.0
    _____ .
    _____ *
    1. An actual parameter
    2. An arithmetic operator
    3. A "class constant"
    4. The command-line arguments
    5. A formal parameter
    6. A literal
    7. A local variable
    8. A logical operator
    9. The membership operator
    10. The name of a class
    11. The name of a method
    12. A relational operator
    13. A typecast operator
  3. (10 points) Each of the following is supposed to be written in Java, however some may contain syntax errors. For those expressions that are syntacticaly correct, indicate what they evaluate to. For those that are not syntactically correct, write ERROR.
    true && (false || true)


    5 > (0 && 1)


    (5 < 3) || (5 > 3)


    !(false && false)


    3 < 4 < 5


  4. (5 points) Choose the best answer to each of the following:
    (1) _____ In Java, the statement doubl cost;
    1. A compile-time error
    2. A run-time error
    3. A repetitive stress error
    4. All of the above
    5. None of the above
    (2) _____ In a Java program written for CS149, omitting a period from the end of the first line of a comment will cause which of the following?
    1. A compile-time error
    2. A run-time error
    3. A Checkstyle error
    4. All of the above
    5. None of the above
    (3) _____ In Java, assuming that the variables have been both declared and initialized, the statement average = total / 0; will cause which of the following?
    1. A compile-time error
    2. A run-time error
    3. A repetitive stress error
    4. All of the above
    5. None of the above
    (4) _____ In Java, assuming that the variables have been both declared and initialized, the statement average = 0 / count; will cause which of the following?
    1. A compile-time error
    2. A run-time error
    3. A repetitive stress error
    4. All of the above
    5. None of the above
    (5) _____ In Java, assigning an int literal to a variable that was declared to be a double will cause which of the following?
    1. A compile-time error
    2. A run-time error
    3. A repetitive stress error
    4. All of the above
    5. None of the above
  5. (5 points) Provide a concise comparison of the two terms in each of the following.
    Actual parameters and formal parameters


    Declaration and assignment


    double and int


    The @param tag and the @return tag in a Javadoc comment


    Class and method


Copyright 2020