Monday, April 28, 2014

Identifiers in Java

Identifiers are names of classes, interfaces, methods, variables and packages.
Must start with:
  • A - Z or a - z                     
  • $  or _ (underscore)
Can also contain:
  • 0-9
Cannot be 
  • null literal
  • boolean literal (true or false)
  • a keyword
No limits on number of characters.
List of keywords:
Note: goto and const are reserved keywords in Java. (They are not used anywhere).
Legal identifiers:
MyClass (Class name)
m1 (Method name)
var (Variable name)
_123 (Not recommended but legal)
$UNLIMITED (Strange)
MAX_VALUE (static final variable)
Illegal identifiers
public (keyword)
123_ (starts with number)
null (null literal)

No comments :

Post a Comment