Previous | Next | Trail Map | Writing Java Programs | The Nuts and Bolts of the Java Language


The Standard Output Stream

class Count {
    public static void main(String args[])
        throws java.io.IOException
    {
        int count = 0;

        while (System.in.read() != -1)
            count++;
        System.out.println("Input has " + count + " chars.");
    }
}    
You've already seen the System class being used to read characters from the standard input stream. The character-counting program also uses the System class to display its output. System.out.println() displays its string argument followed by a newline. println() has a companion method print() that displays it argument with no trailing newline. To explicitly specify the newline character use \n.

System.out implements the standard output stream. The standard output stream is a C library concept that has been assimilated into the Java language. Simply put, a stream is a flowing buffer of characters; the standard output stream is a stream that writes its contents to the display. The standard output stream is a convenient place for an old-fashioned text-based application to display its output.

See Also

java.lang.System
Standard Output and Error Streams from Using System Resources


Previous | Next | Trail Map | Writing Java Programs | The Nuts and Bolts of the Java Language