Moving Forward - Java 8 Lambdas (2014)

Java 8 Lambdas (2014)

Chapter 10. Moving Forward

In many ways, Java as a language has stood the test of time well. It’s still an incredibly popular platform and a good choice for developing enterprise business software. A vast array of open source libraries and frameworks have been developed, solving every problem from how to write a modular and complex web application (Spring) right down to getting basic date and time arithmetic right (Jodatime). The tooling in space from IDEs such as Eclipse and Intellij right through to build systems like gradle and maven is unrivaled.

Unfortunately, over the years Java has acquired a bit of a reputation as a staid development choice that has failed to evolve with the times, in part because it has been popular for a long period of time; familiarity breeds contempt. And of course, there have been genuine issues around the evolution of Java. The decision to maintain backward compatibility, despite its benefits, has complicated this.

Fortunately, the arrival of Java 8 signals not just an incremental improvement in the language but a step change in its development. Unlike Java 6 and 7, this release doesn’t equate to a few minor library improvements. I fully expect and hope that future releases of Java will continue the rapid pace of improvement seen with Java 8. That’s not just because I’ve enjoyed writing a book on the topic! I really do think that there is a long way to go in terms of improving the fundamental task of programming: making code easier to read, clarifying its intent, making it easier to write high-performance code. My only regret is that there isn’t enough space in this concluding chapter to detail the full potential of future releases.

We’re nearing the end of this book, but I hope we’re not nearing the end of your time with Java 8. I’ve covered a bunch of different ways you can use lambda expressions: better collections library code, data parallelism, simpler and cleaner code, and finally concurrency. I’ve explained the why, what, and how, but it is still up to you to put everything into practice. In this spirit, here is a series of open exercises to which there are no right and wrong answers. Undertaking them can help guide your ongoing learning experience:

§ Explain what lambda expressions are and why they should be of interest to another programmer. This could be a friend or a coworker.

§ Start a trial deployment of your work product on Java 8. If you’ve already got your unit tests running under the Jenkins CI system, then it’s very easy to run the same build under multiple Java versions.

§ Start refactoring a bit of legacy code in a real product to use streams and collectors. This could be an open source project you’re interested in or maybe even your work product if the trial deployment went well. If you aren’t ready to move wholesale, then perhaps prototyping things on a different branch is a good way to start.

§ Do you have any concurrency problems or large-scale data-processing code? If so, try to prototype a refactor in order to use either streams for data parallelism or some of the new concurrency features in RxJava or CompletableFuture.

§ Have a look at the design and architecture of a code base you know really well:

§ Could it be implemented better at a macro level?

§ Can you simplify the design?

§ Can you reduce the amount of code needed to implement a feature?

§ Can the code be made easier to read?