Default Charset Is UTF-8

Confirm that Charset.defaultCharset is UTF-8 since JDK 18 regardless of platform, so charset-less getBytes and new String behave identically everywhere.

JavaData Integrity

Code

snippet
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

public class EncodingBaseline {

    public static void main(String[] args) {
        // JDK 18 起(JEP 400):default charset 恒为 UTF-8,与平台无关
        Charset def = Charset.defaultCharset();
        System.out.println("defaultCharset: " + def);
        System.out.println("is utf-8: " + (def == StandardCharsets.UTF_8));
        System.out.println("file.encoding: " + System.getProperty("file.encoding"));

        // 不带 charset 参数的 getBytes / new String 走同一套 default charset
        byte[] bytes = "naïve 中文".getBytes();
        System.out.println("utf-8 cjk bytes: " + "中".getBytes().length);
        System.out.println("roundtrip: " + new String(bytes).equals("naïve 中文"));
    }
}

How it works

The code’s whole job belongs to the class EncodingBaseline and the function main.

Caveats

  • No dependencies section needed; the standard library is the whole story.

Using it

Signature: public static void main(String[] args)

The run emits 5 labeled sections — defaultCharset:, is utf-8:, file.encoding:, utf-8 cjk bytes:, roundtrip: — one per step.

Key statements

Charset def = Charset.defaultCharset();

Interactive Tools for This Topic

FAQ

What does Default Charset Is UTF-8 print when run?
No setup needed: run the file and look for labeled lines like `defaultCharset:`, `is utf-8:`, `file.encoding:` in the output.