The code and naming conventions for Java are fairly well established. In particular, this one (or its mismatch) can be seen in Section 9 - Naming Conventions
The names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores ("_"). (ANSI constants should be avoided, for ease of debugging.)
static final int MIN_WIDTH = 4;
static final int MAX_WIDTH = 999;
static final int GET_THE_CPU = 1;
The key point is that this is a variable in the example code. Its one that you've given the hint to other coders that once assigned it can't be changed - but it is not a constant. Furthemore, it isn't a class constant.
public final void myMethod(User user, Group group) {
final int MAX_USERS_PER_GROUP = group.getMaxUsersPerGroup();
int usersInGroup = 0;
// Get users in group and all subgroups, recursively
if (usersInGroup > MAX_USERS_PER_GROUP) {
throw new Exception(...);
}
}
This would be incorrect according to the naming standards.
You may wish to look into running checkstyle. The naming conventions checks for this are in accordance with Java naming conventions.
The local final variable check is:
LocalFinalVariableName
local, final variables, including catch parameters
^[a-z][a-zA-Z0-9]*$
It starts with a lower case and does not include underscores. Of course, your team could vary from this Java standard, and tweak checkstyle's rules to make sure that you are all following the same convention - though you will confuse other Java coders who look at the code.
"yes, absolutely, these questions are on-topic, and here's why I think so"I posted a similar question on this Stack Exchange that is +6. I don't see your point. – NobleUplift Apr 09 '15 at 15:55if(usersInGroup > group.getMaxUsersPerGroup()) { /* ... */ }You should try to avoid defining constants within methods, if at all possible – HotelCalifornia Apr 09 '15 at 18:02MAX_USERS_PER_GROUPis a constant (which is debatable), I would hopemyMethodisn't so big that you need a naming convention to keep track of local variables. – Doval Apr 09 '15 at 18:03group.getMaxUsersPerGroup()came from a different database object with a different name, so if I have to revert this code I can change it at one location, not many. @Doval I'd say it's close to 500 lines long. – NobleUplift Apr 10 '15 at 15:21