Java 10 features with examples

Category : Java | Sub Category : Java 10 features | By Prasad Bonam Last updated: 2023-08-09 07:43:47 Viewed : 303


here are some Java 10 features with examples to help illustrate their usage:

  1. Local-Variable Type Inference (var):

    java
    var name = "John"; // Inferred as String var numbers = List.of(1, 2, 3); // Inferred as List<Integer>
  2. Application Class-Data Sharing:

    bash
    # Create an archive of class data $ java -Xshare:dump # Use the archived class data at startup $ java -Xshare:on -jar MyApp.jar
  3. Time-Based Release Versioning:

    bash
    $ java -version openjdk version "10" 2018-03-20
  4. Parallel Full GC for G1:

    bash
    $ java -XX:+UseG1GC -XX:+UseParallelGC -jar MyApp.jar
  5. Thread-Local Handshakes:

    java
    Thread.currentThread().registerOnThreadLocalHandshake(() -> { // Code to execute during the handshake System.out.println("Thread-local handshake executed."); });
  6. Additional Unicode Language-Tag Extensions:

    java
    Locale locale = Locale.forLanguageTag("en-u-ca-chinese"); System.out.println(locale.getUnicodeLocaleAttributes()); // Output: [chinese]
  7. Heap Allocation on Alternative Memory Devices:

    bash
    $ java -XX:AllocateHeapAt=non-volatile-memory -jar MyApp.jar
  8. Thread-Local Random Number Generator:

    java
    int randomInt = ThreadLocalRandom.current().nextInt(1, 100);

Please note that while these examples provide a basic understanding of the Java 10 features, some features may require specific runtime options or additional configuration. For comprehensive details and advanced usage, refer to the official Java documentation and resources for Java 10.

Search
Related Articles

Leave a Comment: