15-100 Sections S-V / Fall 2008
Quiz 7 / 20 Questions / 30 Minutes
Quiz Date:  Tue 11-Nov-2008

 

  1. When looking up files on www.cmu.edu, your browser first contacts a ____________________________ to determine that www.cmu.edu has the IP address 128.2.10.163.
     
  2. The type “char” is both wider and narrower than either the type _______________ or _______________.
     
  3. \b is the escape sequence for _______________________.
     
  4. A reasonable synonym of “deprecated” might be _______________________.
     
  5. A local variable _____________________ an instance variable if both variables have the same name.
     
  6. The J2ME is basically a version of Java designed for _______________________________.
     
  7. A constant is declared with the _________________ keyword.
     
  8. Unlike Strings, StringBuffers are ________________________.
     
  9. ___________________________ is an example of a sequential access device.
     
  10. _____________________ occurs when Java tries to represent a positive double value that is smaller than Double.MIN_VALUE.
     
  11. This code fails to compile because the “+” operator converts chars to ints by ____________ conversion..
        char c1 = 1;
        char c2 = 2;
        char c3 = c1 + c2;

     
  12. The smallest char value is ______________ and the largest byte value is _________________.
     
  13. If a class implements the _____________________ method in the _______________________ interface, then collections of that class can be sorted using the built-in Arrays.sort or Collections.sort methods.
     
  14. In the code below, “a” is a(n) _______________ parameter and “b” is a(n) _______________ parameter.
       public int foo(int a) {
         int b = a – 32;
         return Math.abs(b);
       }
     
  15. Write a single line of code that demonstrates all of the following, each of which must be clearly labeled:
    1. Assignment Conversion
    2. Method Invocation Conversion
    3. Promotion
    4. Casting
       
  16. Give an example of each of the following in Java’s libraries (and not your own classes):
    1. A static method
    2. An instance method
    3. An overloaded method
    4. A static field
       
  17. The following code demonstrates overflow.  What, exactly, will it print?
    SHOW YOUR WORK!
        byte b1 = 67;
        byte b2 = 97;
        byte b3 = (byte) (b1 + b2);
        System.out.println(b3);

     
  18. What will the following code print?
        int x = 3, y = 7;
        while (x++ < y--)
          System.out.println(--y); // note the decrement!
        System.out.println(x + "," + y);

     
  19. What will the following code print?  Line up your columns carefully!
       int y = 123, z = 45;
       double d = 45.678;
       String s = "Wahoo";
       System.out.printf("123456789\n");
       System.out.printf("%4d%4h\n",y,z);
       System.out.printf("%+07d\n",y);
       System.out.printf("%8.1f\n",d);
       System.out.printf("X%-7sX\n",s);

     
  20. Write a method that takes a variable number of Strings and returns the shortest one.
     
  21. BONUS:  Assuming x and y are ints where x=1 and y=100, what will the following print:
    for (x++,--y;++x<y--;++x,y--)++x; y--; System.out.println(x+","+y);
     

carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem