---
title: "Java 16: An Introduction from a Java 8 Monogamist"
description: "With the recent release of Java 16, we thought it would be nice to provide a\nquick overview of its new features and upgrades. While the update introduces a\nnumber of behind-the-scenes changes, this post will focus instead on coding\nfeatures that are more immediately relevant to programmers in their"
image: https://blog.ippon.tech/hubfs/Imported_Blog_Media/Java-16-_-An-Introduction-from-a-Java-8-Monogamist-3.png
---

[Skip to main content](https://blog.ippon.tech/java-16-introduction#main)

[![IpponLogoKleinBlue](https://blog.ippon.tech/hs-fs/hubfs/IpponLogoKleinBlue.png?width=219&height=64&name=IpponLogoKleinBlue.png) ![IpponLogoKleinBlue](https://blog.ippon.tech/hs-fs/hubfs/IpponLogoKleinBlue.png?width=219&height=64&name=IpponLogoKleinBlue.png) ![IpponLogoKleinBlue](https://blog.ippon.tech/hs-fs/hubfs/IpponLogoKleinBlue.png?width=168&height=49&name=IpponLogoKleinBlue.png) ![IpponLogoKleinBlue](https://blog.ippon.tech/hs-fs/hubfs/IpponLogoKleinBlue.png?width=168&height=49&name=IpponLogoKleinBlue.png)](https://ipponusa.com/)

- [Home](https://ipponusa.com)
- [Show submenu for About About](https://ipponusa.com/about-us) 
    - [Who We Are](https://ipponusa.com/who-we-are)
    - [Careers](https://ipponusa.com/careers)
    - [Show submenu for Our Partners Our Partners](https://ipponusa.com/our-partners/) 
          - [AWS](https://ipponusa.com/our-partners/aws/)
          - [Snowflake](https://ipponusa.com/our-partners/snowflake/)
          - [Databricks](https://ipponusa.com/our-partners/databricks/)
          - [Microsoft](https://ipponusa.com/our-partners/microsoft/)
- [Show submenu for Services Services](https://ipponusa.com/services) 
    - [Snowflake](https://ipponusa.com/service/snowflake-concierge/)
    - [Artificial Intelligence](https://ipponusa.com/service/artificial-intelligence/)
    - [Data & Analytics](https://ipponusa.com/service/data-analytics/)
    - [Cloud Strategy](https://ipponusa.com/service/cloud-strategy/)
    - [Platform Modernization](https://ipponusa.com/service/platform-moderization/)
    - [Product Innovation](https://ipponusa.com/service/product-innovation/)
    - [Operating Model](https://ipponusa.com/service/operating-model/)
- [Blogs](https://blog.ippon.tech/)
- [Success Stories](https://ipponusa.com/success-stories/)
- [Show submenu for Resources Resources](https://ipponusa.com/resources/) 
    - [eBooks](https://ipponusa.com/ebooks/)
    - [The Data Pour](https://info.ippon.tech/the-data-pour)
    - [Videos & Webinars](https://info.ippon.tech/videos-and-webinars)
    - [Media Center](https://ipponusa.com/media-center/)

Search

Open main navigation

Close main navigation

- [Home](https://ipponusa.com)
- Show submenu for About About 
  
    - About
    - [About](https://ipponusa.com/about-us)
    - [Who We Are](https://ipponusa.com/who-we-are)
    - [Careers](https://ipponusa.com/careers)
    - Show submenu for Our Partners Our Partners 
      
          - Our Partners
          - [Our Partners](https://ipponusa.com/our-partners/)
          - [AWS](https://ipponusa.com/our-partners/aws/)
          - [Snowflake](https://ipponusa.com/our-partners/snowflake/)
          - [Databricks](https://ipponusa.com/our-partners/databricks/)
          - [Microsoft](https://ipponusa.com/our-partners/microsoft/)
- Show submenu for Services Services 
  
    - Services
    - [Services](https://ipponusa.com/services)
    - [Snowflake](https://ipponusa.com/service/snowflake-concierge/)
    - [Artificial Intelligence](https://ipponusa.com/service/artificial-intelligence/)
    - [Data & Analytics](https://ipponusa.com/service/data-analytics/)
    - [Cloud Strategy](https://ipponusa.com/service/cloud-strategy/)
    - [Platform Modernization](https://ipponusa.com/service/platform-moderization/)
    - [Product Innovation](https://ipponusa.com/service/product-innovation/)
    - [Operating Model](https://ipponusa.com/service/operating-model/)
- [Blogs](https://blog.ippon.tech/)
- [Success Stories](https://ipponusa.com/success-stories/)
- Show submenu for Resources Resources 
  
    - Resources
    - [Resources](https://ipponusa.com/resources/)
    - [eBooks](https://ipponusa.com/ebooks/)
    - [The Data Pour](https://info.ippon.tech/the-data-pour)
    - [Videos & Webinars](https://info.ippon.tech/videos-and-webinars)
    - [Media Center](https://ipponusa.com/media-center/)
- Search
- [Contact Us](https://ipponusa.com/contact/)

[Contact Us](https://ipponusa.com/contact/)

# Java 16: An Introduction from a Java 8 Monogamist

![Mike Mitchell](https://app.hubspot.com/settings/avatar/d41d8cd98f00b204e9800998ecf8427e)

 by [Mike Mitchell](https://blog.ippon.tech/author/mike-mitchell)

March 26, 2021

![Java 16: An Introduction from a Java 8 Monogamist](https://blog.ippon.tech/hubfs/Imported_Blog_Media/Java-16-_-An-Introduction-from-a-Java-8-Monogamist-3.png)

[Java](https://blog.ippon.tech/tag/java/) [Ippon](https://blog.ippon.tech/tag/ippon/) [introduction](https://blog.ippon.tech/tag/introduction/) [new features](https://blog.ippon.tech/tag/new-features/) [beginner](https://blog.ippon.tech/tag/beginner/) [intro](https://blog.ippon.tech/tag/intro/) [oracle](https://blog.ippon.tech/tag/oracle/) [java 16](https://blog.ippon.tech/tag/java-16/)

 

With the recent release of Java 16, we thought it would be nice to provide a quick overview of its new features and upgrades. While the update introduces a number of behind-the-scenes changes, this post will focus instead on coding features that are more immediately relevant to programmers in their daily work. Before diving in, let's take a look at the coding upgrades made between Java 9 and Java 15.

 

## Java 9 and 10

***JShell***: execute and experiment with Java code without creating a class or main method; those of you familiar with the Python shell will quickly be able to put this to good use

```
jdk-9\bin>jshell.exe
|  Welcome to JShell -- Version 9
|  For an introduction type: /help intro
jshell> "This is my long string. I want a part of it".substring(8,19);
$5 ==> "my long string"
```

***.copyOf()***: create an unmodifiable copy of lists, maps, and sets (modify throws exception)

```
List<Integer> copyList = List.copyOf(someIntList);
copyList.add(4); //throws exception
```

***.toUnmodifable()***: similar to *copyOf*(), but for stream collection

```
List<Integer> evenList = someIntList.stream()
  .filter(i -> i % 2 == 0)
  .collect(Collectors.toUnmodifiableList());
evenList.add(4); //throws exception
```

***.orElseThrow()***: if no value is present for an optional, throw a specified exception

```
Integer firstEven = someIntList.stream()
  .filter(i -> i % 2 == 0)
  .findFirst()
  .orElseThrow();
```

***var***: new reserved type name, similar to its use in Scala; allows for type inference; must be initialized, and cannot be initialized to null (needed for compiler to determine what to do); only supported for local in-method variables

```
Map<Integer, String> map = new HashMap<>();
//vs
var idToNameMap = new HashMap<Integer, String>();

var message = "Hello, Java 10";
assertTrue(message instance of String);
```

## Java 11

**New helpful String methods:** .*isBlank*() .*lines*() .*strip*() .*stripLeading*() .*stripTrailing*()

```
String multilineString = "I love \n \n Java 11 \n a lot.";
List<String> lines = multilineString.lines()
  .filter(line -> !line.isBlank())
  .map(String::strip)
  .collect(Collectors.toList());
  
assertThat(lines).containsExactly("I love", "Java 11", "a lot.");
```

***.toArray()***: simpler collection conversion to an array. Why is this useful? Arrays are of a fixed size, have better performance (although cost more memory), and can hold either objects or primitives

```
List sampleList = Arrays.asList("Java", "Kotlin");
String[] sampleArray = sampleList.toArray(String[]::new);

assertThat(sampleArray).containsExactly("Java", "Kotlin");
```

***var now supported for lambda parameters***: more readable than explicit type definition; allows for type annotations within streams

```
List<String> sampleList = Arrays.asList("Java", "Kotlin");
String resultString = sampleList.stream()
  .map((@Nonnull var x) -> x.toUpperCase())
  .collect(Collectors.joining(", "));
  
assertThat(resultString).isEqualTo("JAVA, KOTLIN");
```

***Directly run java without javac compiling***: allows for single file source code, without the need for pre-compilation

```
$ javac HelloWorld.java
$ java HelloWorld 
Hello Java 8!
//vs
$ java HelloWorld.java
Hello Java 11!
```

## Java 12

**New String methods:** String *.indent()* and *.transform()*

```
String text = "Hello Ippon!\nThis is a Java 12 blog post.";

text = text.indent(4);
System.out.println(text);
//prints this (with an indent of 4 spaces)
    Hello Ippon!
    This is a Java 12 blog post.
```

```
String text = "Hello Ippon!\nThis is a Java 12 blog post.";

text = text.indent(-10);
System.out.println(text);
//prints this (with no indent)
Hello Ippon!
This is a Java 12 blog post.
```

```
String text = "Ippon";
String transformed = text.transform(value ->
      new StringBuilder(value).reverse().toString()

assertEquals("noppI", transformed);
```

**Files package .*mismatch()* static method**: will return -1 if two files are matching, or the index of the first differentiating byte; no more byte array comparisons!

```
Path filePath1 = Files.createTempFile("file1", ".txt");
Path filePath2 = Files.createTempFile("file2", ".txt");
Files.writeString(filePath1, "Java 12 Article");
Files.writeString(filePath2, "Java 12 Article");

long mismatch = Files.mismatch(filePath1, filePath2);
assertEquals(-1, mismatch);
```

***CompactNumberFormat***: convert numbers to strings based on patterns provided by a given locale

```
NumberFormat shortFormat = 
      NumberFormat.getCompactNumberInstance(new Locale("en", "US"), NumberFormat.Style.SHORT);
shortFormat.setMaximumFractionDigits(2);
assertEquals("2.59K", shortFormat.format(2592));

NumberFormat longFormat = 
      NumberFormat.getCompactNumberInstance(new Locale("en", "US"), NumberFormat.Style.LONG);
longFormat.setMaximumFractionDigits(2);
assertEquals("2.59 thousand", longFormat.format(2592));
```

## Java 13 and 14

**Improved switch expression concision**: we can now define multiple cases within a single line, without the need for breaks

```
boolean isTodayHoliday;
switch (day) {
    case "MONDAY":
    case "TUESDAY":
    case "WEDNESDAY":
    case "THURSDAY":
    case "FRIDAY":
        isTodayHoliday = false;
        break;
    case "SATURDAY":
    case "SUNDAY":
        isTodayHoliday = true;
        break;
    default:
        throw new IllegalArgumentException("What's a " + day);
}

//vs

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

More helpful and descriptive Null Pointer Exceptions. I can already hear you quietly saying to yourself, "Finally!"

```
int[] arr = null;
arr[0] = 1;
Exception in thread "main" java.lang.NullPointerException
at com.baeldung.MyClass.main(MyClass.java:27)

//vs

int[] arr = null;
arr[0] = 1;
java.lang.NullPointerException: Cannot store to int array because "a" is null
```

## Java 15

**Text blocks:** Now fully supported as a production ready feature

```
String html = """
              <html>
                    <body>
              		  <p>Hello World.</p>
        	    </body>
    	      </html>
    	      """;
```

```
String multiline = "A quick brown fox jumps over a lazy dog; the lazy dog howls loudly.";
//vs
String multiline = """
    A quick brown fox jumps over a lazy dog; \
    the lazy dog howls loudly.""";
```

**Sealed classes:** More control over and ability to be restrictive with inheritance; the below code will prevent any object other than Employee and Manager from ever extending Person

```
public abstract sealed class Person permits Employee, Manager {
//...
}

public final class Employee extends Person {}

public non-sealed class Manager extends Person {}

//the below will not throw a warning, even without 
//a final 'else' condition, as the compiler can infer 
//from the sealed class definition that all possibilities 
//have been exhausted

if (person instanceof Employee) {
    return ((Employee) person).getEmployeeId();
} 
else if (person instanceof Manager) {
    return ((Manager) person).getSupervisorId();
}
```

## Java 16

**Records:** More concise definitions of immutable DTOs; compiler will also auto-provide *toString*, *equals*, and *hashCode* methods. (Note: while records were previewed in Java versions 14 and 15, Java 16 releases them as a production-ready feature)

```
//Immutable DTO Before
public class Person {
    private final String name;
    private final int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }
}

//vs Immutable DTO After

public record Person(String name, int age) {}
//and
public record Person(String name, int age) {
    public Person {
        if(age < 0) {
            throw new IllegalArgumentException("Age cannot be negative");
        }
    }
}
```

**Pattern matching:** Remove boilerplate code required for *instanceof* checks; you can now have pattern matching and conditionals within the same line of code. (Note: similar to Records, this was previewed in earlier versions, but is now a fully supported production-ready feature)

```
if (person instanceof Employee) {
    Employee employee = (Employee) person;
    Date hireDate = employee.getHireDate();
    //...
}

//vs

if (person instanceof Employee employee) {
    Date hireDate = employee.getHireDate();
    //...
}

//and

if (person instanceof Employee employee && employee.getYearsOfService() > 5) {
    //...
}
```

You probably noticed that these updates don't appear to include all that many changes. This is both because Java releases now occur every 6 months, and that they tend to include mostly under-the-hood upgrades. For a more in-depth look at the differences between Java's LTS and non-LTS releases, see: [https://blog.ippon.tech/comparing-java-lts-releases/](https://blog.ippon.tech/comparing-java-lts-releases/)

We hope that this introduction will allow for you to more quickly dive into post-Java 8 versions and use what they have to offer in your daily work. For more information regarding non-coding-related changes made in these updates, be sure to check out Oracle's very helpful JDK release notes library. Thanks for reading!

### **Sources**

Oracle  
Baeldung  
Ippon Blog  
Journal Dev  
Info World  
Educba  
Javat Point  
Plural Sight

## Related Articles

##### [![Introduction to Karate](https://blog.ippon.tech/hs-fs/hubfs/Imported_Blog_Media/karate-3961079_1280-3.jpg?width=520&height=294&name=karate-3961079_1280-3.jpg) cucumber • September 1, 2021 Introduction to Karate 6 min read](https://blog.ippon.tech/introduction-to-karate)

### Comments

### Subscribe to Our Blog!

Stay informed with the latest insights and updates by signing up for our weekly blog newsletter – delivered straight to your inbox!

[Back to blog homepage »](https://blog.ippon.tech/)

![IpponLogoKleinBlue](https://blog.ippon.tech/hs-fs/hubfs/IpponLogoKleinBlue.png?width=247&height=73&name=IpponLogoKleinBlue.png "IpponLogoKleinBlue")

Ippon is a consulting and expertise firm, who is convinced that technology is a source of progress for society. We help our clients leverage their digital assets to design an appropriate strategy and deploy their transformation roadmap at scale.

#### Navigation

- [Home](https://ipponusa.com/)
- [About](https://ipponusa.com/about-us/)
- [Services](https://ipponusa.com/services/)
- [Blogs](https://blog.ippon.tech/?__hstc=223043268.1036d82247623b329dfefe4e92697801.1714729179243.1714729179243.1714729179243.1&__hssc=223043268.2.1714729179244&__hsfp=803678701)
- [eBooks](https://ipponusa.com/ebooks/)
- [The Data Pour](https://info.ippon.tech/the-data-pour?__hstc=223043268.1036d82247623b329dfefe4e92697801.1714729179243.1714729179243.1714729179243.1&__hssc=223043268.2.1714729179244&__hsfp=803678701)

[Contact Us](https://ipponusa.com/contact/)

[Join Us](https://ipponusa.com/careers/)

#### Services

- [Data & Analytics](https://ipponusa.com/service/data-analytics/)
- [Cloud Strategy](https://ipponusa.com/service/cloud-strategy/)
- [Artificial Intelligence](https://ipponusa.com/service/artificial-intelligence/)
- [Operating Model](https://ipponusa.com/service/operating-model/)
- [Platform Modernization](https://ipponusa.com/service/platform-moderization/)
- [Product Innovation](https://ipponusa.com/service/product-innovation/)

#### Ippon International

- [France](https://fr.ippon.tech/?__hstc=223043268.1036d82247623b329dfefe4e92697801.1714729179243.1714729179243.1714729179243.1&__hssc=223043268.2.1714729179244&__hsfp=803678701)
- [Australia](https://au.ippon.tech/?__hstc=223043268.1036d82247623b329dfefe4e92697801.1714729179243.1714729179243.1714729179243.1&__hssc=223043268.2.1714729179244&__hsfp=803678701)

- #### Contact
- Ippon Technologies  
  [3431 West Leigh Street Richmond, VA 23230, USA](https://maps.app.goo.gl/RySm6SAwZnsxeiLz9)
-  
- [(844) 477- 6687](tel:8444776687)
-  
- [Sales@ipponusa.com](mailto:Sales@ipponusa.com)

<https://www.facebook.com/IpponUSA/> <https://www.youtube.com/c/ipponusa> <https://www.linkedin.com/company/ippon-technology>

©Copyright 2024 Ippon USA. All Rights Reserved.   |   [Terms and Conditions](https://ipponusa.com/privacy-policy/)   |   [Privacy Policy](https://ipponusa.com/privacy-policy/)   |   [Website by Skol Marketing](https://skolmarketing.com/)

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Mike Mitchell",
    "url" : "https://blog.ippon.tech/author/mike-mitchell"
  },
  "dateModified" : "2024-01-25T17:40:26.015Z",
  "datePublished" : "2021-03-26T16:40:00.000Z",
  "headline" : "Java 16: An Introduction from a Java 8 Monogamist",
  "image" : [ "https://blog.ippon.tech/hubfs/Imported_Blog_Media/Java-16-_-An-Introduction-from-a-Java-8-Monogamist-3.png" ],
  "mainEntityOfPage" : {
    "@id" : "https://blog.ippon.tech/java-16-introduction",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://blog.ippon.tech/hubfs/logo_SVG.svg"
    },
    "name" : "Ippon Technologies"
  }
}
```