hands on: java 13
we learned a lot about the java 12 features in the former post. in this article, we will have a closer look at java 13. in java 13, there is only one interesting feature we can have a look at. the other features mentioned in version 13 were already introduced in 12, so we won't repeat ourselves.
with java 13 a new way to write strings was introduced. sometimes we want to build a json, html, xml or sql queries by hand. stored entire scripts or partial parts as strings is a common way to do so. one way to write it can be something like that:
private static final String HTML = "<html>\r\n" + "<body>\r\n" + "\t<b>Hi All</b>\r\n" + "</body>\r\n" + "</html>" + "\r\n";
even after thousand declarations of such ugly string constants, one cannot get familiar with all the special characters which disturb the fluent reading of contents. but we aren't sad anymore, because java 13 introduced the string text blocks, which can improve the readability a lot. lets have a look:
private static final String HTML_IN_NICE = """ <html> <body> <b>Hi All</b> </body> </html> """;
nice! reading the text block feels like looking at a real html file. all the special characters and the concatenation with with the + symbol are all gone. awesome!
in java 13 there aren't a lot of changes, but the one described in this article is a very valuable change and many developers will appreciate it.
so what do you think about the changes? do you like it and will try to adapt them in upcoming process, or will you wait for the next lts before using it? let me know.
see the full source code here: https://github.com/KlemensM/java13