Are true
and false
keywords in Java?
+21
A:
Here's the complete list of Java Language Keywords. In particular, note that
true
,false
, andnull
might seem like keywords, but they are actually literals; you cannot use them as identifiers in your programs.
Zach Scrivena
2009-02-23 01:15:11
Can you explain the difference?
Tim Matthews
2009-02-23 01:23:21
It's syntactical. Literals represent values, like "Hello" and 42, whereas keywords don't.
Zach Scrivena
2009-02-23 01:26:41
OK but why isn't true,false,null a keyword as well as a literal?
Tim Matthews
2009-02-23 01:36:08
"Keywords" and "literals" are mutually exclusive, by their definition.
Zach Scrivena
2009-02-23 01:39:59
i the java language specification, it says "The tokens are the identifiers (§3.8), keywords (§3.9), literals (§3.10), separators (§3.11), and operators (§3.12) of the syntactic grammar.". so by saying "false, ..." is not a keyword, that maybe simplifies matters. i dunno
Johannes Schaub - litb
2009-02-23 01:55:44
Thanks Zach. Now bookmark the link, it will refrain you from posting lot of other questions.
Adeel Ansari
2009-02-23 02:03:54
@CAD1337: what would be gained if they where keywords?
Joachim Sauer
2009-04-15 11:36:15