CS 110 Fundamentals of Computing - Final Exam
Professors Bolker and Rodriguez
Open book
December 19, 2001
login name ________________________        real name_________________________

1	2	3	4	5	6	7	total
  /50	 /20	 /20	 /15	 /15	/15	/30	    /165

Note that some of the answers go on this exam, some in your blue book. If you need more space continue in the blue book.

  1. (50 points) In order to answer this question you will need to read and understand the code in file WcCommand.java (attached, with line numbers). That code compiles and runs correctly (We have tested it).

    Here is a fragment of a Juno session using wc:

    notMars> ls
    3 files:
    greeting	root	12	Tue Dec 18 13:06:35 EST 2001
    greeting2	root	13	Tue Dec 18 13:06:35 EST 2001
    users/	        root	5	Tue Dec 18 13:06:35 EST 2001
    notMars> cat greeting
    hello, world
    notMars> cat greeting2
    hello,
    world
    notMars> wc greeting
    
    *** 
    
    notMars> wc greeting2
    
    *** 
    
    notMars> wc foo
    
    *** 
    
    notMars> wc users
    
    *** 
    
    notMars> wc
    
    *** 
    
    notMars> help
    shell commands
      cat: display contents of a TextFile
      cd: change current directory
      help: display ShellCommands
      logout: log out, shut down the Shell
      ls: list contents of current directory
      mkdir: create a subdirectory of the current directory
      newfile: create a new TextFile
      wc: *** 
    notMars> 
    

    1. (5) How many registered users are there in this Juno system (not counting root)?

    2. (5) Explain why there's a 12 in the listing for greeting but a 13 for greeting2.





    3. (10) Provide appropriate text for lines 4, 8-13, 19, 20 and 23-27 in WcCommand.java .
    4. (10) At each of the six lines marked *** in the script above, show what Juno's response would be. Your answer should take into account your answer to the previous question.
    5. (20) Here are lines 41 and 42 of WcCommand.java:
          int words = 
      	new StringTokenizer(contents).countTokens();
      

      • (2) How many tokens are there on those lines

      • (3) Which tokens are identifiers?

      • (3) Which tokens are Java keywords?

      • (12) In what class would you expect to find method countTokens declared? Write the declaration header, and a javadoc comment to accompany it.









  2. (20 points) What is the call stack when method retrieveJFile in Directory.java is executing because it was called from line 39 in WcCommand.java ? Your answer (in the blue book) should list the methods and the classes they are in: Here's a framework:
    	Class		method
    
    	Juno		main
    
    	// you fill in the rest
    
    	Directory	retrieveJFile
    
  3. (20 points) Draw a box-and-arrow picture (in the blue book) showing the state of the variable commandTable declared on line 36 of Juno.java (Program Listing 7.11) after line line 79 in method fillTable in ShellCommandTable.java has executed.

    Here's how your diagram should start

    
    
    
    
    
    
    
    
  4. (15 points) After you retrieve an object from a Java collection sometimes you must cast it to its own type before sending it a message. Sometimes casting it to the type of a superclass is sufficient.

    Discuss (in the blue book) each of these constructions, referring to explicit examples from programs you have worked on this semester. We should be able to understand your answer without having the code in front of us.

  5. (15 points) It is often useful to override a method in the Object class in order to change how instances of a subclass respond to some message. We have studied two such methods. Discuss one of the two in detail, giving examples from our work.

  6. (15 points) When handling an error in a program you can either Which is better? Illustrate (in the blue book) with examples from code we have studied.

  7. (30 points) Use each of the following words or phrases in a sentence or short paragraph describing something we covered in this course. Your answer (in the blue book) should show that you know the meaning and the significance of the concept. Do not give a formal definition or simply paraphrase something from the text.

    1. OOP
    2. API
    3. JVM
    4. delegation
    5. unit test
    6. signature
    7. io redirection
    8. linking files
    9. grep