Not stagnation, but regression of Java. Where modern Java 17 loses to Java 8

Marian Čaikovski
4 min readDec 3, 2021

Most simple demonstration using the code from Java API

Although few recent features might produce an illusion of Java evolution, Java language has not changed much since Java 8.

There are improvements in some built-in classes, but overall improvements in Java performance are not easy to detect.

What if there is a clear degradation in the modern Java performance?

Computational tasks in Java

Java is not as performant as Python, but is more convenient to use for calculations. Let’s make simplest possible experiments to see what happened to computational capacity of the modern Java.

The standard calculation known by anyone is calculation of Fibonacci numbers. In Java it can be done synchronously and even faster through parallel computation. There is even a dedicated class RecursiveTask, so the code is not as complicated as in JavaScript or Python. I try both ways to calculate Fibonacci numbers.

In my code I reuse the sample code from RecursiveTask. The API recommends not to start new tasks for numbers before position 10.

public class Main {static long fibonacci(long n) {
if (n <= 1) {
return n;
} else {
return fibonacci(n - 1) + fibonacci(n - 2);
}
}
class Fibonacci extends RecursiveTask<Long> {final long n;Fibonacci(long n) {
this.n = n;
}
protected Long compute() {
if (n <= 10) {
return fibonacci(n);
}
Fibonacci f1 = new Fibonacci(n - 1);
f1.fork();
Fibonacci f2 = new Fibonacci(n - 2);
return f2.compute() + f1.join();
}
}
Map<String, List<Long>> results = new HashMap<>();void execute(IntFunction<Long> code, int num, String name) {
long start = System.currentTimeMillis();
long r = code.apply(num);
long time = System.currentTimeMillis() - start;
results.computeIfAbsent(name, k -> new LinkedList<>()).add(time);
System.out.println(r + " in " + time + " ms");
}
void run(int num, int repeats) {…

--

--

Marian Čaikovski

Java, JavaScript and SQL developer. Interested in data collection and visualization.