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:

Popular Community topics Top

Tommy
So I have enough money to last a year. Realistically I’m still going to have to work part time painting. I’m so done with it though! I h...
New
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
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
TwistingTwists
This is my Journal for readings on Designing Elixir Systems with OTP. Will post chapter 01 tomorrow! Stay tuned!
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
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
Fl4m3Ph03n1x
Learning Domain-Driven Design Building software is harder than ever. As a developer, you not only have to chase ever-changing technologic...
New

Other popular topics Top

axelson
I’ve been really enjoying obsidian.md: It is very snappy (even though it is based on Electron). I love that it is all local by defaul...
New
AstonJ
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
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
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
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
First poster: joeb
The File System Access API with Origin Private File System. WebKit supports new API that makes it possible for web apps to create, open,...
New
Help
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
New
PragmaticBookshelf
Author Spotlight: VM Brasseur @vmbrasseur We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New