Maven Plugin: Java Code Formatter

Enforcing code format in an organization needs discipline. And the best way to do that is by doing some automation. A plugin for Maven will be a easy decision if your organization has used Maven to manage the build. This plugin is one plugin that exactly does that. The backbone on the plugin comes from …

op4j: Bending the Java spoon

The tagline of op4j is very interesting: ‘Bending the Java spoon’, which implies that the library offer magic to Java programming. And indeed it does. The basic idea of the library is to use Fluent Interface to a much greater use. To do this, the developer basically try to provide as much general functions as …

Little Java Generic Quiz

Let say I have following code: Can you guess what are the answers for following questions? TestGeneric will be reported as error by Java 6 (true/false) TestGeneric will be reported as error by Java 7 (true/false) TestGeneric will be reported as error by Eclipse 3.5 using Java 6 (true/false) TestGeneric will be reported as error …

Computing Map on Google Collections

Google always makes interesting projects. My toy nowadays is Google Collections. I don’t think I need to reintroduce it as it has been nicely covered on several blog posts: Introduction to Google Collections A series from CodeMunchies Beautiful code with Google Collections, Guava, and Static Imports Diving Into the Google Guava Library Functional Java Filtering …

Lambda4JDT: lambda expression on your Java code

This is just another proof how many people are starting to want some functional syntaxes on Java. Some lambda expressions are possible to be implemented using current Java, but there are just too many noise in the result. Lambda4JDT provides a new plugin for Eclipse that can collapse the noise in the implementation without changing …

Java Tips: Optimizing your Map loop

Quite often, a program needs to go through all elements of a Map. Unfortunately, like a Set, a Map doesn’t have index in the data structure so you can’t just get a key of certain index or a value of certain index. The most common practice used to iterate all elements in a Map is …

Java Tips: Thread Safety Documentation

Joshua Bloch in his book, “Effective Java” summarized the levels of thread safety: immutable—Instances of this class appear constant. No external synchronization is necessary. Examples include String, Long, and BigInteger (Item 15). unconditionally thread-safe—Instances of this class are mutable, but the class has sufficient internal synchronization that its instances can be used concurrently without the …

Java Tips: Memory Optimization for String

String is a unique object in Java. The Java Specification explains several unique properties of String in Java. We might already know some of them. First, String is unique because it can be created without new keyword, like example below. I have to mention that you can still create String object using new keyword, like …

Spring Tips: Initializing bean using EasyMock for unit test

Unit test is a very good practice for creating robust application. Using Spring, we can avoid using ApplicationContext and instead arrange all dependencies programmatically. However, once in a while, we still need to test using the actual ApplicationContext. This can be problematic if our test using mock from EasyMock. So here is the example on …