Upgrading from Java 11 to Java 17
Tags: java, news, programming, development
Published: 2021-10-22 12:40:05

---
title: Upgrading from Java 11 to Java 17
published: true
date: 2021-09-23 23:15:00 UTC
tags: java, news, programming, development
canonical_url: https://www.benjaminrancourt.ca/upgrading-from-java-11-to-java-17
cover_image: https://www.benjaminrancourt.ca/images/pexels-cottonbro-8721342.jpg
---
With the release of **[Java 17](https://openjdk.java.net/projects/jdk/17/)** on September 14, 2021, those who use only _Long Term Support_ (LTS) versions will be thrilled to update their Java version! But to use the new functionalities that come with a new version, we must know what are they. 😉

The list below is the ongoing new features that I think will be useful to my colleagues or myself. It doesn't contain any advanced features (or deep), so if you want to know them, check all the release notes. 😘

## [Text indentation](https://www.baeldung.com/java-12-new-features#stringMethods)

Java 12 introduces a new String function: `indent` and as its name says, it helps to **indent a string** with spaces.

```java
// From older versions
final String version = "Java 12";
final String release = " There is a new indent function.";
System.out.println(version);
System.out.println(release);

// Java 12 +
final String version = "Java 12";
final String release = "There is a new indent function.".indent(2);
System.out.println(version);
System.out.println(release);
```

Both versions will produce an output that looks like this:

```java
Java 12
  There is a new indent function.
```
<figcaption>The output text from the previous lines of code.</figcaption>
## [Text Blocks](https://www.baeldung.com/java-text-blocks)

Since Java 15, **multi-line strings** , more know as _Text Blocks_ in the Java world, are available.

```java
// Before
final String description =
  "Une ou plusieurs exceptions sont survenues durant l'exécution de la passerelle."
  + NEW_LINE
  + NEW_LINE
  + " **Veuillez vérifier le bon fonctionnement de celle-ci et adaptez le code en conséquence.**";
 
// After
 final String description =
   """
     Une ou plusieurs exceptions sont survenues durant l'exécution de la passerelle.

     **Veuillez vérifier le bon fonctionnement de celle-ci et adaptez le code en conséquence.**
   """;

// Before
notes.add(
        " **" + note + "**" + NEW_LINE + ("```" + getStackTrace(exception) + "```") + NEW_LINE);

// After
notes.add(
  """
    **%s**
    %s
  """.formatted(note, getStackTrace(exception)));
```

It was one of the features that I was looking forward to, as it is available for a long time in JavaScript. 😎

It is much cleaner, right? 😉

## [Switch Expressions](https://www.baeldung.com/java-14-new-features#switch)

For this one, I'm am not sure about the readability, but it could prove useful to know someday that there is a way to write **succinct switch expressions** in Java 14:

```java
DayOfWeek dayOfWeek = LocalDate.now().getDayOfWeek();
boolean isTodayHoliday = switch (day) {
    case MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY -> false;
    case SATURDAY, SUNDAY -> true;
    default -> throw new IllegalArgumentException("What's a " + day);
};
```

## [Helpful NullPointerExceptions](https://www.baeldung.com/java-14-new-features#nullpointer)

Ever had a _NullPointerException_? Before Java 14, we needed to debug the code to know exactly what variable had caused the exception. Now, the log will be more precise and will say which variable caused the exception.

```
// Before
Exception in thread "main" java.lang.NullPointerException
at com.baeldung.MyClass.main(MyClass.java:27)

// After
java.lang.NullPointerException: Cannot store to int array because "a" is null
```

I can't wait to see the next time I run across this exception. 🤣

## Conclusion

If you find other features that others and I should learn, let me know! 🤘

Do you plan to upgrade your Java applications to the latest LTS version?