Identifiers

by Michael Thomas

(Tutorial Home Page)

by Michael Thomas

(Tutorial Home Page)

Topic Notes
Identifiers

Rules for Legal Identifiers

  • Definition:  Letter = (A-Z, a-z or '$' or '_' )
  • Definition:  Digit = ( 0 -9 )
  • An identifier is a series of characters consisting of letters, digits, underscores(_) and dollar signs ($) that does not begin with a digit, does not contain any spaces and is not a keyword.
    • Must begin with a letter, '$', or "_".
    • After the first char, any char that is a letter (including '$' or '_') or digit may be used. 
    • Cannot be a reserved word (aka keyword).
    • No spaces are allowed in the identifier.
    • Cannot have a Java operator symbol (because not a letter or digit).
    • No limit to the number of letters & digits (0 - 9).
  • Unicodes & Identifiers - you may also use the Unicode form to build an identifier.  Valid Unicodes are from \u00c0 to \uD7A3 .  Therefore, international alphabets can be used also via the Unicode character set.  However, I suggest not using Unicodes!
  • Uses of  Identifiers - are used to create names for variables (primitive or object references), methods, classes, interfaces, etc...

(Note: For a naming convention, use '$' to access legacy code (old code that does not follow good naming conventions) or code that automatically generates identifiers on the fly.)

Examples of Identifiers

Legal Identifiers

  • $Test
  • _test
  • test_test
  • test$test
  • test2
  • t2example
  • _5_
  • $5$
  • \u0041Test   (ie  ATest)
  • Test\u0041 
    (ie   TestA)

Illegal Identifiers

  • 2test
  • #test
  • test#test
  • @test
  • test+test
  • test*test
  • test(test