xiver77 xiver77 - 17 days ago 4
Java Question

An Object with a Same Name as the Class in Java

CoordinateArray coordinateArray, coordinateArray1, coordinateArray2;
FileCopy fileCopy, fileCopy1, fileCopy2;


or

CoordinateArray c_arr, c_arr_1, c_arr_2;
FileCopy f_copy, f_copy_1, f_copy_2;


When writing C, I would definitely do the latter, but recently while writing a little Java code I'm tempted to go for the first one. Which way is preferred in Java for whatever reason, or is it 'okay' to name variables the first way? I'm asking specifically for Java since I would like to follow the language's convention.

Answer

Readability and camelCase are the conventions in Java.

from the official docs:

Variables:

Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed.

Variable names should be short yet meaningful. The choice of a variable name should be mnemonic- that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for temporary "throwaway" variables. Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters.

Here's a link to an archived version of Oracles naming conventions: http://www.oracle.com/technetwork/java/codeconventions-135099.html