The article is interesting and informative, but I believe Sun's engineers should have thought harder before deciding to separate the Console from Standard Input/Output (System.in, System.out and System.err). Those familiar with Standard I/O (in UNIX, Windows and other operating systems) know that the Standard I/O files and the Console are synonymous -- at least when a program is started without I/O redirection -- and one can not exist without the other.
The first few lines of code in the article capture the irony of this separation succinctly:
Code:
Console console = System.console ();
if (console == null)
{
System.err.println ("Console not available");
return;
}
If you place these lines in a class packaged in an executable JAR (with a Main-Class entry in the manifest file), and start up the code by double-clicking the JAR file, the if statement will find no Console. But the message printed to System.err will mysteriously disappear as well! I believe in most situations where System.console() returns null, printing to System.err fails as well.
The System class has interesting features (such as setIn() and setOut()) that allow a program to redirect its standard I/O files while executing. But the initial configuration of these files (and how they differ from the I/O channel used by System.console()) should atleast be documented (by Sun) in greater detail.