Java: Unicode in Source Code
File Encoding
- In Java 1.5 (2004), the source file encoding should be UTF-16, by spec.
- In Java 18 (2022) , source code should be UTF-8
When saving file, make sure you save it as UTF-8 encoding. Your editor should have a option to do so. 〔see Set Text Editor File Encoding〕
If you have errors in compiling, try
javac -encoding UTF8 filename