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

mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New
RobertKielty
My overall initial first impressions of this book are very good. I will document my local spacemacs setup to as I work through the book.
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
ggarnier
In Aborting Multiple Fetch Requests with One Signal section, the code in abort/abort_ex09.js doesn’t show the downloaded images until Pro...
New
rgerardi
Hello all. Creating this space here for general discussion and chat about Powerful Command-Line Applications In Go In particular, we ca...
New
adamaiken89
Anyone is interested in a classical textbook for algorithms can go and check that.
New
AstonJ
With Phoenix and LiveView having recently had a fairly major release, and Programming Phoenix LiveView being updated too, we thought it w...
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

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1023 17214 380
New
AstonJ
SpaceVim seems to be gaining in features and popularity and I just wondered how it compares with SpaceMacs in 2020 - anyone have any thou...
New
AstonJ
There’s a whole world of custom keycaps out there that I didn’t know existed! Check out all of our Keycaps threads here: https://forum....
New
AstonJ
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first: asdf plugin-upd...
New
Exadra37
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New
DevotionGeo
The V Programming Language Simple language for building maintainable programs V is already mentioned couple of times in the forum, but I...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1139 25652 757
New
AstonJ
Biggest jackpot ever apparently! :upside_down_face: I don’t (usually) gamble/play the lottery, but working on a program to predict the...
New
AstonJ
We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New
New