Will Java 8 Lambda expressions really change JavaEE development?

One of the most anxiously anticipated Java 8 features was the addition of Lambda expressions. But after almost a year since their release, are they actually being adopted, and will they really have any impact on how JavaEE applications are developed?

The introduction of Lambdas with Java 8 is enticing old hands at Java to try something new with their programming. Some love the fresh take on Java and others feel that it simply gives mediocre programmers another way to write awful code that's impossible to maintain. But most enjoy the challenge of at least giving it a spin and offering an opinion. 

The first time developers, the people that learn Lambdas when they're learning Java, are going to be the ones who use it most. 

Nicholas S. Williams

For Nicholas S. Williams, author of Professional Java for Web Applications, learning Lambdas was a necessity. After all, he couldn't write a book about a topic like this without getting some hands on experience. He said he foresees a future in which using Lambdas will seem as natural as breathing. It all starts with the fresh crop of programmers.  Just as today's children don't remember a world before the Internet, young developers will never have known a different way to do Java.

"The first time developers, the people that learn Lambdas when they're learning Java, are going to be the ones who use it most. The more skilled, more experienced Java developers who have pre-Lambda Java in their heads are going to stick with what they know. Historically, since Java 4, the Java community has been a little bit slow to adopt. Certainly it will be a while before experienced Java developers are going to be using Lambdas on a regular basis."

How hard is learning Lambdas?

Not at all, according to Nicholas. It's really a matter of having the will to give it a try. He offered his perspective as an experienced Java developer who had never used Lambdas before. "It's extremely easy to learn. It took me about a day to learn all the nuances of Java Lambdas. If you've got any type of experience with dot.net or with JS, it's going to be second nature to use Lambdas. There's not much of a learning curve. The only real problem is that generics can be a gotcha. But when has that NOT been true in Java?"

Barry Burd, author of Android Application Development All-in-One for Dummies, also felt that Lambdas were a walk in the park compared to the trickier generics. "I think, for me, Lambdas are easier than generics. Some of the finer points of generics are things I hardly ever use and would probably fail a quiz on. Generics are pretty easy to use in their most basic form. But when you get to the subtleties, they're harder."

Burd agreed with Williams that Lambdas are reminiscent of other non-Java programming languages. "Because I've done Haskell and some other functional programming, I don't find them quite as intimidating." For Java programmers who aren't familiar with other languages, they should know that Lambdas aren't reinventing the wheel for the coding world as a whole. They are just borrowing some of the concepts that make other languages easier to write and applying it to Java. "It's not different because it's new. It's different because it's just different stuff."

What's next after Lambdas?

The rumor around the water cooler is that the game changer in Java 9 could be unsafe. That is, it could be sun.misc.Unsafe. Burd said he is chomping at the bit to give this new feature set a whirl. "The idea is that with the Unsafe mechanism in Java, you can basically bypass all the things that Java was built for. And you're doing it safely because you're declaring the use of this unsafe class. Basically, you can write non-Java code in Java. When somebody told me about this, I had to go home and explore it."

What could developers play around with in the unsafe library? "You can do pointer arithmetic, you can do casting that's normally not legal in Java. You can mess around with it like you're a C programmer, shoot yourself in the foot and have fun doing it."

Based on his first cursory excursion into unsafe territory, Barry felt this option might turn out to be a bit pointless. "It's not anything particularly practical. I'm sure there are practical applications, but if you're using it for practical purposes in the long term, you'd probably want to skip to a different language."

However, many Java developers would like to see more access to this feature set to address very practical problems. Unsafe is already in use in the database arena to improve memory performance and reduce the amount of work for the garbage collector. It's simply a matter of making the option more broadly available. Of course, as developers learn their way around this feature set in the enterprise world with real life consequences, they will need to be cautious about shooting anyone in the foot. Stay safe out there.

What features would you like to see in Java 9? Let us know.

Dig Deeper on Java ALM