Member-only story

Strings — how Java 17 is worse and better than Java 8

Are Java 17 and 8 compilers compatible?

Marian C.
5 min readDec 6, 2021

Overall, strings are the most used and critical data type in web development. Most of time users either read or type something. JSONs and HTML pages produced by Java servers are made through concatenating strings.

Since Java 9 strings are compact — they can occupy twice fewer bytes the equivalent strings in Java 8. If the memory use is reduced, allocation and the garbage collection take less time. At the time the authors of the enhancement were not sure if in real applications the overhead of creating and using the novel compact strings can be compensated by their benefits. Sources in the internet suggest that the Java team is still working to deliver even better balance between memory saving and run-time performance.

Let’s see how Java 8 and Java 17 differ at string handling. I make several straightforward tests without any sophisticated tools so that anyone can easily reproduce my findings.

To be realistic, I use strings derived from real-life web contents. I download a voluminous HTML page from a well-known web site https://edition.cnn.com/world. Then I generate many unique strings by swapping the beginning with the end in the source string.

List<String>…

--

--

Marian C.
Marian C.

Written by Marian C.

Java, JavaScript and SQL developer. Interested in data collection and visualization.

Responses (2)