Java 1.5 Features

Chapter: Java 1.5 Features

CountWords.java uses some of the new features of Java 1.5.

You should compare the ease of programming this with the nightmare you endured doing a similar job in C in your lab.


Exercise 2

Compile and run the program. Be sure you understand everything. Ask now if you don't.

Now I want you to make a small adjustment:


Exercise 3

Change the program so it behaves like this:
> java CountWords CountWords.java =
= appears 11 times
> java CountWords tobe.txt to
to appears 2 times
tobe.txt contains the first few words of Hamlet's soliloquy. See the extra string on the commandline ("=" and "to"): We look it up in the HashMap and print the count.

For this last exercise, you will not need to do much to the code of the original CountWords.java. But you will need to do some digging around in the API documentation.


Exercise 4

Have the individual words and their counts print out as in the original program; but print the words in alphabetic order!


rhyspj@gwu.edu