Modern Java in Action 7 - notes about the module system
Chapter 14 is “The Java Module System” and this post is a note that helps to refresh my knowledge about Java Module System.
Chapter 14 is “The Java Module System” and this post is a note that helps to refresh my knowledge about Java Module System.
Od jakiegoś czasu, dość nieregularnie, publikuję moje (dość nieporządne) notatki z lektury “Modern Java In Action” (2018) (Raoul-Gabriel Urma, Alan Mycroft, Mario Fusco).
Listę notatek umieściłam w serii Modern Java in Action - po angielsku, ponieważ łatwiej mi pisać po angelsku kiedy czytam po angielsku 😂
Jeśli chcecie rzucić okiem na inne wpisy po angielsku, wejdźcie na angielską wersję bloga.
Miłego czytania!
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.
//static <E> List<E> of(E... elements)
static <E> List<E> of(E e1)
static <E> List<E> of(E e1, E e2)
static <E> List<E> of(E e1, E e2, E e3)
static <E> List<E> of(E e1, E e2, E e3, E e4)
static <E> List<E> of(E e1, E e2, E e3, E e4, E e5)
// ... other variants
static <E> Set<E> of(E e1)
static <E> Set<E> of(E e1, E e2)
//... etc, other variants up to 10
static <K, V> Map<E> of(K k1, V v1)
static <K, V> Map<E> of(K k1, V v1, K k2, V v2)
// ... etc, variants up to 10 pairs
// or with entries
import static java.util.Map.entry;
static <K, V> Map<E> ofEntries(entry(k1, v1), entry(k2, v2))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:
System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "12");Stream.iterate(1L, i -> i + 1).limit(N)LongStream.rangeClosed(1, N)| class | composability |
|---|---|
| ArrayList | 😄 Excellent |
| IntStream.range | 😄 Excellent |
| HashSet | 😐 Good |
| TreeSet | 😐 God |
| LinkedList | 😭 Bad |
| Stream.iterate | 😭 Bad |
protected abstract R compute();if (task is small enough or no longer divisible) {
compute task sequentially
} else {
split task in two subtasks
call this method recursively possibly further splitting each subtask
wait for the completion of all subtasks
combine the results of each subtask
}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.
This post starts Java 8 refresher series - I will keep here my short notes during reading “Modern Java in Action”.
Szybka aktualizacja:
pdf (wygenerowane w Javie - patrz kamchy/bajki) są już dostępne na moim bloguhtml (wygenerowane w TypeScript + deno - patrz kamchy/stories)Miłego czytania! 😂
Ostatnio prowadzę zajmujące rozmowy z moimi nastolatkami. Filozofujemy na wiele różnych tematów. Jednym z ostatnich rozważanych przez nas zagadnień było myślenie krytyczne.
Podczas porannego pieczenia bułeczek posłuchałam wykładu dotyczącego umiejętności krytycznego myślenia Study skills Workshop 05 - Critical Thinking Skills i pomyślałam, że warto się na chwilę zatrzymać nad problemem: co to jest myślenie krytyczne? Jak je praktykować?
Ten wpis to zbiór luźnych notatek z wspomnianego wykładu oraz kilka moich refleksji. Znajdują się tu: