This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

keyword doubt

 
Janet Yap
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Which of the following are Key-words in java ???.
1)switch
2)class
3)extends
4)null
5)true
6)goto
7)const
8)implements

I know that
case1:: 6),7) are reserved words , so can we include it into key words ???
case2:: 4) is string literals and 5) is boolean literals. can we include it into keywords???
case3:: 1),2),3),8) are keywords

But my doubt is mainly in case1 and case2. I have gone through so many tests but everywhere i have found different things so please anybody help me. I am taking the exam in the next week.

Thanx
sp
 
Sanjay Mishra
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am pasting the list of Keywords from the Java Language Specifications (JLS). This list very much contains "goto" and "const".
Consult JLS when in doubt for these kind of questions.
Keyword:
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
The keywords const and goto are reserved, even though they are not currently used.
Regards
Sanjay
 
Sagar Sharma
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

all are java keywords
refer Phillip Heller's book on JAVA 2 Certification
 
sankar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi SP,
I think it is better to understand difference between the Keywords and Reserved word. The reserved words are set of words defined by the language and the user cannot use those words other then specified purpose.
The Keywords are the reserved words that are currently used by that language version, like Java 2.0 does not support the use of goto and const. But the persons who developed jave have defined these words meaning that it may be made possible to be used by some other versions.
Hope this will clear u'r doubt

So the case one is ruled out. coming to the case 2, the literals null, true and false are not considered as reserved words.

 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ...
Think the confusion with null, true and false occurs because you can't use them as identifiers but they are not keywords.


JLS §3.8


An identifier cannot have the same spelling (Unicode character
sequence) as a keyword (�3.9), boolean literal (�3.10.3), or the null literal (�3.10.7).

 
Rajiv Kannan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi sp,
This is from JLS.
The keywords const and goto are reserved by Java, even though they are not currently used in Java. This may allow a Java compiler to produce better error messages if these C++ keywords incorrectly appear in Java 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).

sanjay
Originally posted by sp:

Which of the following are Key-words in java ???.
1)switch
2)class
3)extends
4)null
5)true
6)goto
7)const
8)implements

I know that
case1:: 6),7) are reserved words , so can we include it into key words ???
case2:: 4) is string literals and 5) is boolean literals. can we include it into keywords???
case3:: 1),2),3),8) are keywords

But my doubt is mainly in case1 and case2. I have gone through so many tests but everywhere i have found different things so please anybody help me. I am taking the exam in the next week.

Thanx
sp

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic