Default charset varies by machine
String and file APIs that omit a charset can decode differently across environments. Specify StandardCharsets.UTF_8 or the protocol-defined charset explicitly.
Since JDK 18,
Charset.defaultCharset()is UTF-8 by default, but code running on older JDKs still gets the platform value. Corrections or other cases welcome below.Methods without a charset argument use the platform default, which can vary between machines and decode the same bytes differently. Passing StandardCharsets.UTF_8 or the protocol's charset removes that variation.
When no charset is named, decoding depends on the environment, so the same bytes can yield different strings. Name the charset explicitly, using UTF-8 or whatever the protocol mandates.
Specific and to the point: "Default charset varies by machine". Worth a look if you touch java / encoding.
Omitting the charset ties the result to the host's default encoding, a common reason text looks right on one machine and garbled on another. Pass the charset explicitly at every such call.
Specific and to the point: "Default charset varies by machine". Worth a look if you touch java / encoding.
"Default charset varies by machine" is a useful thing to know about with java / encoding. Thanks for sharing it.
Good to see "Default charset varies by machine" written down. Handy reference for anyone working with java / encoding.
"Default charset varies by machine" is a useful thing to know about with java / encoding. Thanks for sharing it.