CIT591 Final Exam
Fall, 2003
Name_________________________________________

Please keep all your answers short and to the point. Read the questions carefully and answer only the question that was asked--do not provide extra information that was not asked for.

When I ask for a "single statement," that means one statement that does not contain any other statements.

In your Java code, be sure I can tell the difference between your lowercase letters and your CAPITAL LETTERS.

  1. (25 points) Short answer:
    1. What is the default layout manager for an Applet?

    2. What is the default layout manager for a Frame?

    3. What type of parameter does the applet paint(...) method take?

    4. What type of value is 5L ?

    5. A hex (hexadecimal) digit is equivalent to how many bits?

    6. What class is like an array that gets bigger when you add things to it?

    7. What are the two kinds of polymorphism?

    8. When will the expression x % y give a negative result?

    9. What operation does the ^ operator (as in, x ^ y) perform?

    10. Another term for "static variable" is _________________________________.

    11. What color is returned by the call new Color(0, 0, 255)?

    12. When you declare an object (for example, String s;), what is space allocated for?

    13. What is the immediate superclass of Error?

    14. On what stream does printStackTrace() put its output?

    15. What package contains the Random class?

    16. What package contains the Observer interface?

    17. What package contains the ActionListener interface?

    18. What character encoding does Java use?

    19. The Java API documentation was generated by what program?

    20. In order to run an Applet, you need to create what additional file (besides the .class files) ?

    21. Name an AWT Component that is also a Container.

    22. What does the acronym UML stand for?

    23. What should not change when you refactor a program?

    24. A method that is used to create objects is called a _____________________ method.

    25. Name one keyword that is reserved but not used by Java.

  2. (3 points) Variable ch is a char variable, containing a letter in the first part of the alphabet. Write a single statement to change ch to be the next consecutive character (for example, if ch has value 'e', your statement will change it to have value 'f').


  3. (3 points) Write a single statement that will print out 5 lines if the value of lineCount is 5, but will print out 1 line if the value of lineCount is 1.


  4. (3 points) Write a single statement to set integer x to the numeric value of s, where s is a String that contains only digits.


  5. (4 points) Write nested for loops to print out all the values in the array defined by int[][] rag = { {1}, {2, 3}, {4, 5, 6} }; Each row should be printed on a separate line.





  6. (3 points) What is printed by the following program?
  7. public class CallTest {
    	
    	public static void main(String[] args) {
    	    int n = 5;
    	    int[] a = new int[] {1, 2, 3};
    	    modify(n, a);
    	    System.out.println(n + " " + a[0] + a[1] + a[2]);
    	}
    	
    	static void modify(int x, int[] y) {
    	    x++;
    	    y[1] = x;
    	}
    }
    
    
    
  8. (10 points) Each of the following statements is legal in some context (you do not need to specify the context in which the statement is legal). Tell briefly what each statement does. Do not use the keywords this or super in your explanation (for example, for that=this; don't say "assigns this to that").

    1. that = this;


    2. this();


    3. super();


    4. super.that();


    5. that(this);


  9. (8 points) What lines are printed out by the following program? (Be sure to write the lines in the correct order.)
    public class Test {
        String instVar;
        static String statVar = "A";
        
        Test() {
            System.out.println("test: " + instVar + statVar);
            instVar = "B"; statVar = "C";
        }
        
        public static void main(String[] args) {
            Test t1 = new Test();
            t1.instVar = "D";
            t1.statVar = "E";
            Test t2 = new Test();
            System.out.println("inst: " + t1.instVar + t2.instVar);
            System.out.println("stat: " + t1.statVar + t2.statVar);
        }
    }
    
    
    
    
    
  10. (3 points) What will happen when the following code is executed?
         int i = 5;
         while (i > 0);
            System.out.println(i--);
         System.out.println("Blast off!");
    


  11. (2 points) Every method declared within an interface is automatically both _______________ and _______________ (two keywords).

  12. (2 points) Elegant software is both ____________________ and ____________________.

  13. (2 points) If we construct an object of type Foo, where
    class Foo { int x = 5; int y; Foo() { x = 2; } }
    ,
    what are the values of x and y in the new object?


  14. (2 points) Briefly describe the two arguments to the instanceof operator.



  15. (3 points) Write a single statement equivalent to x %= y; that does not use the %= operator.



  16. (2 points) Under what circumstances does the expression x ^ y return true?



  17. (4 points) If class Foo implements Runnable and contains a run() method, write the code necessary to start an object of this class running in a new thread.




  18. (4 points) If vec is a Vector and x is an int, both the following statements are wrong. Correct them.

    1. vec.add(x);


    2. x = vec[0];


  19. (2 points) Briefly, tell how you can "break" a constructor chain.




  20. (5 points) Write a method that, given a nearly-but-not-quite sorted int array, counts how many elements are "out of place." An element is "out of place" if it is larger than the element that follows it.







  21. (1 point) Name one method that is inherited by every object: _______________________ .

  22. (1 point) A method whose use is discouraged (because it has been replaced by a newer, better method) is called a ____________________ method.

  23. (1 point) A class used to create an object from a primitive, so that the primitive can be used where an object is required, is called a(n) ____________________ class.

  24. (1 point) You can cause the current Thread to stop doing anything for five seconds by writing the statement _________________________.

  25. (1 point) You don't need a browser in order to use an Applet; you can use the standalone program ____________________.

  26. (1 point) In a ___________________ method it is illegal to use the keyword this.

  27. (4 points) Which of the following are objects in Java? (Write "yes" or "no" for each.)

    1. arrays

    2. errors

    3. events

    4. exceptions