Java programming language has its own set of rules and conventions for naming variables. Here's what you need to know:
- Variables in Java are case-sensitive.
- A variable's name is a sequence of Unicode letters and digits. It can begin with a letter, $ or _. However, it's a convention to begin a variable name with a letter. Also, variable names cannot use whitespace in Java.
- When creating variables, choose a name that makes sense. For example, score, number, level makes more sense than variable names such as s, n, and l.
- If you choose one-word variable names, use all lowercase letters. For example, it's better to use speed rather than SPEED, or sPEED.
- If you choose variable names having more than one word, use all lowercase letters for the first word and capitalize the first letter of each subsequent word. For example, speedLimit.
There are 4 types of variables in Java programming language:
- Instance Variables (Non-Static Fields)
- Class Variables (Static Fields)
- Local Variables
- Parameters