CIT 591 Midterm Exam, Fall 2007 Name ______________________________
  1. (5 points) What is the purpose of instance variables in a class?

  2. (5 points) Why should instance variables normally be marked private?

  3. (5 points) How does the DRY principle apply to data?

  4. (4 points) In Eclipse, a small red mark to the left of the Java code indicates a syntax error.

    1. What happens when you move the mouse (without clicking) over this mark?

    2. What happens when you click on this mark?

  5. (2 points) What happens when you double-click on a tab in Eclipse?

  6. (2 points) What is the purpose of the JDK? That is, what does having it allow you to do?

  7. (2 points) What is the purpose of the JRE? That is, what does having it allow you to do?

  8. (3 points) What are the arguments, in the correct order, to the new Color(__, __, __) constructor?

  9. (4 points) Write the Java operators for: "and"_____, "or" _____, "not" _____, "mod" _____.

  10. (3 points) When should a method be static?

  11. (2 points) What does the acronym KISS stand for?

  12. (2 points) What does the acronym YAGNI stand for?

  13. (2 points) Suppose you have the following class definition:
         class Foo { int x = 3; int y = 5; static int z = 7; }
    and you create three Foo objects. How many ints have been created?

  14. (3 points) Write a constructor for the above Foo class that takes one int parameter, and returns a Foo whose x value equals twice the given parameter.

  15. (3 points) Write a method maxCoordinate for the above Foo class that returns the larger of the two values x and y.

  16. (3 points) Suppose names is an array of Strings. Write a loop to print out the contents of this array, one String per line.

  17. (2 points) What is the purpose of an assert statement? That is, when should you use it?

  18. (2 points) Write the declaration for a 9x9 array of integers named sudoku.

  19. (6 points) Give a very brief explanation of each of the parts of public static void main(String[ ] args):

    1. public

    2. static

    3. void

    4. main

    5. String[ ]

    6. args

  20. (5 points) Consider the following program:
        int syntaxErrors(input) {
            private int count = 0;
            do {
                int maximum = 100;
                input = 2 * input;
            } while (input <= maximum);
            return count;
    1. There are three syntax errors in the above method. Find and fix them.

    2. Assuming the errors have been fixed, write a single statement to call this method with the parameter 10 and print the result.

    3. What is printed by the statement in part (b) of this question?

  21. ( 3 points) Why is it a bad idea to do both computation and input/output in the same method?

  22. (2 points) What, in Java, does a method signature consist of?

  23. (4 points) Mention two ways in which writing tests before writing the code to be tested (rather than writing them afterwards) is likely to improve the quality of the program.

  24. (10 points) Tell, very briefly, what each of the following keyword means or does.

    1. static

    2. this

    3. void

    4. break

    5. continue

  25. (4 points) In pair programming,

    1. What is the role of the "driver"? That is, what does he or she do?

    2. What is the role of the "navigator"?

  26. (2 points) What is the name of the program that produced the Java API documentation?

  27. (2 points) Add one line to complete the following constructor.
    class Person {
            String name;
            Person(String name) {
    } }
  28. (3 points) Suppose you get a NullPointerException for the following statement:
    What can you say about the probable cause of the error?

  29. (2 points) What does a "unit test" test?

  30. (3 points) What package is automatically loaded into your Java program, without needing to explicitly import it?