Starting with Java 18, the default charset used for Java source files is UTF-8. This change came from JEP 400, “UTF-8 by Default,” which standardized the default across operating systems, locales, and Java installations.
The practical compiler detail is that javac assumes a .java file uses the default charset unless the developer supplies the -encoding option. Therefore, a source file saved in an older platform-dependent encoding may need an explicit setting when compiled with Java 18 or later. Projects that consistently store source as UTF-8 generally gain more predictable builds and fewer “works on my machine” character problems.
This rule concerns how bytes in the source file are decoded; it does not change Java’s internal representation of char values. Java source syntax can still express Unicode characters using escapes, and UTF-16 remains part of the language’s conceptual character model. The change also does not mean every stream uses UTF-8: console output has separate charset behavior, and an API that receives an explicit charset follows that choice.
Before Java 18, the default commonly depended on the host environment. Windows installations could use code pages such as windows-1252 or windows-31j, while many Unix-like systems already used UTF-8. That historical variability is why older source files can expose migration issues.