Home » Tag Archives: Lambdas

Tag Archives: Lambdas

How and Why to Serialize Lambdas

java-logo

Overview Serializing lambdas can be useful in a number of use cases such as persisting configuration, or as a visitor pattern to remote resources. Remote Visitors For example, so I want to access a resource on a remote Map, I can use get/put, but say I just want to return a field from the value of a Map, I can ...

Read More »

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 »
Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.