public final class StdOut extends Object
Getting started.
To use this class, you must have StdOut.class
in your
Java classpath. If you used our autoinstaller, you should be all set.
Otherwise, either download
stdlib.jar
and add to your Java classpath or download
StdOut.java
and put a copy in your working directory.
Here is an example program that uses StdOut
:
public class TestStdOut { public static void main(String[] args) { int a = 17; int b = 23; int sum = a + b; StdOut.println("Hello, World"); StdOut.printf("%d + %d = %d\n", a, b, sum); } }
Differences with System.out.
The behavior of StdOut
is similar to that of System.out
,
but there are a few technical differences:
StdOut
coerces the character-set encoding to UTF-8,
which is a standard character encoding for Unicode.
StdOut
coerces the locale to Locale.US
,
for consistency with StdIn
, Double.parseDouble(String)
,
and floating-point literals.
StdOut
flushes standard output after each call to
print()
so that text will appear immediately in the terminal.
Reference. For additional documentation, see Section 1.5 of Computer Science: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.
Modifier and Type | Method and Description |
---|---|
static void |
close()
Deprecated.
Calling close() permanently disables standard output;
subsequent calls to StdOut.println() or System.out.println()
will no longer produce output on standard output.
|
static void |
main(String[] args)
Unit tests some of the methods in
StdOut . |
static void |
print()
Flushes standard output.
|
static void |
print(boolean x)
Prints a boolean to standard output and flushes standard output.
|
static void |
print(byte x)
Prints a byte to standard output and flushes standard output.
|
static void |
print(char x)
Prints a character to standard output and flushes standard output.
|
static void |
print(double x)
Prints a double to standard output and flushes standard output.
|
static void |
print(float x)
Prints a float to standard output and flushes standard output.
|
static void |
print(int x)
Prints an integer to standard output and flushes standard output.
|
static void |
print(long x)
Prints a long integer to standard output and flushes standard output.
|
static void |
print(Object x)
Prints an object to standard output and flushes standard output.
|
static void |
print(short x)
Prints a short integer to standard output and flushes standard output.
|
static void |
printf(Locale locale,
String format,
Object... args)
Prints a formatted string to standard output, using the locale and
the specified format string and arguments; then flushes standard output.
|
static void |
printf(String format,
Object... args)
Prints a formatted string to standard output, using the specified format
string and arguments, and then flushes standard output.
|
static void |
println()
Terminates the current line by printing the line-separator string.
|
static void |
println(boolean x)
Prints a boolean to standard output and then terminates the line.
|
static void |
println(byte x)
Prints a byte to standard output and then terminates the line.
|
static void |
println(char x)
Prints a character to standard output and then terminates the line.
|
static void |
println(double x)
Prints a double to standard output and then terminates the line.
|
static void |
println(float x)
Prints an integer to standard output and then terminates the line.
|
static void |
println(int x)
Prints an integer to standard output and then terminates the line.
|
static void |
println(long x)
Prints a long to standard output and then terminates the line.
|
static void |
println(Object x)
Prints an object to this output stream and then terminates the line.
|
static void |
println(short x)
Prints a short integer to standard output and then terminates the line.
|
@Deprecated public static void close()
public static void println()
public static void println(Object x)
x
- the object to printpublic static void println(boolean x)
x
- the boolean to printpublic static void println(char x)
x
- the character to printpublic static void println(double x)
x
- the double to printpublic static void println(float x)
x
- the integer to printpublic static void println(int x)
x
- the integer to printpublic static void println(long x)
x
- the long to printpublic static void println(short x)
x
- the short to printpublic static void println(byte x)
To write binary data, see BinaryStdOut
.
x
- the byte to printpublic static void print()
public static void print(Object x)
x
- the object to printpublic static void print(boolean x)
x
- the boolean to printpublic static void print(char x)
x
- the character to printpublic static void print(double x)
x
- the double to printpublic static void print(float x)
x
- the float to printpublic static void print(int x)
x
- the integer to printpublic static void print(long x)
x
- the long integer to printpublic static void print(short x)
x
- the short integer to printpublic static void print(byte x)
x
- the byte to printpublic static void printf(String format, Object... args)
format
- the format stringargs
- the arguments accompanying the format stringpublic static void printf(Locale locale, String format, Object... args)
locale
- the localeformat
- the format stringargs
- the arguments accompanying the format stringpublic static void main(String[] args)
StdOut
.args
- the command-line arguments