DEV Community

Jack Meyer
Jack Meyer

Posted on • Originally published at jackcmeyer.dev

What's new in Java 15: Setup and Introduction

Java 15 reached General Availability on September 15, 2020. In this Java release, there were many new language features that will improve the developer experience. In this series of blog posts, we will learn how to install Java 15, use it with our IDE, explore the new language features, and refactor existing code to make use of the new language features.

Installing Java 15

macOS

On a macOS, the easiest way to install Java 15 is with Brew, a popular package manager for macOS.

After installing Brew, open your favorite terminal and run the command:

brew cask install adoptopenjdk15

To check if Java 15 was successfully installed, open your favorite terminal, and run the command:

java --version

The output should look like:

$ java --version
openjdk 15 2020-09-15
OpenJDK Runtime Environment AdoptOpenJDK (build 15+36)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 15+36, mixed mode, sharing)

Windows

To install OpenJDK 15 on Windows, first download the OpenJDK 15 zip file.

Once the zip is finished downloading, extract the zip file to some location on your computer.

After the zip is extracted, update your system's JAVA_HOME and PATH variables to point to OpenJDK 15 folder.

JAVA_HOME=C:\path\to\jdk-15
PATH=...%JAVA_HOME%\bin;...

To check if Java 15 was successfully installed, restart the terminal, and then once it is restarted run the command:

java --version

The output should look like:

$ java --version
openjdk 15 2020-09-15
OpenJDK Runtime Environment AdoptOpenJDK (build 15+36)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 15+36, mixed mode, sharing)

Setting up the IDE

Once OpenJDK 15 has been installed, now it is time to configure the IDE to recognize and execute applications using Java 15.

IntelliJ

To start configuring Java 15 for a project in IntelliJ, open up or create a new Java project.

Once the project is opened, navigate to File -> Project Structure. This will open up the Project Structure window. In this window, make sure that the Language Level is set to "15 (Preview)".

Spring Boot

Spring Boot 2.4.0 M1 added support for Java 15 language features.

To try out Java 15, with a Spring Boot app, first go out to Spring Initializr and create a new project. To follow along with this blog series, the following dependencies are needed:

  • Spring Boot 2.4.0 (M3)
  • Spring Web
  • Spring Data JPA
  • Validation
  • Lombok
  • H2 Database

To quickly get started, use this link. This link pre-loads a configuration with the above dependencies on Spring Initializr.

Once the project is imported into some IDE, make sure that the pom.xml is configured properly to use Java 15 code. The two important pieces are the java.version and maven-compiler-plugin configurations.

The java.version value should be 15.

<project>
   ...
   <properties>
        ...
        <java.version>15</java.version>
        ...
    </properties>
    ...
</project>

The maven-compiler-plugin should have a source version value of 15, a target version value of 15, and enable preview options.

<project>
    ...
    <build>
        <plugins>
            ...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>15</source>
                    <target>15</target>
                    <compilerArgs>--enable-preview</compilerArgs>
                </configuration>
            </plugin>
            ...
        </plugins>
    </build>
    ...
</project>

Conclusion

In this post we learned how to download Java 15, tell our IDE to use Java 15 language features, and how to use Spring Boot and Java 15. An example Spring Boot application can be found on my GitHub profile.

Top comments (0)