In Java, static final variables are constants and the convention is that they should be in upper-case. However, I have seen that most people declare loggers in lower-case which comes up as a violation in PMD.
e.g:
private static final Logger logger = Logger.getLogger(MyClass.class);
Just search googleor SO for "static final logger" and you will see this for yourself.
Should we be using LOGGER instead?
If you are using an automated tool to check your coding standards and it violates said standards then it or the standards should be fixed. If you're using an external standard, fix the code.
The convention in Sun Java is uppercase for public static constants. Obviously a logger is not constant, but represents a mutable thing ( otherwise there would be no point calling methods on it in the hope that something will happen ); there's no specific standard for non-constant final fields.
I personally think it looks really big in upper-case. Moreover, since it's a class that it's not directly related to the class behaviour, I don't see a major problem in using
logger
instead ofLOGGER
. But if you are going to be strictly pedantic, then useLOGGER
.Don't forget that PMD will respect a comment with
in it. This will cause PMD to skip the line from its checks, this will allow you to choose whichever style you want.
To add more value to crunchdog's answer, The Java Coding Style Guide states this in paragraph 3.3 Field Naming
Following this convention,
logger
is astatic final
object reference as stated in point 2, but because it is followed by ".
" everytime you use it, it can not be considered as a constant and thus should be lower case.I like Google's take on it (Google Java Style)
Examples:
The logger reference is not a constant, but a final reference, and should NOT be in uppercase. A constant VALUE should be in uppercase.