I don't get it. The first example in JS vs Java looks very similar. Now all those other code blocks, they certainly have more going on but idk how that compares to JS. And to answer the questions: A completable future is something that in the future may complete. I think that's self explanatory. A promise seems equally vague. Boilerplate looks the same. JS is just a function, Java they put a class around it. Java req…
Yeah that first example is rather poor. And it uses the word boilerpate to seemingly refer to the stuff unrelated to the async code (class declaration, exception handling, main method).
I don't use Java async much, but I guess if you have a utility method named "setTimeout" than the example can simply be:
public CompletableFuture fetchData() {
return setTimeout(() -> "Data Fetched", 10000);
}
public void loadData() {
fetchData().thenAccept(System.out::println);
}
Which is simpler or equivalent to the JS example.