• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Manifest Constants

 
Philani Dlamini
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that (K&B book) on the exam we wont be asked to make esoteric dinstictions between keywords and manifest consants: null,true & false.
i assumed the JVM identifies keywords by boldfacing them(if theres such a thing) and this is what happens with manifest constans as well.
why not just make them keywords, anyone with a clue?
 
Serge Plourde
Ranch Hand
Posts: 140
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that (K&B book) on the exam we wont be asked to make esoteric dinstictions between keywords and manifest consants: null,true & false.
i assumed the JVM identifies keywords by boldfacing them(if theres such a thing) and this is what happens with manifest constans as well.
why not just make them keywords, anyone with a clue?


I don't think it is the JVM that handles this but rather the compiler.

null, true and false are not constants but literals of the boolean type and the null type, as stated below.

The keywords help the compiler to parse the code with the different elements of the language, and the literals are used to assign values. So, I don't think that you can mix those two different things up.

From the JLS (Java Language Specirication, 3rd ed):

3.9 Keywords
The following character sequences, formed from ASCII letters, are reserved for use as keywords and cannot be used as identifiers (�3.8)... While true and false might appear to be keywords, they are technically Boolean literals (�3.10.3). Similarly, while null might appear to be a keyword, it
is technically the null literal (�3.10.7).


... then
a literal is the source code representation of a value of a primitive type, the String type, or the null type.


You can read the JLS, especially chapter 3: Lexical Structure. I think it helps in understanding that.
 
Philani Dlamini
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
3.9 Keywords
The following character sequences, formed from ASCII letters, are reserved for use as keywords and cannot be used as identifiers (�3.8)... While true and false might appear to be keywords, they are technically Boolean literals (�3.10.3). Similarly, while null might appear to be a keyword, it
is technically the null literal (�3.10.7).

The above helps solidify my understanding, thank you very much.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic