11

I have been exploring the new features in the JDK8, like the lambda expressions, the extension methods, and the new stream API.

Evidently none of these features are new in the programming world and that made wonder why are getting all these things in Java until now.

We had lambda expressions in Lisp (1958), SML (1973), Haskell (1990), Python (1991), JavaScript (1994), Ruby (1995), Scala (2003), C# (2007) and 55 years after Lisp and practically everyone else, in Java (2013).

And I had read about streams in SIC (1996).

I have been wondering why now? The evidence suggests that competing with other languages is not the motivation.

It would seem that all the cool new features in this release of Java are just a by-product of implementing parallelism. We have lambdas because they make writing parallel algorithms simpler, and we have extension methods because we needed them to give support to the changes that lambda expressions required, etc., etc.

So, my question is: can we safely affirm that the main topic in this upcoming release of Java is actually parallelism? Or can we justify other reasons for the appearance of the oldest tricks in the book until now in Java?

5
  • 4
    All this can turn into is a flamewar about Java's behind-the-times-ness.
    – Michael K
    Mar 8, 2013 at 19:13
  • 5
    The evidence suggests - please share your research.
    – user40980
    Mar 8, 2013 at 19:16
  • 2
    None of the features either in Java or in the JVM or in the JRE were ever new. And even the combination of features isn't new, Eiffel had all of those in 1985 (GC, OO, type-safety, even Generics which Java didn't get until 2003). In fact, it has very much been an express goal of the Java designers to not introduce anything new. Mar 8, 2013 at 20:22
  • 2
    @MichaelK - I agree this could turn into a flame war. It could also turn into a valid answer regarding Sun's challenging history; Oracle's acquisition of Sun and Java; and how the current maintainers of Java are trying to drive the language. My hope is that answers will focus on the constructive aspects of this question.
    – user53019
    Mar 8, 2013 at 20:23
  • @MichaelT: I hope it will not turn into a flame war and some interesting ideas could emerge. For example, often we assume that a language that does not constantly evolve is behind the times. IMO this is not true because it assumes that language evolution is linear (that all new features that become popular are good and should be adopted by all modern languages). But the maintainers of a language could decide that a new feature does not fit with the rest of the language. Also, consider that there are standardized, stable languages that are definitely not behind the times (e.g. Common Lisp).
    – Giorgio
    Mar 8, 2013 at 22:14

4 Answers 4

12

When Java was first designed it was considered appropriate to leave out anonymous functions. I can think of two reasons (but they might be different from the official ones):

  1. Java was designed as an object-oriented language without functions, so it was not very natural to have anonymous functions in a language without functions. Or at least, this would have influenced the design of the language a lot.
  2. Anonymous functions were not popular in the programmer communities that Java was meant to attract (C, C++, Pascal?). Even now, many Java programmers seem to consider these features quite exotic (but this will probably change very quickly with Java 8).

In the following years, as Robert Harvey has explained, the policy of Sun was always to keep Java backward compatible and very stable.

On the other hand, other competing languages have emerged (the most important being C#, which was born as a Java clone and then took its own development direction).

Competing languages have put Java under pressure for two reasons:

Expressive power

New features can make certain programming idioms easier to write, making the language more attractive for programmers. Normally the set of features provided by a language is a compromise between expressive power, language complexity, design coherence: adding more features makes a language more expressive but also more complex and difficult to master.

Anyway, in the last few years Java's competitors added lots of new features that Java did not have, and this can be considered an advantage.

Hype

Yes, unfortunately this is a factor in technology choice, at least from what I can see in my daily experience as a programmer: a tool must have a certain feature, even if most members of the team don't know how to use it and those who would be able to use it don't need it most of the times.

Hype can be even more important for non technical people like managers, who may be the ones who decide the platform for a certain project. Managers sometimes only remember some keywords like lambda, parallelism, multicore, functional programming, cloud computing, ... If our technology of choice has a green mark on each item of the list, then we are up to date.

So IMO for some time Java has been caught between

  • the original policy of language stability and design simplicity, a huge code base and developer community on one hand, and
  • the pressure of competing languages that could attract Java programmers, C# at first, and then Scala, Clojure, F# (I name the ones I am aware of, there may be others).

Eventually Oracle decided to upgrade Java to make it more competitive. In my opinion, the new features address especially Java programmers that might be tempted to switch to C# and who see other languages like Scala and Clojure as too different from Java. On the other hand, developers who have some experience with functional programming and still want to use the JVM have probably already switched to Scala, Clojure, or another language.

So the new Java 8 features will make Java more powerful as a language and the declared focus is concurrent and parallel programming, but the upgrade seems to address also the marketing aspects (Mark Reinhold, chief architect for Java at Oracle, said: "Some would say adding Lambda expressions is just to keep up with the cool kids, and there’s some truth in that, but the real reason is multicore processors; the best way to handle them is with Lambda", see this article).

So, yes, many (all) Java 8 features were well known already, but why and when a feature is added to a language depends on many factors: target audience, existing community, existing code base, competitors, marketing, etc.

EDIT

A short note regarding "... I had read about streams in SIC (1996).": do you mean that you need Java 8 lambdas to implement streams? Actually you can implement them using anonymous inner classes.

4
  • +1 And I wish I could give you more points because this is the best answer so far to the question.
    – edalorzo
    Mar 8, 2013 at 22:24
  • Based on your answer I investigated more about what Mark Reinhold had said I have found an interesting article. I will post it here with your answer for future reference: Closures for Java by Mark Reinhold.
    – edalorzo
    Mar 8, 2013 at 22:35
  • And that article actually refers to this another one Closures for Java.
    – edalorzo
    Mar 8, 2013 at 22:39
  • 1
    From the link you sent I found this ibm.com/developerworks/java/library/j-jtp03048/index.html#4.0, saying that Java can use anonymous inner classes, but these are too verbose. Yet, Java 8 closure are not just syntactic sugar for anonymous inner classes. So now Java will have TWO (semantically) different kinds of closures: anonymous inner classes and lambda expressions.
    – Giorgio
    Mar 8, 2013 at 22:50
11

Java has changed focus with time. At first it was designed as a simple powerful language, as a reaction to "powerful complex" C++. Some features that were in C++ were intentionally left out, like operator overloading, templates, enums, that were deemed too complicated or relics of the C era, and OOP being at the peak of its popularity, everything was made an Object in a single-paradigm worldview. Lambdas at this time were considered simply "not needed" since introduction of anonymous/inner classes in Java 1.1. The fact that the syntax was far more verbose was almost considered a feature.

Java having found its public, there were no incentive to change until Microsoft introduction of C#, which learned from the lessons of Java design mistakes, and launched a series of new language features. They were not constrained by backwards compatiblity. I think that Java conceptors realized the danger of C# competition and release Java 5 with generics, enums, etc.

Inclusion of lambdas in Java is discussed since that time and it was only exacerbated by the current trend for functional programming. But things like this are slow to make right, and it has to be right the first time. In my opinion Java botched generics with type erasure because backwards compatibility was considered a reason to implement it as no more than syntactic sugar. Closures has been thought up more thoroughly, it appears, and it will be more than just syntactic sugar.

In conclusion, what is Java 8 main topic? I don't think a language version has a topic. As C++11, the Java 8's raison d'etre is to keep up with the competition by introducing in the language the things that more and more programmers are taking for granted now. Lisp may have lambda since 1958, its popularity has plateaued for decades now and only recently functional programming has been considered seriously for "mainstream" programming (for lack of a better word).

3
  • "Lisp may have lambda since 1958, its popularity has plateaued for decades now and only recently functional programming has been considered seriously for "mainstream" programming": A language's popularity does not seem to be a good indicator for its effectiveness. Functional programming has been advocated for many years but most people in the industry considered it the kind of stuff researchers like to play with to write their PhD thesis on. Now all of a sudden the industry is waking up and giving it a chance, maybe because now that OOP is mainstream they are looking for the next big thing.
    – Giorgio
    Mar 9, 2013 at 12:52
  • 1
    The reason why closures were not originally included in Java according to: Understanding the Closures Debate. There James Gossling said: "Closures were left out of Java initially more because of time pressures than anything else. In the early days of Java the lack of closures was pretty painful, and so inner classes were born: an uncomfortable compromise that attempted to avoid a number of hard issues. But as is normal in so many design issues, the simplifications didn't really solve any problems, they just moved them."
    – edalorzo
    Mar 9, 2013 at 14:17
  • "Inclusion of lambdas in Java is discussed since that time and it was only exacerbated by the current trend for functional programming.": I find it interesting that in some communities (C++, Java, ...) "using lambdas" often means "doing functional programming".
    – Giorgio
    May 25, 2018 at 6:04
8

Evidently none of these features are new in the programming world and that made wonder why are getting all these things in Java until now.

Because Java has to go through an approval process that involves several high-visibility stakeholders in a process akin to "design by committee", and that process takes time, that's all.

Contrast that with other languages and you'll find either a benevolent dictator, or a small committee of language designers who work closely together and are not tied to corporate interests.

Combine that with an established code base of millions of lines of Java code that has to stay backwards compatible, and you have all the ingredients for change at a glacial pace.

3
  • 1
    OTOH, you also have the ingredients for really strong and widely accepted standards. Contrast e.g. JPA with the situation for PHP, where everye web framework has its own half-assed ORM. Mar 22, 2013 at 12:31
  • I may be wrong, but my understanding is that Haskell is also a "design by committee" language, and it's a cutting-edge language. So maybe that's not what's hindering Java?
    – Andres F.
    Mar 22, 2013 at 16:58
  • @AndresF. Yes, but I imagine that you don't have large, monolithic companies sitting on the Haskell committee. See also the conversation in the comments here. Mar 22, 2013 at 17:19
1

I would say that the most important purpose of a programming language is to be used; currently C and Java don't have lambda expressions and they are the most used languages (according to TIOBE for example).

And to answer the question I believe that Java is addressed to the enterprise; in this domain things need to be very stable and reliable; for example Java 7 has appeared for almost 2 years yet I don't know directly any project in Java 7. Also another important thing is backwards compatibility which is very important for the enterprise.

1
  • I agree with you (+1): I value Java a lot (as a language and for its huge ecosystem) but I would have found it more appropriate to freeze the language at Java 6. I am not going to put any effort into learning Java 7 or 8 unless I am forced to (some very interesting project in which Java 7 or 8 is a must), I rather spend my time learning Scala and Clojure.
    – Giorgio
    Jul 17, 2013 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.