Category Archives: Java

Unknown Java Features Part 2: TimeUnit

Simple Way to use different time units TimeUnit is the simplest way to work with different time units since Java 5. Aren’t you annoyed about writing all the time how to convert e.g. minutes to milliseconds? Like “5 * 60 … Continue reading

Posted in common practice, Java, Unknown feature | Tagged , | Leave a comment

Autoboxing Performance

Preface Because of my previous post about autoboxing I get many search queries about autoboxing performance. Now I’m curious, too. So let’s get ready for some benchmarks. When we talk about boxing performance, then we always have two sides. Throughput … Continue reading

Posted in Java, Performance | Tagged , , , , | 2 Comments

Singleton Pattern

The singleton pattern is one every developer must know. It is a class which has only one instance, which is handled inside it. You can only get the instance, but never (reflection etc excluded) create a new instance. Advantages It can … Continue reading

Posted in common practice, Java, tips | Tagged , , | Leave a comment

Use Jaxb where possible

I was asked in an job interview, if I know something about DOM or SAX parsing. I know something about it, but I have only used it once. Why should I bother myself with this, when I just can use … Continue reading

Posted in Java, tips | Tagged , , | Leave a comment

JaCoCo – the new and revolting Java Code Coverage tool

I’ve stumpled across JaCoCo while searching for a possibility to have the code coverage of a multi modul project merged. JaCoCo is made from the same developer, which made the eclipse plugin EclEmma. The big advantage (and disadvantage maybe) is … Continue reading

Posted in Java, Tooling | Tagged , , , , , | Leave a comment

calendar.equals is evil (especially over RMI)

And again I stumbled across a problem of the date/time API of the JVM. This time it is the java.util.Calendar object. The Calendar object violates against the x.compareTo(y)==0       ==         x.equals(y)           recommendation. It’s not a … Continue reading

Posted in Java, Problems | Tagged , , , | Leave a comment

Autoboxing: Traps and Advantages

What is ‘autoboxing’ some people might ask? Autoboxing is a feature, which was added in Java 5. Autoboxing is the automatic conversion of primitive data types like int, double, long, boolean to its wrapper Object Integer, Double… and vice versa. … Continue reading

Posted in common practice, Java, Performance, Uncategorized | Tagged , , , , | Leave a comment

The costs of String concatenation (+) or what String appending really does

String concatenation (e.g. “fu” + “bar”) are for most developers a mystery what it really does. The simple case Something like will usually be appended at compile time. So if you decompile this you see: The final case What happens … Continue reading

Posted in common practice, Formatting, Java, Performance | Tagged , , , , | Leave a comment

SimpleDateFormat in multithreaded environment

SimpleDateFormat is wide known in Java as the default tool to convert a String to a (java.util.)Date and vice versa. Usually you would think you can make a SimpleDateFormat static, like: Because we think, that the formatter just contains the … Continue reading

Posted in Formatting, Java, Multi threading | Tagged , , , , | 1 Comment