String.intern() – there are better ways

4349787041_f31a40baf4_o I don’t want to write a “considered harmful” article (because they are harmful), but after experimenting with different solutions I do have a strong opinion that there almost no reason to use String.intern() in Java. But let us proceed step-by-step.

First of all, what does String.intern() do ...

more ...


Computing the last digit of b^e efficiently

Geek PSA: Yesterday was PI day (3.14, get it?). Lets celebrate with this spiked math comic:

Last week I saw the following problem which peaked my interest:

Compute the last (decimal) digit of 2 raised to the power e where e might be very large.

We assume that we ...

more ...

In praise of Regexp::Assemble

…and of the Perl modules in general. I had the following problem:

Given a list of 16 character alphanumeric IDs, find all the lines from a large-ish (\~6GB) logfile which contain at least one of the IDs.

The naive approach was to construct a big regular expression like \W(\QID1 ...

more ...

Java import statement gotcha

190774444_2687512fb9_o There is a lot of debate on the intertubes if one should or shouldn’t use wildcard imports. I’m mostly indifferent to the discussion (mainly because all the package references are resolved compile time – so there is no performance overhead – and because today’s IDE’s contain a lot ...

more ...

Carving out files with Perl

I’ve had to use this trick a couple of times the last few years, so I decided that I might as well document it:

If you have an image of a storage media (like an SD card or CD/DVD) which you can not mount (either because the filesystem ...

more ...

Splitting hairs^H^H^H^H^H strings with Java

[![Split Personality](http://farm3.static.flickr.com/2097/2225546021_4864c2bc72.jpg)](http://www.flickr.com/photos/nickwheeleroz/2225546021/ “Split Personality by nickwheeleroz, on Flickr”)

Offtopic: where does \^H come from? (since I too found it only recently) - from the source of all wisdom - Wikipedia :-p

Pressing the backspace key on a ...

more ...

Choosing a Java profiler

Recently I’ve been looking around for a Java profiler (since the two things you need for a successful performance tuning session are good data and clear targets). I’ll share the notes about my findings in the hope that they might be useful for someone. Quick disclaimer: don’t ...

more ...

Don’t Yield to pressure?

or: does Thread.yield have its place in todays Java programs?

I was profiling a rather old legacy codebase (since the first rule of performance optimization is “profile it” with the close second of “have clear goals in mind” - but that’s an other post) and - after optimizing the first ...

more ...

Using TarInputStream from Java

994941366_af693049f1_o Recently I had to parse trough a bunch of logs, scattered in subdirectories and different types of archives (tar, bz and gz). My first thought was of course Perl (since it is the language for parsing quasi-freeform text), however I didn’t have “streaming” implementation for the archive modules, which ...

more ...