If I understood you correctly, what confuses you is:
- the first example's variable name is uppercase:
LOG
.
- the second example's variable name is lowercase:
log
.
- In one case it's declared simply as a
final
type variable, whereas in the other it's declared as a protected static final
type variable.
If so,
LOG
and log
are exactly the same. However, you should know it is common practice for programmers to declare their constants in uppercase. The final
keyword in Java defines a variable which you want to remain constant. So again, it is not required by the compiler to write your constants in uppercase, but it is common practice to do so - that's why you see some programmers use lowercase and others uppercase; it is a matter of preference.
The protected
keyword in Java means you want the variable to be accessible by not only the methods of the class, but any methods of any subclass that inherits from it.
The static keyword in Java, when applied to variables/fields, states that these fields can only be referenced by static methods.
So,
protected static final Logger LOG
means LOG
will be a constant variable and will not change, and it can be accessed by static methods of this class, which can in turn be accessed by objects of any class that inherits from this class.
And,
final Logger LOG
means LOG
will be a constant variable and will not change, and it can be accessed by ANY method in the PACKAGE - it does not matter if inheritance is present or not.
Like the others, I would go with private static final logger LOG
as well.
Please read the following documentation on Java Access Controls for a deeper understanding of what's going on:
Access Controls in Java
Hope this helps you.