finner

finner

My travels with Modern Java in Action

As one of my New Year resolutions is to read more tech I’ve decided on an attempt to document my travels in Mannings Modern Java in Action

I have just started and currently reading the introductory sections which are generic. The book will take me through whats new in Java 8, 9, 10 & 11 with some of the main topics being lambdas, streams, functional & reactive programming.

Java release timeline relevant to the book.

  • Java 5 2004
  • Java 8 2014
  • Java 9 2017
  • Java 10 2018 (March)
  • Java 11 2018 (September)

As you can see, Java was slow to evolve between Java 5 and 8, a whole 10 years slow. So I guess I got lazy.
Java 8 is the first version of Java with functional programming capabilities.
As of today Java is almost at version 16. Oracle have been on a 6 month release cycle since Java 9. This means the Java community will have to keep up with the pace. This may also inject life back into the old language.

I have high expectations for this book and it has been given positive reviews. There is a lot of material.
With 2 years working experience already in Java 8 I should have a solid foundation to follow what this book will cover. I am hoping to fill in gaps and maybe deep dive in some areas.

So, let’s see how it goes.

Most Liked

finner

finner

Slap bang in the middle of Chapter 5 already which talks about the Stream API and lovin’ it …
… but I’m getting ahead of myself.

The big change for long time Java programmers is the jump to Java 8. Quite literally it is the ability switch from coding in OO to coding in FP. When written well, Java8 code looks quite different to its previous versions.
Here is a very simple example.

Pre Java 8

Using a for loop to iterate a list of String objects.
This is known as external iteration.

public String findWordInList(String wordToFind, List<String> words) {
   for (String word: words) {
       if (word.equals(wordToFind)) {
          return word; 
       }
   }
   return "";
}

Java 8

The same as above but using filter() & findFirst() from the StreamAPI and a lambda predicate. This is known as internal iteration.

public String findWordInList(String word, List<String>) {
   return words.stream()
      .filter(w -> w.equals(wordToFind))
      .findFirst()
      .orElse("");
}

The advantage of internal iteration is that the Stream library can choose a data representation and implementation of parallelism.

To use parallelism you just need to rewrite your code as follows:

public String findWordInList(String word, List<String>) {
   return words.parallelStream()
      .filter(w -> w.equals(wordToFind))
      .findFirst()
      .orElse("");
}

When I see a for statement in code at work these days I experience something akin to being asked to believe that Harry Potter is 14 years old in Harry Potter and the Deathly Hollows.

to be continued …

finner

finner

Totally agree @iPaul , there has to be general consensus between the developers in which style to adopt. What I am seeing at the moment where I work is the heavy use of the Stream API when working with collections. This gives the developer an API similar to FP patterns, such as map, flatMap, filter & reduce. This feels like a natural step towards a functional style without diving in at the deep end.
In my case, the project has 4 teams, 3 of which are external vendors and it is our team who are behind the curve and struggling with the new concepts. Adapting to the other teams code styles has been a struggle for us but already, for me at least, it has helped me a great deal. You have to swallow your pride when you do not know what you do not know.
So coming back to your point, we are actually the alienated team. We are still trying to catch up but at least now I know what I want my code to look like when I grow up :smiley:

But just to clarify, Java 8 is still fundamentally an OO language with some FP features. We are still writing and thinking in OO. But I am hoping with all these new features and practice I will be able to revisit FP languages like Clojure or Scala with more confidence and a deeper appreciation for the mindset.
One must be able to dream …

AstonJ

AstonJ

Nice one Finner!

I am sure your journal is going to provide interesting for a lot of people and I look forward to seeing your updates :nerd_face:

Where Next?

Popular Community topics Top

Rainer
My first contact with Erlang was about 2 years ago when I used RabbitMQ, which is written in Erlang, for my job. This made me curious and...
New
mafinar
Concurrent Data Processing in Elixir is now content complete and I finally found the time I’ve been looking for to dedicate behind readin...
New
mafinar
I am going to dump my thoughts, methods, codes, experiences and rants while learning OCaml into this thread. This is probably the 5th or...
New
Maartz
The very first time I’ve seen a line of Elixir I was in awe. Coming from Ruby the syntax was familiar. But I wanted to know what was thi...
New
mafinar
TL;DR I am reading “Domain Modeling Made Functional” and discussing and keeping a journal of what I learned from it, any co-readers welco...
New
ohm
I would love to begin a book club with Mike Amundsen’s (@mamund) book Design and Build Great Web APIs. It seems that building new syste...
New
TwistingTwists
This is my Journal for readings on Designing Elixir Systems with OTP. Will post chapter 01 tomorrow! Stay tuned!
New
AstonJ
With AI set to play a big role in our industry Elixir users are lucky to have Nx, so we’re running our Nx related book club on Genetic Al...
New
PragmaticBookshelf
When the pandemic, heart disease, and personal tragedy threatened to steal everything the Tates spent years building, they found hope, he...
New
TomMahon
How did a sleepy valley become the epicenter of the technological world as we know it? In the 40th Anniversary Edition of my book, “Charg...
New

Other popular topics Top

wolf4earth
@AstonJ prompted me to open this topic after I mentioned in the lockdown thread how I started to do a lot more for my fitness. https://f...
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File &gt; New Rule: And select Deny, O...
New
New
New
PragmaticBookshelf
Author Spotlight: Peter Ullrich @PJUllrich Data is at the core of every business, but it is useless if nobody can access and analyze ...
New
Fl4m3Ph03n1x
Background Lately I am in a quest to find a good quality TTS ai generation tool to run locally in order to create audio for some videos I...
New