Archive for Best Practices

Live template in IntelliJ IDEA to generate serialVersionUID

Live templates in IntelliJ are cool. They reduce the number of keystrokes you need for repetitive code. One problem is adding the serialVersionUID value to a serializable class. If you have the serialization inspections enabled (Project Settings > Inspections > Serialization Issues > Serializable class without ‘serialVersionUID’), then IntelliJ will warn you and you can [...]

A case for declaring your variables as final in Java

I wrote a few months ago about Yoda conditions and using the final keyword. I recently came across a bug that would never have occurred if a final keyword was used. Consider the following code. I’ve simplified it to the point that a static map structure could be used, but that was not the case [...]

Why Yoda conditions are bad and usage of Java’s ‘final’ keyword is good

I came across some code a while back that made me pause for a moment as I figured out its meaning. This code used something known as a Yoda condition, also sometimes referred to as Yoda notation. In a conditional block, the operands on an operator are reversed, so that the constant expression is listed [...]