Reputation: 3534
Java Naming rules suggests which one to be used. This
public static final class DatabaseTable
or, this
public static final class DATABASE_TABLE
Which one is correct?
Upvotes: 0
Views: 2712
Reputation: 19500
I think first one is appropriate. Any class name that may be final or whatever, it's name should be in proper case without any space. Proper case means first letter of each word should be in Upper Case and remember don't use any UnderScore in this case.
You should name in the second style if it is a final variable
Upvotes: 5
Reputation: 114817
fields with public static final
modifiers are used as "constants" in Java and should be written in capitals. So the correct (compilable) statement would be:
public static final Class DATABASE_TABLE = DatabaseTable.class;
In case you were looking for a classname, then the naming convention is as usual for classes: first letter is capital, the name in CamelCaseNotation.
public static final class DatabaseTable {
// ...
}
Upvotes: 1
Reputation: 206926
There is no such thing as "incorrect" here, in the sense that the Java compiler or syntax of the language does not force you to use specific naming conventions.
If we look at the old Code Conventions for the Java Programming Language document, specifically Chapter 9 - Naming Conventions, we see that classes should have CamelCaseNames:
Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).
It doesn't matter if the class is a nested class (static
) or if the class is final
.
ALL_UPPERCASE_NAMES are for constants; static final
variables (not classes).
Upvotes: 4
Reputation: 24134
I would still use the first one as CAPS are generally meant for CONSTANT fields, not for final methods or final classes even if they are static.
Upvotes: 0