Posts From Category: versions

Changes in Java12

Switch expression

It has been revamped to act as an expression. It removes the usage of break.

switch(day) {
  case SATURDAY, SUNDAY -> System.out.println(1);
  case TUESDAY, FRIDAY -> System.out.println(2);
  case THURSDAY, MONDAY -> System.out.println(3);
  case WEDNESDAY -> System.out.println(4);
}

Read More

From Java8 to Java11

This is a list of the changes at Java’s API I found interesting or that I may use frecuently. Not all the changes from Java9, 10 & 11 are listed here.

Java 9

Java REPL (JShell)

It stands for Java Shell. It’s used to easily execute and test any Java construction like a class, interface, enum, etc.

Module System

The way we deploy Java-Based applications using jars has a lot of limitations & drawbacks. Some of these are: The JRE & JDK are too big; JAR files are too big to use in small devices and applications; There’s no strong encapsulation, public is open to everyone.

The new Module System introduces new features to avoid all this. More information here.

Factory Methods for Inmutable Collections (List, Map, Set & Map.Entry)

(I’ll use Lists as an example in this file, but this is valid for Maps and Sets too)

Until Java8 we could use Collections.unmodifiableList() to achieve this, but this is really verbose. Now we can do the same with

List inmutableList = List.of("bla", "ble", "bli");

Read More