Skip to main content
ICT
Lesson A3 - Primitive Data Types
 
Main Previous Next
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

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.