Skip to main content
ICT
Lesson A3 - Primitive Data Types
 
Main   Previous Next
 

A. Identifiers in Java page 3 of 14

  1. An identifier is a name that will be used to describe classes, methods, constants, variables; anything a programmer is required to define.

  2. The rules for naming identifiers in Java are:

    • Identifiers must begin with a letter.
    • Only letters, digits, or an underscore may follow the initial letter.
    • The blank space cannot be used.
    • Identifiers cannot be reserved words. Reserved words or keywords are already defined in Java. These include words such as new, class, int, etc. See Handout A3.1, Reserved Words in Java

    Java is a case sensitive language. That is, Java will distinguish between upper and lower case letters in identifiers. Therefore:

    grade and Grade are different identifiers

  3. Be careful both when naming identifiers and when typing them into the code. Be consistent and don’t use both upper and lower case names for the same identifier.

  4. A good identifier should help describe the nature or purpose of whatever it is naming. For a variable name, it is better to use

    grade instead of g, number instead of n.

  5. However, avoid excessively long or "cute" identifiers such as:

    gradePointAverageForStudentsAToZ
    or bigHugeUglyNumberThatIsPrettyPointlessButINeedItAnyway

Remember that the goal is to write code that is professional in nature; other programmers need to understand your code.

  1. Programmers will adopt different styles of using upper and lower case letters in writing identifiers. The reserved keywords in Java must be typed in lower case text, but identifiers can be typed using any combination of upper and lower case letters.

  2. The following conventions will be used throughout this curriculum guide:

    • A single word identifier will be written in lower case only. Examples: grade, number, sum.
    • Class names will begin with upper case. Examples: String, DrawingTool, SketchPad, Benzene.
    • If an identifier is made up of several words, all words beyond the first will begin with upper case. Examples: stringType, passingScore, largestNum, DrawHouse, SketchPad.
    • Identifiers used as constants will be fully capitalized. Examples: PI, MAXSTRLEN.

 

Main   Previous Next
Contact
 © ICT 2006, All Rights Reserved.