CMPT 166 Spring 2011 HW Assignments

All homeworks should be turned in electronically to myCourses. Homeworks are due by the start of class (11:40) on the due date. Some homework questions © 2009 Pearson Education Addison-Wesley

HW1 (due Tue 18 Jan) (10pts)

  1. Compare and contrast the JDK and the JRE. [2]
  2. Compare and contrast compiled vs. interpreted languages. [1]
  3. What do comments look like in Java? [1]
  4. Write a minimal "Hello, World!" program in Java. [3]
  5. Describe the eight primitive types in Java, and say something about their differences. [2]
  6. What is the difference between an expression and a statement? [1]

HW2 (due Thu 27 Jan) (10pts)

  1. The controlling expression for a switch statement includes all of the following types except: [1]
    1. char
    2. byte
    3. int
    4. double
  2. A compound statement is enclosed between: [1]
    1. [ ]
    2. { }
    3. ( )
    4. < >
  3. The looping mechanism that always executes at least once is the _____________ statement. [1]
    1. if ... else
    2. do ... while
    3. while
    4. for
  4. A variable whose meaning is confined to an object of a class is called an [1]
    1. instance variable
    2. local variable
    3. global variable
    4. none of the above
  5. A variable whose meaning is confined to a method definition is called an [1]
    1. instance variable
    2. local variable
    3. global variable
    4. none of the above
  6. A method's signature is composed of what elements of its definition? [1]
  7. Write an if-else statement to compute the amount of shipping due on an online sale. If the cost of the purchase is less than $20, the shipping cost is $5.99. If the cost of the purchase over $20 and at most $65, the shipping cost is $10.99. If the cost of the purchase is over $65, the shipping cost is $15.99. [4]

HW3 (due Thu 17 Feb) (20pts)

  1. A programming style that uses a signal and response approach to programming is called: [1]
    1. Object Oriented Programming
    2. Structured Programming
    3. Event-driven Programming
    4. Bottom-up Programming
  2. A button component should have a registered _____________ associated with it. [1]
    1. pixel
    2. JFrame
    3. listener
    4. none of the above
  3. The _____________ manager places components into five regions. [1]
    1. BorderLayout
    2. FlowLayout
    3. GridLayout
    4. AbsoluteLayout
  4. A _____________ is an object that is a simple container class that groups other objects. [1]
    1. JPanel
    2. JMenu
    3. JButton
    4. JTextArea
  5. Explain the model-view-controller pattern when applied to a typical GUI. [3]
  6. Name and describe all the classes involved with writing a serializable object out to a file named "output.txt". [3]

HW4 (due Thu 24 Mar) (20pts)

  1. The method paint() has one parameter of type: [1]
    1. Shape
    2. Graphics
    3. Image
    4. String
  2. Any change to graphics being displayed on the screen requires a call to the ____________ method to update the graphics. [1]
    1. paint()
    2. repaint()
    3. update()
    4. all of the above
  3. The programming statements used to accomplish a thread's task should be included in the method: [1]
    1. start()
    2. init()
    3. run()
    4. none of the above
  4. When a server executes the accept() method it: [2]
    1. Blocks and waits for a connection
    2. Checks for a connection and if there is none it exits
    3. Blocks but in a new thread
    4. Any of the above, depending on the input parameters to accept()
  5. In a Swing program, the only thread that should change the GUI is the ______________ : [2]
    1. main() thread
    2. SwingWorker thread
    3. GUI thread
    4. event dispatch thread
  6. What is a socket? [3]
  7. Compare and contrast TCP and UDP. [4]
  8. Describe how you would use multithreading to design a TCP server that can handle multiple clients. [5]

HW5 (due Thu 7 Apr) (20pts)

  1. What is an Android Activity? Is it the same as an application? Discuss the relationship between an Activity and an app. [5]
  2. Name and describe the three states of an Activity's lifecycle. [6]
  3. Describe how to design an Android application which is internationalization-ready (i.e., its text can be easily translated). [5]
  4. Name and describe two Creational design patterns from the "Gang of Four" (GoF) book. [4]