I once read somewhere about good case practice when naming methods, attributes, variables ... in Java, could someone refresh my memory?
I once read somewhere about good case practice when naming methods, attributes, variables ... in Java, could someone refresh my memory?
Packages
The prefix of the package name must be unique, it should always be written in lowercase all-ASCII and should be one of the top-level domain names, currently with edu, gov, mil, net, org, two letter codes identifying the countries, as specified in ISO 3166, 1981. Subsequent components of the package name vary according to an organization's own internal naming conventions. Such conventions may specify that certain components of the directory name have division, department, project, machine, or login names.
Example:
com.sun.eng
com.apple.quicktime.v2
edu.cmu.cs.bovik.cheese
Classes
Class names must be substantive, in uppercase and lowercase letters with the first letter of each inner word capitalized. Try to keep your class names simple and descriptive. Always avoid linked words, avoid all acronyms and abbreviations, be it semantic.
Example:
class Raster;
class ImageSprite;
Interfaces
Interface names should be used with the first letters in upper case as the class names.
Example:
interface RasterDelegate;
interface Storing;
** Methods **
Methods must be verbs, with the lowercase letter first, with the first letter of each inner word capitalized.
Example:
run();
runFast();
getBackground();
Variables
Variable names should not start with underscore _ or dollar sign $ characters, even though both are not allowed. Variable names should be short but significant. The choice of a variable name must be mnemonic, that is, designed to indicate to the casual observer the intention to use it. A character variable names should be avoided except for temporary "disposable" variables. Common names for temporary variables are i, j, k, m, n and for integers, c, d, and e for
Example:
int i;
char c;
float myWidth;
Constants
Declared variable names of classes and ANSI constants must be all capitalized with words separated by underscores ("_").
static final int MIN_WIDTH = 4;
static final int MAX_WIDTH = 999;
static final int GET_THE_CPU = 1;
Java has a very simple convention, essentially everything should be camelCase (variables anywhere, including attributes, methods, packages).
Except type name (class, interface, enumeration) that should be PascalCase .
And constants, including Enum
, which must be all uppercase ( ALL_CAPS ), where it is the only place where underline is allowed to separate names .
Remembering camelCase traditional begins with lowercase and the other words in the name continue to begin with a capital letter. This difference already gives the notion of being a different word. It can have any number of words. Some people know about this convention by other names.
PascalCase only differs by the fact that the first word of the name is already uppercase as well. There are other names for this convention.
Note that acronyms should use camelCase as well. Then use valorIcms
and not valorICMS
.