We break down three basic encodings a Java developer encounters: what
UTF-8 is (the standard for the web and most formats), how the internal string format in the JVM works —
UTF-16 (with surrogate pairs and
BOM), and why
ISO-8859-1 still appears. We explain compatibility with
ASCII, bytes per character, and demonstrate correct encoding handling in Java using
StandardCharsets,
Files.write,
Files.readString,
Paths.get. Finally, we cover typical pitfalls: incorrect read/write, the system “default” encoding, confusion between
UTF-16/
UTF-8.