aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes r they keywords or literals? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "r they keywords or literals?" Watch "r they keywords or literals?" New topic
Author

r they keywords or literals?

Shubhada Nandarshi
Ranch Hand

Joined: Jun 10, 2005
Posts: 59
Hi friends,

In many of the books & on various sites it is mentioned that 'true','false' and 'null' are keywords. But I think they are literals because we use them as a literals. What is ur opinion?
waiting for ur reply...


Shubha. :roll:


Shubhada
Shalini Chandel
Ranch Hand

Joined: May 05, 2005
Posts: 115
thats right Shubha,

true, false and null are not the keywords but are reserved words.
You cannot use them for identifier.

regards,
Shalini


SCJP 1.4
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

Per the JLS, they're literals.

�3.10.3 Boolean Literals
The boolean type has two values, represented by the literals true and false, formed from ASCII letters.

A boolean literal is always of type boolean.

BooleanLiteral: one of
true false

�3.10.7 The Null Literal
The null type has one value, the null reference, represented by the literal null, which is formed from ASCII characters. A null literal is always of the null type.

NullLiteral:
null


Hope this helps...
Shubhada Nandarshi
Ranch Hand

Joined: Jun 10, 2005
Posts: 59
But why they are included in keywords?
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

But why they are included in keywords?
They're not.

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html
Sachin Dangi
Greenhorn

Joined: Aug 31, 2003
Posts: 17
In the exam objectives it is mentioned that these type of questions will not be asked. Exam Objectives
Identify all Java programming language keywords. Note: There will not be any questions regarding esoteric distinctions between keywords and manifest constants.
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

In the exam objectives it is mentioned that these type of questions will not be asked.
Good point. If you're curious about these things, though, you can always look to the JLS...

�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):



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).

[ June 21, 2005: Message edited by: Steve Morrow ]
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8764
    
    5
Sachin is correct - it's good to know, but it's not on the exam!


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
Steve post about the 48 keywords ....its actually 49 keywords since "assert" is also a keyword now.

but "assert" can be used as a keyword or as an identifier, but not both. as according to K&B book.

in version 1.4, if we enable the assertion at compile time, then "assert" can't be as a identifier, but it is now act as a keyword since assertion are enabled at compile time.

also in version 1.4, assertion are disabled by default. the compiler will act as 1.3 and "assert" can be used as identifier.

correct me if i'm wrong. thanks in advance.


From NickyEng
Diploma in Computer Studies
SCJP 1.4
SCWCD 1.4
Formula 1 app by Maxis (Playbook)
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1511
K & B clearly says about the three

According to the Java Language Specification, null, true, and false are
technically literal values (sometimes referred to as manifest constants) and not keywords. Just as with the other keywords, if you try to create an identifier with one of these literal values, you�ll get a compiler error. For the purposes of the exam , treat them just as you would the other reserved words. You will not be asked to differentiate between reserved words and these reserved literals.


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1511
K & B clearly says about the three

According to the Java Language Specification, null, true, and false are
technically literal values (sometimes referred to as manifest constants) and not keywords. Just as with the other keywords, if you try to create an identifier with one of these literal values, you�ll get a compiler error. For the purposes of the exam , treat them just as you would the other reserved words. You will not be asked to differentiate between reserved words and these reserved literals.
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608

its actually 49 keywords since "assert" is also a keyword now.

its actually 50 since "enum" is also a keyword now.


Tony Morris
Java Q&A (FAQ, Trivia)
Karthikeyan Varadarajan
Ranch Hand

Joined: Jul 04, 2002
Posts: 98
its actually 50 since "enum" is also a keyword now


enum is a keyword ? is it scjp 1.5 or scjp1.4?


~With Smile<br />VK
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
[Karthikeyan]: enum is a keyword ? is it scjp 1.5 or scjp1.4?

enum is a keyword in JDK 5.0/1.5 and questions on enum will be asked in SCJP 1.5. Have a look at the list of keywords in JLS 3.0.
[ June 29, 2005: Message edited by: Joyce Lee ]
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
"u", "r", and "ur" (among others) are not keywords of the English language and therefore using them as such leads to syntactically incorrect English.
Such English does not compile and will be simply ignored by well designed brains.


42
Rick O'Shay
Ranch Hand

Joined: Sep 19, 2004
Posts: 531
Are these keywords? Seems like Java knows about 'em:

1
2
5.8
'X'

I'm thinking... hell no; they're obviously literal values, like these, albeit less obvious:

true
false
null
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: r they keywords or literals?
 
Similar Threads
need clarification about true, false and null
Key Words
Java keywords
keyword
Is null a keyword?