Geschreven door Bouke Nijhuis

Oracle CodeOne `19 update: A sneak peek into Java 13

Development3 minuten leestijd

So the first conference day at Oracle CodeOne in San Francisco is over. I have learned some interesting things today. First I would like to show two new features in Java 13 and then finish with the tip of the day.

On the second conference day, the latest Java version (13!) will be released. Two new features already caught my eye: the switch expressions and text blocks.

Switch expressions

Let’s start with the new switch expressions. There was already a new switch expression in Java 12, but they refined it even further. The easiest way to show this, is by a simple code example:

switch (day) {
    case MONDAY, FRIDAY, SUNDAY -> System.out.println(6);
    case TUESDAY                -> System.out.println(7);
    case THURSDAY, SATURDAY     -> System.out.println(8);
    case WEDNESDAY              -> System.out.println(9);

When using the traditional switch statement one has to use around twenty (!) lines to do the same. Please also note the absence of the break statement and the default label. The new switch statement for the win!

Text Blocks

Another killer feature is the introduction of the text blocks. This is a much requested feature which finally will be available in Java 13. Again a piece of example code.

String html = """
                      <p>Hello, world</p>

So in the past we needed five different Strings for this which we had to concatenate. Furthermore the first four lines needed a new line at the end. So using a text block is much more elegant. It uses less code and it is much more readable. If you are worrying about the spaces in front of every line, the new text block feature got you covered. It will detected those obsolete spaces and remove them for you.

TOTD: Stream debugger in IntelliJ

Last but not least: the tip of the day. Since Java 8 we can use streams. This is a wonderful feature, but it is a bit hard to debug. Apparently IntelliJ has a stream debugger. Whenever you are working with streams, you can put a breakpoint on the line containing the stream. When the debugger pauses the execution of the program, you can click on an icon to show the stream debugger.

The screenshot below shows you exactly where you can find this incredible feature. 

The next screenshot shows you what the debugger looks like. Why didn’t anybody tell me this earlier? 🙂

I am already looking forward to the next conference day, more updates will follow!

Bouke Nijhuis