File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Difference between identifier and keyword Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Difference between identifier and keyword" Watch "Difference between identifier and keyword" New topic

Difference between identifier and keyword

jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
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

Joined: Mar 06, 2010
Posts: 14
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

Joined: Oct 27, 2005
Posts: 20273

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.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Difference between identifier and keyword
It's not a secret anymore!