CS 136 Tutorials - Spring 2007

Tutorials »

Tutorial 11: File I/O and Java Arrays (July 13)

The first part of today's tutorial gives us some practice with file input and output in Java, and the rest of the tutorial mostly focuses on how to use, process, and understand Java arrays. The material for this tutorial comes from lecture module 10 (see handouts).

  1. Java File I/O
  2. Recall that in Tutorial 10 we wrote a class FrequencyList which counts how many times items of some type are added to the list. Let's use this class to count the frequency of words in some text file (you can get working code for FrequencyList and the other relevant classes from the solutions from Tutorial 10 on the main tutorials page).

  3. The semantics of variable mutation in Java
  4. The following two classes have one main method which requires no command-line arguments and writes some output to the screen. Without actually compiling and running these classes, determine exactly what will be printed to the screen by each one. You will probably want to draw the stack/heap memory and trace through the execution step by step.

  5. Array Processing
  6. Write a class ClosestPair which has one method,

    public static int[] find( int[] array )
    This method should find the closest pair of integer entries in array that share the same value, and return the subarray that lies between them (inclusive). If no value is repeated in the array, the method should return null. You can look at the file ClosestPairTest.java for some examples of usage and expected behavior.

Last modified on Wednesday, 09 January 2019, at 14:31 hours.