Skip to main content

Java 8: It’s a Whole New Java

  • Chapter
  • First Online:
Java Closures and Lambda
  • 2742 Accesses

Abstract

This book is about lambdas (closures) in Java 8. More than that, though, it’s about the new language that Java has become. The revolution was not televised, and it was met with little fanfare, but it has happened. It is possible for you to continue to write the same old Java code in our new Java 8 world, but unless you get onboard with the revolution, you will increasingly discover code that is called “Java,” but which has language, syntax, and customs that are foreign to you.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

eBook
USD 16.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 16.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    Unfortunately, they don’t have the same capability with Lists specifically, so I had to do some work to get to the right type.

  2. 2.

    It has happened on Apple’s platform, where Swift is replacing Objective-C. It’s also worth noting that Clojure has made a valiant effort on the JVM front. Some of my peers will defend themselves by pointing to the relative success of Scala, but Scala is not actually a functional programming language: http://blog.enfranchisedmind.com/2009/05/scala-not-functional/ .

  3. 3.

    We will get into the language of “closure” vs. “lambda” later on. In general, a developer can get along just fine treating them as synonyms. Java prefers “lambda,” whereas most other languages on the Java Virtual Machine prefer “closure.” Ruby, notably, has seven variations on “lambda” and “closure,” leading to this quite entertaining exploration of the programming language: http://innig.net/software/ruby/closures-in-ruby .

  4. 4.

    Project Coin was a project for small change. (Get it?) Introducing lambdas was initially proposed as a bit of syntactic sugar, but it quickly became clear that the implications of having lambdas would have wide-reaching ramifications for the Java SDK’s API.

  5. 5.

    E.g., Hibernate.

  6. 6.

    http://www.jooq.org/ .

  7. 7.

    API at http://bit.ly/jdbcTemplate .

  8. 8.

    The more generalized version of the “Inversion of Control” pattern is the “Hole in the Middle” pattern. http://blog.enfranchisedmind.com/2007/07/the-hole-in-the-middle-pattern/ .

  9. 9.

    Static methods are the obvious exception to this rule, although you can think of the static members of a class as implementing a singleton object. This way of thinking is demonstrated best by Scala’s “object” keyword.

  10. 10.

    It’s worth noting at this point that inner classes—including anonymous inner classes—were not part of the Java 1.0 specification. They arrived in Java 1.1.

  11. 11.

    Is there any question what an implementation of the PreparedStatementSetter interface is supposed to do?

  12. 12.

    Because of Java’s adamant object-oriented roots, the language itself is still a bit awkward with this trade-off: for instance, the java.util.function documentation specifies that it’s okay to refer to a lambda as “this function” instead of “the function represented by this object.” Nonetheless, lambdas are a powerful feature borrowed from the functional programming paradigm, and integrated well into Java 8.

  13. 13.

    There are, of course, corner cases to this claim, especially when you’re calling a method overloaded with similar interface type structures. We will get into these boundary cases later.

  14. 14.

    http://github.com/webonise/funjava .

  15. 15.

    The author does grant that this could be selection bias.

  16. 16.

    http://www.scala-lang.org/old/node/4960 .

  17. 17.

    E.g., Haskell, OCaml, Lisp.

  18. 18.

    If you would like to see object-oriented programming done in C, for instance, see the GMP library’s C API.

  19. 19.

    Might I suggest picking up OCaml over the course of an evening or two?

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2015 Robert Fischer

About this chapter

Cite this chapter

Fischer, R. (2015). Java 8: It’s a Whole New Java. In: Java Closures and Lambda. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4302-5999-2_1

Download citation

Publish with us

Policies and ethics