Code Monkey home page Code Monkey logo

java-new-features's Introduction

Java new features

Java 8 (LTS)

  • Introduction of functional programming
  • Functional Interfaces
    • Consumer
    • BiConsumer
    • Supplier
    • Function
    • BiFunction
    • Predicate
    • BiPredicate
  • Interface
    • default method
    • static method
  • Stream API
    • stream()
    • parallelStream()
    • filter()
    • map()
    • forEach()
    • collect()
      • Collectors
        • toList()
        • toMap()
        • toSet()
        • groupingBy()
        • mapping()
        • joining()
  • Lambda Functions
  • Enhancements in Date/Time API
  • StringJoiner
  • String
    • join()

Java 9

  • private method inside Interface
  • effective final with try-with-resource -> resource as dependency can be passed as an argument in try(resource). No need to say try(Resource resource = new Resource)
  • variable with name underscore ( _ ) not allowed now
  • String
    • chars()
    • codePoints()
  • Stream
    • takeWhile(Predicate) -> It is like door open now and close in future
    • dropWhile(Predicate) -> It is like door close now and open in future
  • IntStream iterate()
    • with bounds
    • without bounds
  • Optional
    • ifPresentOrElse() -> It is new method to get Optional value
    • or()
    • stream()
  • Collectors
    • filtering()
    • flatMapping()
  • CompletableFuture
    • completeOnTimeout()
    • orTimeout()
  • List.of(), Set.of(), Map.of() methods to create immutable collections
  • Annonymous inner class with diamond <> operator
  • JShell -> REPL(Read Evaluate Print Loop) for java
  • JPMS (Java Platform Module System)
    • Types of modules
      • unnamed modules
      • automatic modules
      • named modules
    • jdeps
    • jmods
    • Modular Jar
    • Module Path
    • Module Declaration (module-info.java)
      • module (modulename){}
      • requires [static] [transitive] (module)
      • exports (package) [to] [module]
      • opens (package) [to] [module]
      • open module (moduelname) {}
      • provides (service) with (implementation)
      • uses (service)
    • Module Descriptor (module-info.class)
    • jdeps -jdkinternals [jar] (command to validate java internal api usage in jar)
  • Java Linker
    • jlink

Java 10

  • local variable type inference using var
    • var can't be used as method parameter and return type.
    • var can't be used as class level attributes
    • null can't be assigned to var
  • Optional
    • orElseThrow()
  • Collectors
    • toUnmodifiableList()
    • toUnmodifiableSet()
    • toUnmodifiableMap()
  • List.copyOf(), Set.copyOf() and Map.copyOf() methods

Java 11 (LTS)

  • var for lambda local variables
  • Optional.empty()
  • Files
    • readString(Path)
    • writeString(Path)
  • Predicate
    • not()
  • String
    • repeat(int) - Repeats the String as many times as provided by the int parameter
    • lines() - Uses a Spliterator to lazily provide lines from the source string
    • isBlank() - Indicates if the String is empty or contains only white space characters
    • stripLeading() - Removes the white space from the beginning
    • stripTrailing() - Removes the white space from the end
    • strip() - Removes the white space from both, beginning and the end of string

Java 12

  • Switch Expressions (Preview)
  • Collectors
    • teeing()
  • String
    • indent()
    • transform()

Java 13

  • Text Block (Preview)
    • multi line strings with """ --------- """
    • No need to escape
    • Smart Indentations
    • Trailing space handling
    • New escapes
      • \
      • \s
    • formating
      • replace(), replaceAll()
      • String.format()
  • Switch Expressions (Second Preview)

Java 14

  • Switch Expressions (Live)
  • Java Records (Preview)
    • data classes
    • By default record is final and all properties are final (Immutable)
    • Implements interfaces but can't extends classes
    • No default constructor
    • no setter method available
    • toString() method avaialble by default
    • Adding a canonical constructors
    • Adding methods
    • Adding local records inside function
  • Pattern Matching for instanceof (Preview)
  • Helpful NullPointerExceptions (-XX:+ShowCodeDetailsInExceptionMessages)
  • Text Block (Second Preview)

Java 15

  • Text Block (Live)
  • Sealed classes (Preview)
  • Local Class, Interface, Enum and Record (Preview)
  • Pattern Matching for instanceOf (Second Preview)
  • Java Records (Second Preview)
    • We can use annotations on top of Record
    • We can implement sealed interface

Java 16

  • Java Records (Live)
  • Add InvocationHandler::invokeDefault Method for Proxy's Default Method Support
  • Stream.toList()
  • Pattern Matching for instanceOf (Live)
  • Sealed classes (Second Preview)
  • Find Period-of-day using DateTimeFormatter.ofPattern("B").format(LocalDateTime.now())

Java 17 (LTS)

  • Pattern Matching for switch expressions (Preview)
  • Sealed classes (Live)
  • Strognly Encapsulate JDK Internals
  • Removal of experimental Java based ahead-of-time (AOT) and just-in-time (JIT) compiler.
  • Deprecate the Security Manager for removal

Java 18

  • UTF-8 by default in all java apis
  • Code Snippets in Java Documentation
    • {@snippet : final SnippetExample instance = SnippetExample.newInstance(); // @highlight substring="newInstance" instance.processIt(); }
  • Minimal web server
    • jwebserver
    • Supports only HTTP protocol
    • Serve only static contents
    • Serve static content from specific folder
  • Pattern Matching for switch expressions (Second Preview)
    • Guarded Pattern
    • Null matching
  • Deprecate the finalization for removal

Java 19

  • Pattern Matching for switch expressions (Third Preview)
switch (obj) {
case String s && s.length() > 5 -> System.out.println(s.toUpperCase());
case String s                   -> System.out.println(s.toLowerCase());

case Integer i                  -> System.out.println(i * i);

default -> {}
}

above code can be written like this

switch (obj) {
case String s when s.length() > 5 -> System.out.println(s.toUpperCase());
case String s                     -> System.out.println(s.toLowerCase());

case Integer i                    -> System.out.println(i * i);

default -> {}
}
  • Record Patterns (Preview)
  • Virtual Threads (Preview)

References

java-new-features's People

Contributors

javamultiplex avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.