Identifer versus keyword

前端 未结 5 1572
北海茫月
北海茫月 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:23

    Identifiers are names of variables. For example in

    int a = 3;
    

    a would the identifier. Keywords, on the other hand, are reserved (i.e. you can't name a variable with a keyword), pre-defined words that have a specific meaning in the language. For example in

    if (a == 3)
        System.out.println("Hello World");
    

    if is a keyword. It has a specific function and cannot be used as a variable name. Moreover, the words used to declare primitive types are all keywords as well, e.g. int, char, long, boolean etc. You can see a full list of Java keywords here

提交回复
热议问题