• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Keywords ?

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cud somebody clarify my understanding on java keywords by answering these questions. I seem to be lost inbetween the terms "keyword" and "reserved word" .

1 Which of the following are java keywords ?
a> short
b> goto
c> null
d> true
2. Which are java reserved words ?
a> short
b> goto
c> null
d> true

Thanks in advance!
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keywords: short
Reserved words: goto(and to be complete: const)
Special literal values: true, false and null
But I understood this changes overtime...in Brogden's ExamPrep (1999) he mention's 11 reserved words.. For the latest score see JLS I think..
Erik Dark
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a technical difference between a keyword, and a reserved word...but for purposes of the test, you just need to know what the reserved words are.
null, true, and false are reserved words. They are not keywords.
Also, in the RHE study guide, in a footnote, they write "The exam is careful to avoid potentially ambiguous questions that require you to make purely academic distinctions between reserved words and keywords". And since two of the authors actually worked at Sun developing the exam, I will take their word for it on this one!
Nitty Gritty:
---------------
A reserved word is a sequence of characters that obeys the rules of a lexical identifier, but that the compiler will prevent you from using as an identifier for your own objects; ie, you cannot use a reserved word to name your variables, classes, interfaces, etc, because the word has been reserved for use. All keywords are reserved. So are the lexical symbols 'null', 'true', and 'false'.
A keyword is a parsed token that invokes special semantic processing; it is semantically different than an identifier, and appears in your source code in positions that are syntactically distinct from an identifer.
The confusion I think comes because in the JLS section 3.9 states:
Keywords
"The following character sequences, formed from ASCII letters, are reserved for use as keywords and cannot be used as identifiers (3.8) ...(long list omitted)... The keywords const and goto are reserved, even though they are not currently used...While true and false might appear to be keywords, they are technically Boolean literals. Similarly, while null might appear to be a keyword, it is technically the null literal"
For the purpses of the SCJP, they are not going to ask you to understand the differences between keywords and reserved words. The questions will be "which are reserved words in java?"
The following character sequences, formed from ASCII letters, are reserved for use as keywords and cannot be used as identifiers (�3.8):
Keyword: one of
abstract default if private this
boolean do implements protected throw
break double import public throws
byte else instanceof return transient
case extends int short try
catch final interface static void
char finally long strictfp volatile
class float native super while
const for new switch
continue goto package synchronized
Rob
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's not repeat things...
here is a thread where those keyword-reserved words issues are already thoroughly discussed and debated.
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=014367
HIH
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some of those reserved words in the 1999 Exam Prep book were in error. Sun had been using them in pre 1.02 release but dropped them without remarking on it. Tables are corrected for the 2001 editions and there is an errata for the first edition at:
http://www.lanw.com/books/errata/
Bill
 
Erik Dark
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the final (=keyword!) answer must come from Sun! (is 'technically not a keyword' in between 'it is' and 'it isn't' ??)
(William, I already had corrected my '99 copy of ExamPrep.. but still waiting on you to change the errata on my remarks! Nevertheless a great book!)
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cud somebody clarify my understanding on java keywords by answering these questions. I seem to be lost inbetween the terms "keyword" and "reserved word" .
1 Which of the following are java keywords ?
a> short
b> goto
c> null
d> true
2. Which are java reserved words ?
a> short
b> goto
c> null
d> true

Thanks in advance!



For Q1: a,b,c,d
For Q2:b
 
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ruchi Kolla:

For Q1: a,b,c,d
For Q2:b


Ruchi,
You can check your answers against this authoritative source: http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#229308
 
Jennifer Wallace
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got confused regarding this earlier because of the various mock/practise exams I have been taking.
Interestingly, the discussion has confused me more!
Anyway, I think to score in the Sun java Exam
better speak Sun's language !

So, accordingly,
I am writing the answers which I think wud be right as in a Sun exam.
Based on the following Two References I am answering my questions,
1. Sun Online Java Tutorial
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html
2. JLS (as has been pointed out by many others)
http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#229308

1. Which are java keywords ?
a> short
b> goto
c> null
d> true
Ans: a and b
Reason: Simply because 'null' and 'true' dont appear in the list of keywords.

2. Which are java reserved words ?
a> short
b> goto
c> null
d> true

Ans: a,b,c,d
Reason : All keywords, and boolean literals 'true' and 'false' and null literal are reserved in Java.
Please correct me if I am way off mark !
Thanks !
 
Junilu Lacar
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jennifer Wallace:
Interestingly, the discussion has confused me more!
1. Which are java keywords ?
Ans: a and b
2. Which are java reserved words ?
Ans: a,b,c,d


I disagree: You're not at all confused if you got these answers.
BTW, the exam does not require you to make (in the words of RHE) "purely academic distinctions between reserved words and keywords." It is sufficient to know which words are reserved and can't be used as identifiers.
 
Jennifer Wallace
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ITs good to know that I finally got the hang of it.
Well, if confusing is not the word ! then "long and windy" definitely are !
But, I have been learning so much since i found JavaRanch and from the so many Discussions !
Thanks to all for their time!
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jennifer Wallace:

1. Which are java keywords ?
a> short
b> goto
c> null
d> true
Ans: a and b
Reason: Simply because 'null' and 'true' dont appear in the list of keywords.

2. Which are java reserved words ?
a> short
b> goto
c> null
d> true

Ans: a,b,c,d
Reason : All keywords, and boolean literals 'true' and 'false' and null literal are reserved in Java.
Please correct me if I am way off mark !
Thanks !



Nope, you are right on target.
And, welcome to the land of ranch-hands Jennifer!


Rob
 
Ruchi Kolla
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Junilu Lacar:

Ruchi,
You can check your answers against this authoritative source: http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#229308



Hi Junilu Lacar
Thanks for correcting me. I have a book of RHE(which is First edition-1999 give by some one to me ...i mean not the latest one of the authors).In that book on Page 6 they have kept true,null etc in the table of java keyword..so I was sure while answering the question.
but thanks for correcting me. I am wondering but how can authors write it this way...anyway I am happy that I got the corrected.
This is the advantage of this group.
Thanks again.
 
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic