Sitemap

JAVA 8 to 18

2 min readSep 24, 2023

--

Changes from JAVA 8 to 18

Coding style changes

  1. Automatic type inference: It is not required to define the exact class for the variable
    - Example: var url = new URL(“dummy.com”);
  2. Simpler switch statements
    - Can omit default if the switches are exhaustive
    - Can switch on variable datatype
    - Can test for null inside switch statement
  3. Guarded patterns: Can combine multiple conditions
    - Example: case String s when s.size()==1 -> evaluate
  4. Text blocks
  5. Record classes: Final classes with only constructor for carrying around data
  6. 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
  7. Sealed classes: Restrict the use of classes or interfaces by restricting the classes who can extend, implement them

Get Abhishek Kumar Yadav’s stories in your inbox

Join Medium for free to get updates from this writer.

JDK changes

  1. Null Pointer Exceptions: Pinpoints the variable which gives NPE
  2. 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
  3. 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
  4. Java Packager( jpackage): Can create native application package( .exe, .deb, .dmg)
  5. Java Shell( jshell): Type and execute java syntax
  6. Launch single-file source code programs in a single step
    - Example: java HelloWorld.java
  7. Flight Recorder: Allows monitoring of Garbage collection, JIT compilation, locks, class loading, events
  8. Async, non-blocking http requests
  9. Initialize collections with data in single line
    - Example: Set.of( vars…);
  10. Foreign functions and Memory API: Call native libraries and read native data outside java heap
  11. Deserialization Filtering: Can filter objects before deserializing them into classes
  12. Virtual Threads
    -
    A virtual thread still runs code on an OS thread. However, when code running in a virtual thread calls a blocking I/O operation, the Java runtime suspends the virtual thread until it can be resumed. The OS thread associated with the suspended virtual thread is now free to perform operations for other virtual threads.
    -
    Async can increase requests per second very much but is hard to debug and thus has high maintainenece cost
    - Virtual thread will work on top of platform thread, and multiple virtual threads will share one platform thread
    - Virtual threads should be used whenever there can be a blocking operation
    - Virtual threads should not run in memory operations
    - We should not do IO operations in parallel streams
    - We should not run parallel streams in virtual threads
    - Native operations pin virtual threads on top of platform threads, making it async, therefore it behaves the same as a normal thread

--

--