The package is made up of five main classes: IO
(console I/O, formatting,
serialization, graphics, and test harness support), UniReader
(file / URL input),
UniWriter
(file output), UniPanel
(graphics), and SE
(assertion).
There are also exception classes used
by SE
to distinguish assertion violations.
I/O Choices
The package provides several ways to perform Standard I/O, and they are not
equivalent. To demonstrate the different approaches, consider the following three
fragments that read an int
from the user and store it at x
:
int x = IO.readInt();
UniReader reader = new UniReader();
int x = reader.readInt();
int x = IO.in.readInt();
ENTER
. This approach is the easiest to understand and we ask that all
students use it because it keeps the program prompts and inputs in synch with the user
entries and thus allows input to proceed in an orderly fashion.
The second approach relies on the services of the UniReader class which are all more general, allowing multiple entries per line: Each input starts from where the previous one left off. This approach is well-suited for files but can be quite confusing for beginners when used in an interactive setting. For example, consider the code fragment:
  IO.println("Enter the temperature");   int temp = reader.readInt();   IO.println("Fahrenheit or Celsius? (F/C)");   char unit = reader.readChar();and assume the user entered the value 10, pressed
ENTER
, and then entered 'F'.
This will not work because unit
will end up storing the new line character
that was entered after the integer! In short, this type-ahead feature is a potential
pitfall, especially for beginning users.
The third approach is similar to the second but uses the static class variables in
and out
which are pre-connected to Standard Input and Standard Output.
It is shorter since you don't have to explicitly create the instance.
Although you can mix all three approaches in the same program, it is recommended that your program uses only one.
J2SE 5.0
If you are using J2SE release 5.0 or later, then you do not
need to use the classes of this package. For console and file I/O,
use the new Scanner
and PrintStream
classes.
For assertions, use the assert
keyword. For other services
offered by this package, use the ToolBox
class in
type.lib
.