19 June 2013

Many languages have a sense of "idiomatic" code: code that embraces the norms of that language. These idioms can often reflect the opinions of the language themselves: functional vs. object oriented vs. imperative, etc.

Java, on the other hand, debuted more as a simpler version of existing norms, rather than an opinion motivating people in any one direction. I would argue that - aside from understanding basics like JavaBean properties and what equals, hashCode and toString do - there's very little to "idiomatic" Java code, except perhaps compliance with Java style.

There have been many texts published over the years espousing Java style. Compliance with Java style will make your code imminently more readable to 99% of the Java community. Sun / Oracle have published several documents over the years espousing good guidelines for code names and conventions. This directory has a good listing of several style guides. I'd definitely recommend taking a look at the first two guides, in particular.

If you want very well structured code, then I can recommend no finer a guide than the Spring framework code itself. Here's a great podcast on some of the lengths Spring framework lead Juergen Hoeller has gone to over the years to ensure clean, well structured code (code that, as I'm sure you're aware, has stood the test of time and remained utterly and completely backwards compatible for more than a decade!). The Spring framework is legendary for having a REALLY great codebase. It routinely scores high on code quality tests. It's actually won awards at various conferences. This is because Juergen Hoeller, lead of the Spring framework, is notorious for ensuring a VERY consistent look and feel to the Spring framework. ALL the Spring projects follow his basic style and approach. That's why they're so easy to get started with, because they all look and feel consistent. In fact, Juergen's discipline is so famous that the act of having your code torn to shreds and rebuilt in a stylistically more consistent way is known as Juergenization.

My colleague Oliver Gierke also has a great post on this anomaly, as well as a proper definition on his blog.