Skip to content

On September 19, 2023, major launch events celebrated the release of Java 21

Notifications You must be signed in to change notification settings

achhibi/java21-new-features

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Testing Java 21 New Features

This project contains examples of code to test the new features of Java 21 with sample Main class.

Features tested

  • InstanceMainMethodLauncher
  • RecordPattern
  • SequencedCollection
  • StringTemplate
  • UnnamedClass
  • ScopedValueUsageTest

Examples

Each feature is represented by a java file containing one or more examples of code.

UnnamedClass


/**
**  java --enable-preview --source 21 UnnamedClass.java
**/
static String staticField = "I'm static field";
String istanceField = "I'm instance field";
private String privateInstanceField = "I'm private instance field";

void main() {
   System.out.printf("%s%n", staticField);
   System.out.printf("%s%n", istanceField);
   System.out.printf("%s%n", privateInstanceField);
}

StringTemplate

public class StringTemplateSample {
public static void main(String[] args) {
var productName = "IPhone 15";
var productPrice = 1129.99;
var productAvailable = true;

        String productInfo = STR."""
        Product: \{productName} Price: \{productPrice} Availability: \{productAvailable ? "In Stock" : "Out of Stock"}
        """;

        System.out.println(productInfo);

    }
}

About

On September 19, 2023, major launch events celebrated the release of Java 21

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages