jGRASP Java Unicode I/O Setup on Windows

On Linux and recent versions of MacOS, the default file and terminal encoding is UTF-8. With a default OS installation, you will not have to do anything to use Unicode characters in Java terminal I/O. The only problem may be that the Run I/O font (which is also the CSD font) may not support all the characters you need (see below).

Unicode I/O will not work by default on Windows. You will usually see question marks for characters that aren't supported by the system default file encoding and be unable to pass these characters as input.

On Windows, character encoding for console I/O in Java is problematic. The default file encoding is likely to be 8 bit depending on the system locale. The console encoding is likely to be a different 8 bit encoding. jGRASP connects to a Java program through pipes on Windows. Java treats these as files for encoding purposes, and uses the file encoding to convert characters during I/O. The file encoding also affects file I/O whenever an encoding is not specified. Because it would change the default behavior of many programs, we have chosen not to automatically change the file encoding for Java programs when you change the I/O Charset setting in jGRASP. To get Unicode I/O, you will need to add command line flags as described below. Implementation of Java RFE 8179511 would address this problem. It also appears that future version of Windows will be more UTF-8-friendly.

Settings for UTF-8 terminal I/O for Java programs on Windows

UTF-8 is the simplest choice to achieve Unicode I/O on Windows. To do this, under "Settings" > "Compiler Settings" > "Workspace", on the "Charset" tab, set "I/O Charset" to "UTF-8" as shown below.

Setting Dialog with UTF-8 Settings for Charset

Next, under "Settings" > "Compiler Settings" > "Workspace", select language "Java" if not already selected. On the "Flags / Args" tab, change "FLAGS2 or ARGS2" for "Run" and for "Debug" to "-Dfile.encoding=UTF-8" as shown below.

Setting Dialog with UTF-8 Java Compiler Flags

The second step will have the side effect of changing the default charset for file I/O to UTF-8 also. If this will be a problem, another option is to programmatically set the charset you use for I/O to UTF-8.

From a Windows console, you can get Unicode I/O through UTF-8, though results may not be exactly correct depending on the Windows version - you may see some duplicate characters at the ends of output lines. To do this, change the code page and pass the file encoding flag to Java:

chcp 65001
java -Dfile.encoding=UTF-8 MyMainFile

Font Issues

Having the correct encoding won't help if the font used in the jGRASP Run I/O panel doesn't support the characters that you're printing. In that case, jGRASP will display the hex code for unsupported characters. jGRASP uses the same font for Run I/O and editing windows. Under "Settings" > "Font" the "CSD Font" setting is used to change that font. Finding a font that is good for editing and supports all the Unicode characters you need could be challenging, so you may need to switch the font when editing and testing.