The Predefined Streams

As you know, all Java programs automatically import the java.lang package. This package defines a class called System, which encapsulates several aspects of the run-time environment. For example, using some of its methods, you can obtain the current time and the settings of various properties associated with the system. System also contains three predefined stream variables, in, out, and err. These fields are declared as public and static within System. This means that they can be used by any other part of your program and without reference to a specific System object. , System.out refers to the standard output stream. By default, this is the console. refers to standard input, which is the keyboard by default. System.err refers to the standard error stream, which also is the console by default. However, these streams many be redirected to any compatible 1/0 device. is an object of type Input Stream; System.out and System.err are objects of type Print Stream. These are byte streams, even though they typically are used. to read and write characters from and to the console. As you will see, yo~ can wrap these within character-based streams, if desired.  The preceding chapters have been using System.out in their examples. You can use System.err in much the same way. As explained in the next section, use of is a little more complicated.

[vfb id=1]

Share This