This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

r they keywords or literals?  RSS feed

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thats right Shubha,

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

regards,
Shalini
 
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But why they are included in keywords?
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But why they are included in keywords?

They're not.

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
author
Posts: 8995
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sachin is correct - it's good to know, but it's not on the exam!
 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Akhilesh Trivedi
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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


its actually 50 since "enum" is also a keyword now.
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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



enum is a keyword ? is it scjp 1.5 or scjp1.4?
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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 ]
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!