Covariant return types

After today’s lecture of “Effective Java” from Joshua Bloch, I can share some knowledge! Looking at the previous post about Recursive Builder Pattern, You may see interesting pattern – self() method. The idea is, to override self()from an abstract/superclass and change its return type to the current type. Current means, that it is the type of the child class, which overrides the method. Well, that is the simplified definition of covariant return types in JAVA.

Recursive Builder Pattern

How to mimic self keyword in JAVA? First, check out our tutorial about Recursive Builder Pattern to understand why it is even needed.

We all know how handy is the builder pattern. Stop. Maybe not all? Do not worry, builder pattern is well explained in “Design Patterns” from O’Reilly. You will get it in 10 mins. The most important reason why it is good to have a builder is to avoid numerous parameters being passed to the constructor. The builder pattern has many variations, but for the sake of this tutorial, we will use the simplest possible form – static inner class. Take a look:

“Understanding the Memory Usage of Your Application” by Oracle Learning Library

Great lesson about JAVA and JVM memory usage. Not our tutorial, but – we strongly recommend You to watch it. Released in 2013, still, time did not affect it much.  The structure of the whole lesson, the amount of important information, yet provided in a very convenient way makes it really good. Furthermore, we recommend You to prepare notes, as each minute is packed with tons of JAVA knowledge. The video touches the subject of efficient data handling, regarding different types of collections, briefly. You can also learn about the internal architecture of JVM 32/64 bits, native heap and more.

Enjoy! And thanks Oracle Learning Library for putting this gem online.

“From Java Code to Java Heap: Understanding the Memory Usage of Your Application” by Oracle Learning Library:

Source: https://www.youtube.com/watch?v=FLcXf9pO27w

Merge Sort Algorithm in JAVA

If You are interested in general purpose, common sorting algorithm, I do recommend You to take a look at merge sort algorithm. The type of this algorithm is, of course, divide and conquer. Briefly – You are going to take an input (list, array) and divide it into halves as many times as possible until You reach 1-element sublist. Then, You need to merge it again. After it finished, final output is the sorted input. Read more for the code example, visualization and full recipe. (..)