Print Streams
System.out and System.err are
instances of the
java.io.PrintStream
class. This is a subclass of
FilterOutputStream that converts numbers and
objects to text. System.out is primarily used for
simple, character-mode applications and for debugging. Its
raison d'être is convenience, not
robustness; print streams ignore many issues involved in
internationalization and error checking. This makes
System.out easy to use in quick and dirty hacks
and simple examples, while simultaneously making it unsuitable for
production code, which should use the
java.io.PrintWriter class (discussed in Chapter 15) instead.
The PrintStream
class has print() and println()
methods that handle every Java data type. The
print() and println() methods
differ only in that println() prints a
platform-specific line terminator after printing its arguments and
print() does not. These methods are:
public void print(boolean b) public void print(char c) public void print(int i) public void print(long l) public void print(float f) public void print(double d) public void print(char[] s) public void print(String s) public void print(Object o) public void println() public void println(boolean b) public void println(char c) public void println(int i) public void println(long l) public void println(float f) public void println(double d) public void println(char[] s) public void println(String s) public void println(Object o)
Anything at all can be passed to a print() method; whatever argument you give is guaranteed ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access