Java Reference
In-Depth Information
An identifier must not be a Java keyword, true , false , or null .
Table 2.1 contains a list of valid and invalid identifi ers to demonstrate these rules.
Let's take a look at the invalid identifi ers:
TABLE 2.1 Java Identifiers
Valid Identifiers
Invalid Identifiers
x1
x 1
True
true
_7_
me@company
_firstName
1stName
car$model
x*y
$color
seven#
x 1 has a space in it, which is not allowed.
true is a reserved word.
me@company contains the @ symbol, which is not a Java letter or digit.
1stName does not start with a Java letter. Identifiers cannot start with a digit.
x*y contains the multiplication operator. Identifiers cannot contain any of the Java
operators.
seven# contains the # symbol, which is also not a Java letter or digit.
Java Tokens
When your source code is compiled, the compiler breaks down your code into tokens
based on the spaces, line feeds, tabs and other separators in your code. There are fi ve
types of tokens in Java:
Separators
Keywords
Literals
Operators
Identifi ers
Because identifi ers are the names you come up with for your variables, classes, fi elds,
methods, interfaces (and so on), the compiler needs to be able to recognize them easily. This
is why Java needs a specifi c set of rules that must be followed for creating legal identifi ers.
 
Search WWH ::




Custom Search