Naming Conventions and Restrictions


Java gives you a lot of freedom in the names you give to your variables , but there are some conventions and restrictions to keep in mind. A variable name must be a series of Unicode characters that begins with a letter. The name cannot be one of the Java keywords. A list and description of the Java keywords can be found in Appendix A. A variable cannot have the same name as another variable defined in the same scope. Scope is discussed later in this section. All variable names should be as descriptive as possible within reasonable character count limitations. Try to avoid abbreviations where possible except where the abbreviation is commonly used (using t for time is okay for instance).

According to the Java Language Specification, Java variable names should use the camel capitalization style. The first letter of the variable name is lower case. The first letter of subsequent words in the variable name is upper case. The underscore character is permitted but by convention is reserved for constant variable names. An example of a variable name that follows the standard convention would be isVisible rather than isvisible or is_visible .

The names of constant variables (usually just called constants) are by convention written in all capital letters . Distinct words in a constant name are separated by the underscore character (_). An example of a constant name that follows the conventions is GAS_CONSTANT .



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net