Package names in java are written in all small letters.
Ex:- java.awt, java.io
Each word of class names and interface names start with a capital.
Ex:- String
Method names start with a small letter, then each word start with a capital.
Ex:- println( ), readLine( )
Variable names also follow the above rule.
Ex:- age, empName
Constants should be written using all capital letters.
Ex:- PI
All keywords should be written in all smaller letters.
Ex:- public, void
Choosing a variable name:
The best naming convention is to choose a variable name that will tell the reader of the program what the variable represents. Variable names that describe the data stored at that particular memory location are called mnemonic variables. For example, if you wish to store a grade on a test, a variable name such as grade would be more easily remembered than a variable name such as var2.
Rules for naming variables:
- All variable names must begin with a letter of the alphabet, an underscore, or ( _ ), or a dollar sign ($). The convention is to always use a letter of the alphabet. The dollar sign and the underscore are discouraged.
- After the first initial letter, variable names may also contain letters and the digits 0 to 9. No spaces or special characters are allowed.
- The name can be of any length, but don't get carried away. Remember that you will have to type this name.
- Uppercase characters are distinct from lowercase characters. Using ALL uppercase letters are primarily used to identify constant variables. Remember that variable names are case-sensitive.
- You cannot use a java keyword (reserved word) for a variable name.
No comments:
Post a Comment