DEV Community

Jean-Michel 🕵🏻‍♂️ Fayard
Jean-Michel 🕵🏻‍♂️ Fayard

Posted on • Edited on

Practice what's new in Java

You have read about the new features that have arrived in Java world but didn't have the opportunity to learn them yet? I have a challenge for you.

What's new in Java world

I won't describe what's new in Java world because this article is hard to surpass:

How to practice it?

But reading about what's new is not enough.

Alas, your project at work may be stuck with Java 11 or even Java 8.

In a previous article, I shared the tip that if you want to learn more about a programming language - or here its evolution - you should write unit tests about them.

This is exactly what I've started to do here:

GitHub logo jmfayard / playground-modern-java

Life is too short for Java 8

Playground for Modern Java

Because life is too short for Java 8/11

Requirements

Install via IntelliJ the latest Java SDK installed. As of 2024, it's Java 23

Usage

./gradlew test

What's inside ?

Everything is located inside src/test so that the code is self-tested

In the test/main/modernjava package:

  • Records
  • Lombok
  • Streams
  • var type inference
  • new Collections methods
  • Virtual Threads
  • Markdown comments
  • SmartCasts
  • Optionals
  • Default methods in interfaces
  • Pattern Matching for switch
  • Multiline strings
  • ...

In the test/main/katas

  • binary trees
  • algorithms
  • ...

In the sql folder

  • the schema and a seed for a library, allowing to practice SQL



If you look in the src/main/test folder, you will find snippets like this one:

public class RecordJava14 {
    record Employee (String name, int age, String department) {
    }

    @Test
    void createRecord() {
        var patrik = new Employee("Patrick", 36, "Marketing");
        assertThat(patrik.toString()).isEqualTo("Employee[name=Patrick, age=36, department=Marketing]");
        assertThat(patrik.name()).isEqualTo("Patrick");

        var clone = new Employee("Patrick", 36, "Marketing");
        assertThat(clone).isEqualTo(patrik);
    }
}

Enter fullscreen mode Exit fullscreen mode

This gives you a view of the features of modern Java that are already covered:

java16-playground_–_README_md__java16-playground_

Your challenge

If you want to learn more about modern Java, I challenge you to pick one of the remaining issues and implement it.

https://github.com/jmfayard/java16-playground/issues

(of course, you can also create a new issue)

Issues_·_jmfayard_java16-playground

Top comments (0)