Search code examples
javaunicodejavac

How does javac process Unicode glyphs?


I tried System.out.println("ñ"); and it prints ñ. Why didn't javac run through an error?


Solution

  • Javac can be configured to have a source file encoding. That way, you can use character literals (and symbol names!) with non-ASCII characters.

    If that matches what the file encoding actually is, all works well.

    If not, you may get an error, but more likely, just some broken strings.

    In order to print the text back again, the program needs to know which encoding to use when printing as well. All this needs to be configured correctly (the defaults in Java are not portable), otherwise you can get all kinds of broken text output.