Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between identifier and keyword

 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whats the difference between identifier and keyword.

I read this "You can use assert as a keyword or as an identifier but not both" What does this mean ?
 
Swati Save
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keywords are reserved words like(static,public......) which has a special meaning for compilers.

Identifier can be name of any variable or any name used to identify an object or entity .hence keywords cannot be used as an identifier



 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a few exceptions, mostly caused by changes during a major Java version upgrade.
- Java 1.4 introduced assertions. "assert" became a keyword. You can turn this off by using the compiler flags (-source 1.3) to use Java 1.3 source compatibility, thereby using the keyword "assert" as an identifier
- Java 5.0 introduced enumerations. "enum" became a keyword. See the above; -source 1.4 allows you to use enum as an identifier.

Both will still show a warning but it will no longer be an error.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic