CamelCase
camelCase is a naming convention in which the first letter of each word in a compound word is capitalized, except for the first word. Software developers often use camelCase when writing source code.
camelCase is useful in programming since element names cannot contain spaces. The camelCase naming convention makes compound names more readable. For example, myOneMethod is easier to read than myonemethod.
Other examples of camelCase are listed below:
- newString;
- getNewString()
- myVariableName;
The name camelCase (also "camel case" or "dromedary case") comes from the hump on a camel, which is represented by the capital letter in the middle of the compound word. A camelCase word may have one or more capital letters.
camelCase vs PascalCase
camelCase is similar to PascalCase, which capitalizes the first letters of all words in a compound word, including the first word. For example, myFunction() in PascalCase would be MyFunction(). Programmers may choose to use either font case when writing source code, since it does not affect the syntax. While each developer can choose his or her preferred style, some programming languages have standard naming conventions. For example, in Java, the following cases are recommended:
- Classes: PascalCase — class VectorImage {}
- Methods: camelCase — drawImage()
- Variables: camelCase — string newImageName
NOTE: PascalCase is sometimes called "UpperCamelCase," while standard camelCase may be specified as "lowerCamelCase." In recent years, developers have moved away from these terms and use PascalCase and camelCase instead.