Identifer versus keyword

前端 未结 5 1590
北海茫月
北海茫月 2021-02-16 00:05

I read in the book for OCJP for Java6 the part with assertions. I reached the part where it gives me an overview of how the compiler reacts if the word \'assert\' is used as key

5条回答
  •  臣服心动
    2021-02-16 00:29

    The terms "keyword" and "identifier" are not Java specific.

    A keyword is a reserved word from the Java keyword list provide the compiler with instructions. As keywords are reserved, they cannot be used by the programmer for variable or method names.

    Examples:

    final
    class
    this
    synchronized
    

    Identifiers are the names of variables, methods, classes, packages and interfaces. They must be composed of letters, numbers, the underscore _ and the dollar sign $. Identifiers may only begin with a letter, the underscore or a dollar sign.

    Examples:

    int index;
    String name;
    

    index and name are valid identifiers here. int is a keyword.

    A keyword cannot be used as an identifier.

提交回复
热议问题