An identifier is any name in a Java program. Identifiers are used to denote classes, methods, variables and labels.
An identifier in Java can be composed of a sequence of characters, where a character can be either a letter, a digit, a connecting punctuation (such as underscore _ ) or currency symbol (such as $). Anyway, the first character in an identifier cannot be a digit.
Identifiers in Java are case sensitive. For example; car and Car are two different identifiers.
Examples of legal and illegal identifiers in Java:
car is a legal identifier
Car is a legal identifier
be@home contains the character @ which is not legal in an identifier, so the whole identifier is illegal too.By the way @ is not an operator in Java
deja_vu9 is a legal identifier
total_£ is a legal identifier
total-amount contains the character - which is not legal in an identifier, so the whole identifier is illegal too.(however total-amount could be interpreted as legal expression with two operands.)
$_149 is a legal identifier
names99 is a legal identifier
99names is an illegal identifier, it starts with a digit.
لغة is a legal identifier (In Arabic, means "language" if you are too curious :)
Note: Java programs are written in the Unicode character set, so a letter or digit definition is interpreted accordingly.
No comments:
Post a Comment