API - more than it seems
In this article I’m going to explore what an API is, why we might want to change it, how to do it and how to do it safely.
In this article I’m going to explore what an API is, why we might want to change it, how to do it and how to do it safely.
CPUs like the Intel i7-6900K have multiple hardware threads per core, so the CPU can execute useful instructions even for short delays such as a cache miss.
Chapter 14 is “The Java Module System” and this post is a note that helps to refresh my knowledge about Java Module System.
java.util.Datejava.util.Calendarjava.util.DateFormatDate, not Calendar
Classes and interfaces in a new package java.time (modelled after Joda Time classes) provide better way of thinking about and working with time concepts.
The most important classess in this package are: LocalDate, LocalTime, LocalDateTime, Instant, Duration, and Period .
Reasons why null is problematic:
Three static methods may create instances of Optional:
Here are three simple refactorings that can be used if you want to migrate your codebase to Java 8 (or higher). You may want to do so for many different reasons (readability, conciseness, code reuse, security).
Recommended paper about automatic refactoing of pre-Java 8 codebases into Java8: Lambda Refactoring
this and super (in lambda this refers to enclosing class, in inner class - to itself)Question: when to introduce functional interfaces?
Collection classes got a few nice additions.
They create immutable collection (if you try to add/remove elements, you get UnsupportedOperationException. There is no varargs variant - this variant would require additional array allocation, which non-varargs variants don’t have.
There are overloads from 1 to 10 elements.
|
|
On a list you can use removeIf and replaceAll
Second chapter shows how parallellization works with streams; explains what fork-join pool is (which is used by streams framework underneath), what data structures are decomposable, how to create your own spliterator for more effective splitting of source stream for parallel processing.
parallel() in a chain of stream operationsRuntime.getRuntime().available-Processors() number of threads by default, but you can change it by specifying java.util.concurrent.ForkJoinPool.common.parallelism system property:
|
|
|
|
|
|
| class | composability |
|---|---|
| ArrayList | 😄 Excellent |
| IntStream.range | 😄 Excellent |
| HashSet | 😐 Good |
| TreeSet | 😐 God |
| LinkedList | 😭 Bad |
| Stream.iterate | 😭 Bad |
protected abstract R compute();
|
|
getSurplusQueuedTaskCount() is used for the criteria)Important You don’t have to use fork-join if your datastructure is decomposable; you just use parallel data streams. Automatic way of traversing a source and splitting it is “spliterator” - the interface which standard collections implement in the default implementation.