This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Documentation / Mathematica / Add-ons & Links / J/Link / Part 1. Installable Java: Calling Java from Mathematica /

1.2.9 The Java Console Window

J/Link provides a convenient means to display the Java "console" window. Any output written to the standard System.out and System.err streams will be directed to this window. If you are calling Java code that writes diagnostic information to System.out or System.err, then you can see this output while your program runs. Like most J/Link features, the console window can be used easily from either Mathematica or Java programs (its use from Java code is described in Part 2). To use it from Mathematica, call the ShowJavaConsole function.

Showing the console window.

ShowJavaConsole[]

Capturing of output only begins when you call ShowJavaConsole, so when the window first appears it will not have any content that might have been previously written to System.out or System.err. You will also note that the J/Link console window displays version information about the J/Link Java component and the Java runtime itself. Calling ShowJavaConsole when the window is already open will cause it to come to the foreground.

To demonstrate, we can write some output from Mathematica. If you executed the ShowJavaConsole[] above, then you will see "Hello from Java" printed in the window:

LoadJavaClass["java.lang.System"];
System`out@println["Hello from Java"]

Although it is convenient to demonstrate writing to the window using Mathematica code like this, this is typically done from Java code instead. Actually, there is one common circumstance where it is quite useful to use the Java console window for diagnostic output written from Mathematica code. This is the case where you have a "modeless" Java user interface (as described in Section 1.2.7) and you have not used the ShareFrontEnd function. Recall that in this circumstance, output from calls to Print in Mathematica will not appear in the notebook front end. If you write to System.out instead, as in the above example, then you will always be able to see the output. You might want to do this in other circumstances just to avoid cluttering up your notebook with debugging output.