Java identifiers find all valid identifiers

Question

What are valid identifiers:

miles, Test, a++, --a, 4#R, $4, 
#44, apps, class, 
public, int, x, y, radius 


miles  //valid
Test   //valid
a++    //not valid
--a    //not valid
4#R    //not valid, cannot start with number
$4     //valid
#44    //not valid
apps   //valid
class  //not valid, keyword
public //not valid, keyword
int    //not valid, type name
x      //valid
y      //valid
radius //valid

Note

Rules for creating valid identifiers:

  • An identifier is a sequence of characters that consists of letters, digits, underscores _, and dollar signs $.
  • An identifier must start with a letter, an underscore _, or a dollar sign $.
  • An identifier cannot start with a digit.
  • An identifier cannot be a reserved word.
  • An identifier cannot be true, false, or null.
  • An identifier can be of any length.

Since Java is case sensitive, area, Area, and AREA are all different identifiers.




PreviousNext

Related