Eck Chapters 4-5 discussion questions

  1. Explain the concept of "black box" described in Section 4.1.
  2. Explain the following statement from Eck, Section 4.1: "To use a black box, you shouldn't need to know anything about its implementation; all you need to know is its interface."
  3. You have written a function and defined its input and output types. If you change the way the function works without changing the interface, do you need to change the documentation that describes what the function does?
  4. A subroutine definition in Java takes the form:
    modifiers  return-type  subroutine-name  ( parameter-list ) {
        statements
    }
    
    Name all the modifiers java allows.
  5. You have a class called games.Poker. What is games and what is Poker?
  6. How do you invoke a static method? For example, you have a class called games.Poker, which has a static method called playGame. How would you invoke the method playGame from inside another class?
  7. Look carefully at the definition of GuessingGame2 in Eck Chapter 4, Section 2. What is happening with the static variable gamesWon? Copy the class definition into your NetBeans (or Eclipse) environment and remove the static keyword from the declaration of gamesWon. (Note you will also need to import copy of Eck's class TextIO.java to compile and run the program.) What happens when you try to compile the program after removing the static keyword?
  8. Review the end of section 4.3 and discuss: Why is it risky to make use of a global variable in a sub-routine? How might relying on a global variable within sub-routine disrupt unit-testing?
  9. What does it mean when a function has return type of void?
  10. What does the acronym API stand for?
  11. What does it mean to say that sub-routine have "contracts"? Define: pre-condition and postcondition. How does this idea fit in with unit-testing? (See Section 4.6)
  12. When you declare a variable to be final, what happens?
  13. What does Eck mean by "named constant"?
  14. Look carefully at the RandomMosaicWalk and RandomMosaicWalk2 programs in chapter four. What are the named constants in RandomMosaicWalk2?
  15. What happens if you try something like this in your code, and why?
    void  badSub(int y) {
                    int x;
                    while (y > 0) {
                       int x;  
                         .
                         .
                         .
                    }
                 }
    
  16. Read section 5.1. What does the following command do?
      std = new Student();
    
  17. The class Student has no method called main. Why not?
  18. What Very Important Fact does the Eck textbook emphasize in section 5.1?
  19. What happens if you define a constructor that accepts variables (see: PairOfDice in 5.2) and then attempt to invoke the no-arguments constructor?
  20. What would happen if you declared the variable name to be static in the following class definition:
            public class Student {
            
               private String name;                 // Student's name.
               public double test1, test2, test3;   // Grades on three tests.
               
               Student(String theName) {
                    // Constructor for Student objects;
                    // provides a name for the Student.
                  name = theName;
               }
               
               public String getName() {
                    // Accessor method for reading value of private
                    // instance variable, name.
                  return name;
               }
               
               public double getAverage() { 
                    // Compute average test grade.
                  return (test1 + test2 + test3) / 3;
               }
    
            }  // end of class Student
    
  21. Define the term "garbage collection" in java programming.
  22. How do you use the Java keyword extends in a program?
  23. Explain how the keywords super and this operate. Are there equivalent keywords python?
  24. Is multiple inheritance allowed in Java? What about in python?
  25. What is an interface in java?
  26. Explain how the static variable nextUniqueID operates in the revised version of class Student at the end of Chapter Five.