Class Utf8DefaultCharsetExamples
java.lang.Object
net.jrodolfo.java_evolution.java18.Utf8DefaultCharsetExamples
Demonstrates UTF-8 as the default charset, standardized in Java 18.
Before Java 18, APIs that used the default charset could behave differently on different machines because the default came from the operating system and locale. That made simple text examples harder to reason about and made file exchange bugs easy to create accidentally. Java 18 made UTF-8 the standard default so common text handling is predictable across platforms.
The examples still keep the lesson visible: defaults are now safer, but explicit charsets are still best when a file format, protocol, or external system requires one.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]Encodes text using the default charset, which Java 18 standardized as UTF-8.Reads the JVM default charset.booleanChecks whether the default charset is UTF-8.
-
Constructor Details
-
Utf8DefaultCharsetExamples
public Utf8DefaultCharsetExamples()
-
-
Method Details
-
defaultCharset
-
defaultCharsetIsUtf8
public boolean defaultCharsetIsUtf8()Checks whether the default charset is UTF-8.- Returns:
- whether the default charset is
StandardCharsets.UTF_8
-
bytesWithDefaultCharset
Encodes text using the default charset, which Java 18 standardized as UTF-8.- Parameters:
text- the text to encode- Returns:
- encoded bytes
-