## Versions
- Java 5
- [[Java 8 Features]]
- [[Java 13 Features]]
- Java 17
- Java 19
## Java 8
Codebases can get stuck in Java 8 for certain reasons:
- Build tools (Maven, Gradle, etc) and libraries had initial bugs
- Licensing issues with Oracle
- Up to 8, it was fine
- Then in 2019 Oracle made it paid
- Now it's not an issue anymore
- Some only use LTS builds
Also got a slew of new enhancements in [[Java 8 Features]]
### Lambda
```java
// old code
Runnable runnable = new Runnable(){
@Override
public void run(){
System.out.println("Hello world !");
}
};
// new code with lambdas
Runnable runnable = () -> System.out.println("Hello world two!");
```
### Collections & Streams
Previously would have to use for loops, but now can do functional programming like
```java
list.stream()
.filter(name -> name.startsWith("f"))
.map(String::toUpperCase)
.sorted()
.forEach(System.out::println);
```
### Functional Interfaces
As also talked about [[Java 8 Features#Functional Interfaces]], they are interfaces with one static method which allows for functional programming.
- Runnable Interface
- Comparable Interface
- Consumer Interface
- Predicate Interface
- Function Interface
- Supplier Interface
#### andThen()
`.andThen()` allows developers to compose/chain two Consumers such that one will be executed after another.
```java
// Print list of integers
Consumer<List<Integer>> display = list -> list.stream().forEach(a -> System.out.println(a + " "));
// Double each element in a list of integers
Consumer<List<Integer>> doubleElements = list -> {
for (int i = 0; i < list.size(); i++) {
list.set(i, 2 * list.get(i));
}
};
// setup
List<Integer> myList = new ArrayList();
myList.add(1);
myList.add(2);
myList.add(3);
doubleElements.andThen(display).accept(myList);
```
### Predicate Interface
Commonly used for filtering operations in streams.
```java
Predicate<Integer> isMinor = a -> (a < 18);
System.out.println(isMinor(10));
```
They can be chained too
```java
Predicate<Integer> canSmoke = a -> (a >= 18);
Predicate<Integer> canDrink = a -> (a >= 21);
boolean canSmokeAndDrink = canDrink.and(canSmoke).test(22);
```
Common functions include;
- `isEqual(Object targetObject)`: returns boolean if two arguments are equal according to `Object.equals(obj1, obj2)`
- `and(Predicate other)`: short-circuiting logical *AND*
- `negate()`
- `or(Predicate other)`
- `test(T t)`: evaluates predicate on argument
### Java Time API
### Optional Class
### Method References
### Stream API
### Base64 Encode Decode
### Concurrency Enhancements
### Default Methods
### Type Annotations
### Comparable and Comparator
### IO Enhancements
---
## Java Distributions
### OpenJDK
The single-source of truth, the living codebase for Java. Oracle stops support for previous major versions once a new major version is released
### OracleJDK
Oracle is a vendor that builds Java from source code with a handful of changes/additions. It re-opened OracleJDK with version 17.
### Temurin Aka AdoptOpenJDK
Amazon, Microsoft, Pivotal, Redhat, and others collaborated to maintain Eclipse Adoptium, as another vendored version of Java.
### Amazon, Azul, SAP
These cloud providers also build and vendor their own versions of OpenJDK for their own VMs.
## Features from 8 to 20
## References
- [Guide to Java Versions and Features - Marco Behler](https://www.marcobehler.com/guides/a-guide-to-java-versions-and-features)
- [[Java MOC]]