Stream.forEach() overuse

Starting with Java 8, Java programmers can enjoy the merrits of functional programming thanks to lambdas, java.util.function.* and the stream API. This is great, and allows to improve readability. For example, conversions of lists can be written in a relatively succint way: List<String> hosts =; That is much nicer and easier (or at least faster) to read than this: List<String> hosts = new ArrayList<>(urls.size()); for (final URL url : urls) { hosts. »

Reversing a Linked List

Linked lists are an important data structure and also a popular source of interview questions. Few programmers will actually have to do a fully fledged linked list since most programming languages come with an implementation of it (usually of doubly linked lists). Nonetheless, understanding linked lists and other data structure will help you better understand runtime consequences of choosing one data structure over another. Reversing a linked list is a common task. »

Functional Java

With Java 8 the language got lambdas. This is a huge step towards allowing functional programming in Java and hence brings a fresh breeze. The language designers did not stop by simply providing lambdas but also extended the runtime API significantly to support lambdas and functional programming. What are lambdas? The Java Documentation for Lambda expressions gives a rather dry definition: “Lambda expressions let you express instances of single-method classes more compactly. »

Equals != Equality

The other day, I read the article How to Write an Equality Method in Java. Which reminded me that I wanted to write an entry about equality in programming. I cannot hope to cover this topic adequately in a blog post. My goal is merely to show that equality is very hard and that we often have a sever misconception about it. Most programming languages give us several ways to check equality. »

duckprxy with javasist

I just released version 0.2 of duckprxy. It now comes with a duck proxy implementation that uses Javassist: JavassistDuckPrxy. Proxies created with JavassistDuckPrxy are not using runtime reflection, but dynamically created code that is compiled to byte code by Javassist. This should reduce the overhead to that of normal delegation, hence, very little. I did not do any performance tests yet, though. »

Duck Typing for Java

Every now and then I need to implement some interface, but only one (or very few) methods of it. Usually I need something like this in test code, but it is useful elsewhere, too. The mocking libraries I have seen so far offer something similar, but not quite in the way I want to have it. I had the idea to use something like duck typing for it for a while now. »

The Visitor Pattern in Differen Languages

In this post I want to explore the usage of the visitor pattern in different programming languages. The goal is always to represent expression trees, i.e., to have the abstract syntax tree (AST) of an algebraic expression like 2 * 5 - 3. Let us start with a simple implementation in Java: import java.util.HashMap; import java.util.Map; public class ExpressionTree { public static interface Operator { int eval(int ... args); } public static Map&lt;String, Operator&gt; OPERATOR_MAP = new HashMap&lt;String, Operator&gt;(); static { OPERATOR_MAP. »

Character Encoding --- Part 2: HTTP Auth

My last blog entry was about the character encoding problems I had with Klatschbase. Of course, there has to be a follow-up, since encoding problems are so ubiquitous. I did a change to hunchentoot’s basic authorization method to allow utf-8 login name and password. As Edi Weitz pointed out in the hunchentoot mailinglist, this change is not standard compliant. Thinking about it, my assumptions were quite stupid. Why should the header, that is sent by the client, care about the standard encoding of the server. »

Character Encoding --- a Never Ending Story

Character encoding really is a never ending story. I am a huge fan of Unicode and UTF-8. But it is still not the default everywhere. This blog entry is about the problems I encountered while making Klatschbase working correctly with UTF-8. First of all, SBCL - my common lisp implementation of choice - supports UTF-8 out of the box. So, no problem here. Hunchentoot, Edi Weitz’s wonderful http server, supports UTF-8, but per default uses ISO-8859-1. »