File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Literals vs Keywords Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Literals vs Keywords" Watch "Literals vs Keywords" New topic

Literals vs Keywords

Bojan Knezovic
Ranch Hand

Joined: Nov 20, 2003
Posts: 90
What's the difference between literals and keywords - I have read that true, false and null are all literals and not keywords(I always thought the literals are - literals ) and I'm a bit confused here so if someone could shed some light...

[ November 22, 2003: Message edited by: Bojan Knezovic ]
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
JLS Chapters 3.9, 3.10:

The following character sequences, formed from ASCII letters, are reserved for use as keywords and cannot be used as identifiers (�3.8): [the list of keywords goes here]
The keywords const and goto are reserved, even though they are not currently used. This may allow a Java compiler to produce better error messages if these C++ keywords incorrectly appear in programs.
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).

A literal is the source code representation of a value of a primitive type (�4.2), the String type (�4.3.3), or the null type (�4.1):
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

Vad is right -- according to the JLS, "null", "true" and "false" are literals and not keywords.
for the purposes of the exam -- don't worry about it.
From the SCJP 1.4 Exam objectives
Section 4: Language Fundamentals
* Identify all Java programming language keywords. Note: There will not be any questions regarding esoteric distinctions between keywords and manifest constants.

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Bojan Knezovic
Ranch Hand

Joined: Nov 20, 2003
Posts: 90
Vad, Jessica, thank you both. It's good to know these things they're fundamental anyway.

I agree. Here's the link:
subject: Literals vs Keywords
It's not a secret anymore!