Home » Tag Archives: Lambdas

Tag Archives: Lambdas

Exceptions in Lambdas: An Elegant Solution to a Bit of a Mess

java-logo

Consider the following function for writing to a file: The idea behind the method is to allow the user to pass in different implementations of InputStream to the method so that writeToFile can be called for example with a GZIPOuputStream, SnappyOuputStream (fast compression) or simply a plain FileInputStream. private static void writeToFile(File file, String value, Function<OutputStream, OutputStream> writing) throws IOException{ ...

Read More »

Cheating with Exceptions – Java 8 Lambdas

java-logo

Cheating with Exceptions – Java 8 Lambdas Leaving aside the religious debate about Checked vs Runtime exceptions, there are times where due to poorly constructed libraries, dealing with checked examples can drive you insane. Consider this snippet of code which you might want to write: public void createTempFileForKey(String key) { Map<String, File> tempFiles = new ConcurrentHashMap<>(); //does not compile because ...

Read More »

Java 8 Lambdas in One Line

java-logo

If you understand this line, or better still can write this code you can pretty much say that you have understood the essence of Java 8 Lambdas. Certainly in as much as they can be used with collections. I found this in a recent presentation by Peter Lawrey.  (Definitely worth watching the whole presentation when you have a spare hour.) Anyway ...

Read More »

Yet another Java 8 Lamdbas and Streams example

java-logo

I’ve been lagging behind with what Java 8 features exercising concerns, so in this post I will briefly present my initial experience with lambdas and streams. As usual, I will focus on a Podcast class:               package org.codingpedia.learning.java.core; import java.util.Comparator; public class Podcast { int id; String title; String producer; int subscriptionsNumber; /** number of ...

Read More »

Java 8 Lambda Expressions Tutorial

java-logo

Greetings! :) After a few months away I decided to come back in style :). I noticed that one of my previous posts about the new Date/Time API got really popular, so this time I’m going to dedicate this post to another new feature of Java 8: Lambda Expressions. Functional Programming Lambda Expressions are the way by which the Java ...

Read More »

Using Java 8 Lambda expressions in Java 7 or older

java-logo

I think nobody declines the usefulness of Lambda expressions, introduced by Java 8. However, many projects are stuck with Java 7 or even older versions. Upgrading can be time consuming and costly. If third party components are incompatible with Java 8 upgrading might not be possible at all. Besides that, the whole Android platform is stuck on Java 6 and ...

Read More »

Java8 Lambdas: Sorting Performance Pitfall EXPLAINED

java-logo

Written in collaboration with Peter Lawrey. A few days ago I raised a serious problem with the performance of sorting using the new Java8 declarative style. See blogpost here.  In that post I only pointed out the issue but in this post I’m going to go a bit deeper into understanding and explaining the causes of the problem.  This will ...

Read More »

Java Lambdas and Low Latency

java-logo

Overview The main question around the use of Lambdas in Java and Low Latency is; Does they produce garbage and is there anything you can do about it? Background I am working on a library which supports different wire protocols. The idea being that you can describe the data you want to write/read and the wire protocol determines if it ...

Read More »

Instances of Non-Capturing Lambdas

java-logo

Roughly a month ago, I summarized Brian Goetz’ peek under the hood of lambda expressions in Java 8. Currently I’m researching for a post about default methods and to my mild surprise came back to how Java handles lambda expressions. The intersection of these two features can have a subtle but surprising effect, which I want to discuss. Overview To ...

Read More »

Why Now is the Perfect Time to Upgrade to Java 8

java-logo

Interested to see how you can get the most out of the new Java 8 features with AppDynamics? Start a FREE trial now! This past March, Oracle released their most anticipated version in almost decade, Java 8. The latest version had a growing buzz since it had been announced, and companies of all sizes were eager to upgrade. Our partner, ...

Read More »
Do you want to know how to develop your skillset and become a ...

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!
Get ready to Rock!
To download the books, please verify your email address by following the instructions found on the email we just sent you.

THANK YOU!

Close