Skip to Content
Java in a Nutshell, 5th Edition
book

Java in a Nutshell, 5th Edition

by David Flanagan
March 2005
Intermediate to advanced
1254 pages
104h 21m
English
O'Reilly Media, Inc.
Content preview from Java in a Nutshell, 5th Edition

Name

PrintStream

Synopsis

This class is a byte output stream that implements a number of methods for displaying textual representations of Java primitive data types. System.out and System.err are PrintStream objects. PrintStream converts characters to bytes using the platform’s default charset, or the charset or encoding named in the PrintStream( ) constructor invocation. In Java 5.0, convenience constructors allow you to specify a file (either as a file name or a File object) as the destination of a PrintStream. Prior to Java 5.0 the destination had to be another OutputStream object.

The print( ) methods output standard textual representations of each data type. The println( ) methods do the same and follow the representations with newlines. Each method converts a Java primitive type to a String representation and outputs the resulting string. When an Object is passed to a print( ) or println( ), it is converted to a String by calling its toString( ) method. In Java 5.0, you can also use the printf( ) methods (or the format( ) methods that behave identically) for formatted output. These methods behave like the format( ) method of a java.util.Formatter object that uses the PrintStream as its destination.

This class implements the java.lang.Appendable interface in Java 5.0, which makes it suitable for use with a java.util.Formatter.

See also PrintWriter for a character output stream with similar functionality. And see DataOutputStream for a byte output stream that outputs binary, ...

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.
Start your free trial

You might also like

Java in a Nutshell, 8th Edition

Java in a Nutshell, 8th Edition

Benjamin J. Evans, Jason Clark, David Flanagan
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan
Learning Java, 5th Edition

Learning Java, 5th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck
Learning Java, 4th Edition

Learning Java, 4th Edition

Patrick Niemeyer, Daniel Leuck

Publisher Resources

ISBN: 0596007736Supplemental ContentErrata Page