Difference between Camel Case, Pascal Case, Snake Case and Kebab Case

In any programming language, naming conventions are a very important best practice to follow. Different parts of a program are written in specific cases so they can communicate easily their purpose in the source code.

This short article lists some popular casings such as camel case, pascal case, snake case, and kebab case along with a few other casings with respective examples. We also will compare these cases to understand which one to use in which case, generally.

Casing StyleExampleCharacteristicsWhen to Use?
Camel CasecamelCaseExampleThe first word starts in lowercase, and then all words capitalizedmethod names, variable names in Java
Pascal CasePascalCaseExampleAll words capitalizedclass names, interface names in Java
Snake Casesnake_case_exampleWords (in lowercase) separated by underscoresmethod names, variable names in Python
Kebab Casekebab-case-exampleWords (in lowercase) separated by hyphensURLs, file names, and CSS class names
Upper Snake Case /
Screaming Snake Case
SCREAMING_SNAKE_CASE_EXAMPLEWords (in UPPERCASE) separated by underscoresConstants
Upper Kebab Case / Screaming Kebab CaseUPPER-KEBAB-CASE-EXAMPLEWords (in UPPERCASE) separated by hyphensSimilar to kebab case but with uppercase letters

Let us understand each case in more detail.

1. Camel Case

Camel case is characterized by having the first word lowercase and subsequent words capitalized. The words are written without any separators between words. Camelcase is commonly used for naming variables and method names in programming languages like JavaScript, Java, and C#.

  • The first word starts with a lowercase letter.
  • Subsequent words are capitalized.
  • No spaces or punctuation between words.
getItem()
findAtIndex()
calculateTotalAmount()
userId

2. Pascal Case

Pascal case, also known as Upper Camel Case, recommends the first letter of each word to be capitalized, including the first word. There are no spaces or punctuation between words. Pascal case is commonly used for naming classes, interfaces, and types in languages like Java, C#, and TypeScript.

  • All words are capitalized.
  • No spaces or punctuation between words.
ArrayList
HashMap
WebDriver

3. Snake Case

Snake case is quite popular in Python. It recommends writing the words in lowercase letters and separated by underscores (_). We can use this casing for writing the variables, functions, and file names in Python and other scripting languages.

  • Words are written in lowercase letters.
  • Words are separated by underscores (_).
data_set
user_id
calculate_total_amount

4. Kebab Case

Kebab case, also known as spinal case or dash case, recommends writing the words in lowercase letters and separated by hyphens (-). It is often used for naming variables, file names, and CSS class names in web development, particularly in HTML, CSS, and JavaScript.

  • Words are written in lowercase letters.
  • Words are separated by hyphens (-).
div-height-css
span-id
calculate-total-amount

5. Screaming Snake Case

In Screaming Snake Case, all letters are in uppercase and the words are separated by underscores (_). It is commonly used for constants or configuration variables in programming languages such as Java and C#.

  • Words are written in uppercase letters.
  • Words are separated by underscores (_).
MY_ERROR_CODE
MY_CONSTANT_NAME

6. Screaming Kebab Case

The screaming kebab casing requires to write all the words in uppercase letters and separated by hyphens (-). Similar to the screaming snake case, this casing is also used for constants but in environments where hyphens are preferred over underscores.

  • Words are written in uppercase letters.
  • Words are separated by hyphens (-).
UPPER-KEBAB-CASE-EXAMPLE
MY-VARIABLE-NAME
CALCULATE-TOTAL-AMOUNT

7. Conclusion

This short tutorial discussed some popular casings used in programming languages. We discussed what these casings look like, and their characteristics with examples. We also learned when to use which casing in a programming language, as a general best practice.

Happy Learning !!

Comments

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.