Released on March 20, 2018.
- var keyword is introduced in Java 10.
- We can use var keyword only for local variables.
- Allows us to declare a variable without specifying the type.
- Type inference : compiler infers the type of the variable based on the value.
for (var club : List.of("Barcelona", "Real Madrid", "Atletico Madrid")) {
System.out.println(club);
}Optional<String> optional = Optional.of("value");
optional.orElseThrow(IllegalStateException::new);
// or
optional.orElseThrow(() -> new IllegalStateException("exception message"));copyOf()
The List.copyOf, Set.copyOf, and Map.copyOf factory methods allow creating an immutable copy of a collection (List, Set, or Map).
List<String> players = List.copyOf(Arrays.asList("Messi", "Ronaldo", "Neymar"));
Map<String, Integer> players = Map.copyOf(Map.of("Messi", 10, "Ronaldo", 7, "Neymar", 10));- Java 10 introduced a new Garbage Collector (GC) interface, which is designed to provide a more flexible and extensible GC framework. The new GC interface allows for the creation of custom GC algorithms, which can be plugged into the JVM.
void initialize(): This method is called when the GC is first created, and it can be used to perform any necessary initialization.
void notifyLowMemory(): This method is called when the JVM detects low memory conditions.
void recordGCEnd(): This method is called when a GC cycle ends, and it can be used to record information about the GC cycle.