---
# System prepended metadata

title: JAVA 8 to 21

---

# JAVA 8 to 18

## Coding style changes

- Automatic type inference: It is not required to define the exact class for the variable
    - Example: ```var url = new URL("dummy.com");```
- Simpler switch statements
    - Can omit default if the switches are exhaustive
    - Can switch on variable datatype
    - Can test for null inside switch statement
    - Guarded patterns: Can combine multiple conditions
        - Example: ```case String s when s.size()==1 -> evaluate 
- Text blocks
- Record classes: Final classes with only contructor for carrying around data
- Pattern matching using ```instanceof```
    - ```obj instanceof string s```: Checks if obj is of type string, creates a new variable s and casts obj into s
- Sealed classes: Restrict the use of classes or interfaces by restricting the classes who can extend, implement them

## JDK changes

- Null Pointer Exceptions: Pinpoints the variable which gives NPE
- Java Linker( jlink)
    - Creates "Custom Runtime"
    - Allows us to use the subset of java modules which are required by the application
    - Reduces file size of the compiled file
- Java Dependency Analyzer( jdep)
    - Shows package and class level dependencies of JAVA class files
    - The result can be used in jlink to reduce the number of dependecies
- Java Packager( jpackage)
    - Can create native application package( .exe, .deb, .dmg)
- Java Shell( jshell): Type and execute java syntax
- Launch single-file source code programs in a single step
    - Example: ```java HelloWorld.java```
- Flight Recorder
    - Allows monitoring of Garbage collection, JIT compilation, locks, class loading, events
- Async, non-blocking http requests
- Initialize collections with data in single line
    - Example: ```Set.of( vars...);```
- Foreign functions and Memory API: Call native libraries and read native data outside java heap
- Deserialization Filtering: Can filter objects before deserializing them into classes