the true literal

S

Stefan Ram

The JLS says:

»While true and false might appear to be keywords,
they are technically Boolean literals (§3.10.3).«

What is a keyword?

I used to think that a keyword is a words whose meaning is
given by the language specification and that cannot be
declared as an identifier in source code. I believe that all
of this applies to »true«. So, why then it is not called a
keyword in Java?
 
A

Arne Vajhøj

The JLS says:

»While true and false might appear to be keywords,
they are technically Boolean literals (§3.10.3).«

What is a keyword?

I used to think that a keyword is a words whose meaning is
given by the language specification and that cannot be
declared as an identifier in source code. I believe that all
of this applies to »true«. So, why then it is not called a
keyword in Java?

It is a literal like 123, 123.456 and "ABC" - possible values
of a type.

In the language syntax they work exactly like other literals.

The only difference is that they also happen to be valid keyword or
name.

But I think their place in the syntax is the determining factor.

Arne
 
J

Joerg Meier

The JLS says:
»While true and false might appear to be keywords,
they are technically Boolean literals (§3.10.3).«
What is a keyword?
I used to think that a keyword is a words whose meaning is
given by the language specification and that cannot be
declared as an identifier in source code. I believe that all
of this applies to »true«. So, why then it is not called a
keyword in Java?

I would say a keyword is part of the language syntax - return, if, switch,
that kind of thing. true and false are, like Arne mentioned, more or less
normal literals - they are autoboxed to Boolean.TRUE and Boolean.FALSE,
which are normal final fields. In that sense, they seem most similar to
'f', 'l' or '0x' - something the compiler is hard coded to translate to
something in order to make writing it more convenient.

Liebe Gruesse,
Joerg
 
M

markspace

The JLS says:

»While true and false might appear to be keywords,
they are technically Boolean literals (§3.10.3).«

What is a keyword?

I used to think that a keyword is a words whose meaning is
given by the language specification and that cannot be
declared as an identifier in source code. I believe that all
of this applies to »true«. So, why then it is not called a
keyword in Java?


I think maybe this is an issue for language purists, but if you think of
'true' and 'false' as values, then obviously they're literals. Keywords
have no value, and can't be assigned or used in an expression.

int i = for;

Makes no sense. + and - aren't keywords, they're operators. Different
word again for different thing. So 'true' might look like a keyword,
but it's really like 1 or 3.0 or null. It represents a value that can
be assigned or used in an expression.

true | false;
 
J

Jeff Higgins

The JLS says:

»While true and false might appear to be keywords,
they are technically Boolean literals (§3.10.3).«

What is a keyword?

I used to think that a keyword is a word(s)

You'll need to adjust your intuition.

-------------------------------------------------------------
whose meaning is given by the language specification

3.10.3. Boolean Literals

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

BooleanLiteral: one of
true false

A boolean literal is always of type boolean (§4.2.5).

------------------------------------------------------------
and that cannot be declared as an identifier in source code.

3.8. Identifiers

An identifier is an unlimited-length sequence of Java letters and Java
digits, the first of which must be a Java letter.


Identifier:
IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral

----------------------------------------------------------------
I believe that all of this applies to »true«.

The meaning of true is given in the JLS.
A BooleanLiteral cannot be used as an Identifier.

------------------------------------------------------------

So, why then it is not called a keyword in Java?

3.9. Keywords

50 character sequences, formed from ASCII letters, are reserved for use
as keywords and cannot be used as identifiers (§3.8).


Keyword: one of
abstract continue for new switch
assert default if package synchronized
boolean do goto private this
break double implements protected throw
byte else import public throws
case enum instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp volatile
const float native super while

Because it is a boolean literal?

boolean t_;
if ( !t_ )
t_ = true;
 
E

Eric Sosman

[...]
3.9. Keywords

50 character sequences, formed from ASCII letters, are reserved for use
as keywords and cannot be used as identifiers (§3.8).

Keyword: one of
abstract continue for new switch
assert default if package synchronized
boolean do goto private this
break double implements protected throw
byte else import public throws
case enum instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp volatile
const float native super while

Note the absence of `null' from this list. The situation
seems very similar to that of `true' and `false': all three
are "literals" rather than "keywords". These literals happen
to be spelled entirely with letters rather than with arcane
symbol clusters like `314.159e-2', but they're still "literals".

To me, this seems a good example of a "difference that makes
no difference" -- but a hair-splitting literal-ist (sorry) might
find a difference just so he can feel smug about it.
 
J

Jeff Higgins

[...]
3.9. Keywords

50 character sequences, formed from ASCII letters, are reserved for use
as keywords and cannot be used as identifiers (§3.8).

Keyword: one of
abstract continue for new switch
assert default if package synchronized
boolean do goto private this
break double implements protected throw
byte else import public throws
case enum instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp volatile
const float native super while

Note the absence of `null' from this list. The situation
seems very similar to that of `true' and `false': all three
are "literals" rather than "keywords". These literals happen
to be spelled entirely with letters rather than with arcane
symbol clusters like `314.159e-2', but they're still "literals".

To me, this seems a good example of a "difference that makes
no difference" -- but a hair-splitting literal-ist (sorry) might
find a difference just so he can feel smug about it.
I wish I had found <http://en.wikipedia.org/wiki/Reserved_word>
before I had first responded to the OP. I think it will be a
satisfactory answer to his question.

In general discussion, including usenet, a hair-splitting literal-ist
(ok?) stance can be taken, and motivated by smug. Specification writers,
compiler writers, general purpose program writers,and others might
have other motivations. I'm certain that Stefan Ram was not seeking an
answer to his question in preparation to take a smug stance in some
discussion. My motivation to respond to Stefan's question was not smug,
even if it appeared hair-splitting and literalist. Other respondents
have not come off as smug to me. The (online) Free Dictionary has
literalist as a noun and literalistic as an adjective.
 
E

Eric Sosman

[...]
To me, this seems a good example of a "difference that makes
no difference" -- but a hair-splitting literal-ist (sorry) might
find a difference just so he can feel smug about it.
[...]
In general discussion, including usenet, a hair-splitting literal-ist
(ok?) stance can be taken, and motivated by smug. Specification writers,
compiler writers, general purpose program writers,and others might
have other motivations. I'm certain that Stefan Ram was not seeking an
answer to his question in preparation to take a smug stance in some
discussion. My motivation to respond to Stefan's question was not smug,
even if it appeared hair-splitting and literalist. Other respondents
have not come off as smug to me. The (online) Free Dictionary has
literalist as a noun and literalistic as an adjective.

Jeff, I intended to apply the word "smug" to the writers
of the JLS, not to you nor to Stefan nor to anyone else in
this thread. If my post came across as insulting, I humbly
crave pardon; I should know by now that Usenet does not always
convey nuance well, and should not have expected that wryness
would come across as such.
 
J

Jeff Higgins

[...]
To me, this seems a good example of a "difference that makes
no difference" -- but a hair-splitting literal-ist (sorry) might
find a difference just so he can feel smug about it.
[...]
In general discussion, including usenet, a hair-splitting literal-ist
(ok?) stance can be taken, and motivated by smug. Specification writers,
compiler writers, general purpose program writers,and others might
have other motivations. I'm certain that Stefan Ram was not seeking an
answer to his question in preparation to take a smug stance in some
discussion. My motivation to respond to Stefan's question was not smug,
even if it appeared hair-splitting and literalist. Other respondents
have not come off as smug to me. The (online) Free Dictionary has
literalist as a noun and literalistic as an adjective.

Jeff, I intended to apply the word "smug" to the writers
of the JLS, not to you nor to Stefan nor to anyone else in
this thread.

If I were in a cafe eating and drinking with a group that included
writers of the JLS I would tolerate a smug attitude up to a point.
The JLS is a fine specification as specifications go.
If my post came across as insulting, I humbly
crave pardon; I should know by now that Usenet does not always
convey nuance well, and should not have expected that wryness
would come across as such.

I appreciate the wryness, and other fine qualities of your posts
to this group. I hate smug posts, and try hard (perhaps not always
successfully) not to produce one. A lot of coffee this AM, may be
time for a sandwich an a more soothing beverage.
 
R

Roedy Green

So, why then it is not called a
keyword in Java?

If you looked at a railway diagram of the Java syntax, there is likely
a place where keywords without true and false can be treated
identically.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

literals and keywords 8
What is a literal? 12
Trying to return true if a sub array exists at given index 1
The True Religion 0
The True Religion 3
The True Religion 0
Compound literal without initializer? 3
Java 1

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top