tags:

views:

299

answers:

3

Are true and false keywords in Java?

+15  A: 

No. true and false are literals.

Warrior
A: 

No, but they're reserved.

Giovanni Galbo
+21  A: 

Here's the complete list of Java Language Keywords. In particular, note that

true, false, and null might seem like keywords, but they are actually literals; you cannot use them as identifiers in your programs.

Zach Scrivena
Can you explain the difference?
Tim Matthews
It's syntactical. Literals represent values, like "Hello" and 42, whereas keywords don't.
Zach Scrivena
OK but why isn't true,false,null a keyword as well as a literal?
Tim Matthews
"Keywords" and "literals" are mutually exclusive, by their definition.
Zach Scrivena
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
Thanks Zach. Now bookmark the link, it will refrain you from posting lot of other questions.
Adeel Ansari
@CAD1337: what would be gained if they where keywords?
Joachim Sauer