Previous | Next | Trail Map | Writing Java Programs | Input and Output Streams

Your First Encounter with I/O in Java (1.1notes)

If you have been using the standard input and output streams, then you have, perhaps unknowingly, been using input and output streams from the package.

The example program featured in The "Hello World" Application(in the Getting Started trail) uses System.out.println to display the text "Hello World!" to the user.

class HelloWorldApp {
    public static void main (String[] args) {
        System.out.println("Hello World!");
System.out refers to an output stream managed by the System(in the API reference documentation) class that implements the standard output stream. System.out is an instance of the PrintStream class defined in the package. The PrintStream class is an OutputStream that is easy to use. Simply call one of the print, println, or write methods to write various types of data to the stream.

PrintStream is one of a set of streams known as filtered streams that are covered in later in this lesson.

Similarly, the example program around which The Nuts and Bolts of the Java Language(in the Writing Java Programs trail) is structured uses to read in characters entered at the keyboard by the user.

class Count {
    public static void main(String[] args)
        int count = 0;

        while ( != -1)
        System.out.println("Input has " + count + " chars.");
} refers to an input stream managed by the System class that implements the standard input stream. is an InputStream object. InputStream is an abstract class defined in the package that defines the behavior of all sequential input streams in Java. All the input streams defined in the package are subclasses of InputStream. InputStream defines a programming interface for input streams that includes methods for reading from the stream, marking a location within the stream, skipping to a mark, and closing the stream.

So you see, you are already familiar with some of the input and output streams in the package. The remainder of this lesson gives an overview of the streams in (including the streams mentioned on this page: PrintStream, OutputStream and InputStream) and shows you how to use them.

Previous | Next | Trail Map | Writing Java Programs | Input and Output Streams