• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

r they keywords or literals?

 
Shubhada Nandarshi
Ranch Hand
Posts: 59
  • 0
  • 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:
 
Shalini Chandel
Ranch Hand
Posts: 115
  • 0
  • 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
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
 
Sachin Dangi
Greenhorn
Posts: 17
  • 0
  • 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
  • 0
  • 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 ]
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • 0
  • 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!
 
Nicky Eng
Ranch Hand
Posts: 378
  • 0
  • 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.
 
Akhilesh Trivedi
Ranch Hand
Posts: 1599
  • 0
  • 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: 1599
  • 0
  • 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.
 
Tony Morris
Ranch Hand
Posts: 1608
  • 0
  • 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.
 
Karthikeyan Varadarajan
Ranch Hand
Posts: 98
  • 0
  • 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?
 
Joyce Lee
Ranch Hand
Posts: 1392
  • 0
  • 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 ]
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • 0
  • 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.
 
Rick O'Shay
Ranch Hand
Posts: 531
  • 0
  • 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 agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic