Java Tag

The other day I wanted to add video playback support to Tabris. "Ha!" I thought, "Piece of cake." My fallback strategy was the normally well documented Android API and, as a last resort, Stackoverflow with the answer to almost any question you can think of. As it turned out, none of these assumptions were correct. While implementing the new video feature, I ran into some pitfalls...

Read More

With OSGi we are able to implement building blocks for modular applications. Dependency injection frameworks support us in writing flexible, testable and clean code. The "Blueprint Container Specification" defines a dependency injection framework to build applications that run in an OSGi framework. The specification was added in version 4.2 to the OSGi compendium Specification[1]. This specification is derived from the Spring Dynamic Modules project[2] which...

Read More

Many developers still catch Throwable in their try/catch statements. Is this a good idea? I don't think so. As all of you know, Throwable is a generic superclass for all exception and errors in Java. As exceptions are meant to be caught, errors in most cases are not. If we take a look at the Error class JavaDoc we will read the following: An Error is...

Read More

When it comes to Code Coverage and Java, you can't ignore JaCoCo. JaCoCo was created by Marc Hoffmann based on the lessons learned using the popular Emma coverage tool. There are plenty of projects using JaCoCo but there was one missing piece - integrating the coverage report into the automated build. Since there was no JaCoCo Plugin for Jenkins/Hudson the only way developers could see the report was...

Read More

During my life so far with Java I found myself often using separated Strings, such as a comma separated String. The reason is simple. Separated Strings are useful in many situations, like persistence prototyping, where you don't want to add a full blown persistence solution but a small, lightweight file based store to save some values. Or, when you transmit data over the wire and...

Read More

A common task in object oriented programming is comparing two objects for the purpose of sorting. In Java the useful Comparable<T> Interface exists. I’ve found myself implementing the compareTo method from this Interface plenty of times. But there is something that bothers me everytime: the complexity of the code this implementation creates. Let me explain. One of my goals is to always write easily readable code....

Read More

I can't count the number of times I found myself implementing some sort of cache. In many situations caching is really useful e.g. when the computation of a value is expensive or when loading of resources is involved. I bet you found yourself implementing a cache many times too. Probably you have also used a Java Map for storing the values. One disadvantage of using...

Read More

Working towards clean code is a priority for me when I develop software. For some time I've been using Google Guava for nearly all my projects. The reason is simple. Guava provides great facilities to beautify my code. Today I want to show you how I use Preconditions to avoid unnecessary if/throw statements and Optionals to improve my code semantics. [ Need expert advice for your...

Read More

Last week I talked to a fellow developer, Frank Appel, about Mockito. We've been using this mocking library for over a year. We both agreed that of all the innovations we've tried in the last year or so, Mockito has boosted our coding productivity the most. With this blog series we want to share our experiences with Mockito. You see that I used the word...

Read More