A window where you can view the System.out.println and other debugging data from a Java application or Applet. Sometimes it will be covered over by the Applet or Java Web Start app. Sometimes you have to enable it.
In Java 1.5, if an Applet fails, it will sometimes display a broken icon. Right click on it and that will give you the option to look at the Java console to learn why. The stack trace might mean nothing to you, but it will to those who wrote the program. Copy the entire contents to help in diagnosing the problem.
|Engaging the Java Console in Your Browser||Console Window Size|
|java.exe vs javaw.exe||Reading From The Console|
|Writing to the Console||Colours|
|Import Static Shortcut||Learning More|
|Merging System.out and System.err||Links|
If you are in a browser you have to enable to console before you can see it. Avant and Chrome do not support Java, or more precisely, their support does not work. Safari does support the Java console. Browsers no longer have menu-items to engage and disengage the console. You do it in the Java Control Panel.
In Mac OS Leopard, you also have to enable the console on the Java Preferences Application.
One of the most useful associations to set up is to make *.jar files executable with java.exe. Then you can just type the name of the jar on the command line to start it executing. If you use javaw.exe rather than java.exe you won’t see the console output. Watch out, Java installers often associate *.jar files with javaw.exe instead of java.exe, overriding your setting.
out.print( "\033[H\033[2J" );You can effectively clear the console with a println loop of about 80 lines. This won’t clear a log file of course. You can also write to the less-redirectable error log with System.err.println.
Some consoles don’t display System.out data, just System.err. It is thus probably best to get in the habit of using System.err.println for debugging or error message output.
You can’t read a single character from the console, the way you can with getC in C. The operating system delivers I/O a line at a time. The program can’t read the characters in a line until the user hits Enter. This allows the user to correct mistakes with BS before Java sees them.
How do you get around this? AWT (Advanced Windowing Toolkit) keystroke events are registered immediately. You can thus accept data in a component. You need to fake a console with a TextArea or similar component.
Peter van der Linden created a set of simple console routines for reading character data in various formats called EasyIn. I seem to recall him also writing a keystroke by keystroke class, but I can find no record of it.
When you write on the console with Java strange things happen to the Unicode characters. They get modified in various ways so what you see on the screen can be quite astonishing. Factors that affect what you see include:
Rather than trying to explain what happens, I suggest you experiment with the following program that will send a selection of common Unicode characters to the console. Have a look at the results to understand what to expect with your own programs.
Java does not give you any means to control the foreground or background colours of the console. You might experiment with ANSI sequences in Windows, but they will not work on other platforms. If you want colour, write your own scrolling logging class perhaps based on JTable. It is much simpler than you would think. Then you can go crazy with fonts, colours, fading, gradients etc.
This page is posted
Optional Replicator mirror
|no blog for this page||Canadian
Your face IP:[220.127.116.11]
You are visitor number|