Member-only story
java-release/java-18
Java 18 : Features and Highlights
This article covers the features of Java 18 with code example
Java 18, released in March 2022, brought many new features and enhancements. Let’s understand them with Java code examples.
1. UTF-8 by Default (JEP 400)
This feature changes the standard charset of the Java SE API to UTF-8. Previously, the default charset was dependent on the user’s operating system. This change makes Java more portable and consistent across different platforms.
This is useful in any situation where you’re dealing with text, especially if that text might include non-ASCII characters. For example, if you’re reading a file that includes non-English characters, this change ensures that you’ll be able to handle those characters correctly regardless of the platform.
// Reading a file with UTF-8 encoding
Path path = Paths.get("file.txt");
String content = Files.readString(path, StandardCharsets.UTF_8);2. Simple Web Server (JEP 408)
This feature provides a simple web server for Java. This is not intended to replace full-featured web servers, but it can be useful for testing, debugging, and simple web services. The server supports HTTP/1.1 and HTTP/2, and includes features like TLS, virtual hosting, and automatic generation of directory listings. It’s also easy to extend with custom handlers…









