Course Content‎ > ‎Session 6‎ > ‎

Standard I/O

In java, there are three streams, which are called as the standard I/O streams. Standard I/O streams include:

  1. – standard input stream
  2. System.out – standard output stream
  3. System.err – standard error stream

The System class provides methods for using various system-related information. refers to the keyboard input; System.out writes output to the monitor; System.err is used for writing error messages.

All these streams are created and opened by default. is InputStream reference; System.out and System.err are declared to be of type PrintStream. PrintStream is used with byte streams. Using print and println methods of the PrintStream with System.out, you can get an output by converting objects and numbers into text.

    //A simple program showing the standard input output
    public class simpleIO
        public static void main (String args[]) throws IOException
            int value;
            char letter;
            System.out.println("Please enter an alphabet: ");
            value =;
            character = (char) value;
                System.out.println("You entered the lowercase: " + letter);

In the above code,

  1. System.out.println prompts user to enter an alphabet.
  2. The program then uses to retrieve the first byte from the keyboard in the integer value.
  3. The input read in the “value” is converted to a char, by using the simple cast.
  4. Using if...else, check is made to see, if the character is lowercase or uppercase. System.out.println and System.out.err both display the messages on the console. If we wish to redirect the output of this code to a file, we can say:
    java simpleIO > output.txt

In this case, System.out.println will print the output to output.txt, but System.out.err will print to the console; thus making sure all the error messages and warnings are displayed on the screen.