File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes True, false and null = keyword or identifier? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "True, false and null = keyword or identifier?" Watch "True, false and null = keyword or identifier?" New topic
Author

True, false and null = keyword or identifier?

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Example:
Which of the following are java keyword?
1) if
2) goto
3) case
4) null
5) true
6) then
For the exam should the right answer should be:
12345or
123??
Thanks
Saritha Pilla
Greenhorn

Joined: Feb 25, 2000
Posts: 15
It should be 12345
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
I Agree.


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
According with http://www.software.u%2dnet.com/J2Tutor/04_03Tut.htm the correct answer is: 1234. "True" and "then" are not keywords in Java.
Rolf Weasel
Ranch Hand

Joined: Feb 26, 2000
Posts: 82
no way! as per the JLS it is 123. null is not a keyword but a null literal. null is also the only null literal. true and false are boolean literals. check out the JLS.


May the Moose be with you.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
goto is a reserved word. So can it be considered as a keyword as far as Exam is concerned.
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
If you don't include <CODE>null</CODE>, <CODE>true</CODE> and <CODE>false</CODE> in Java reserved words, you'll get the question wrong. Don't spend energy trying to split hairs between keywords and literals. They are all reserved.
Rolf Weasel
Ranch Hand

Joined: Feb 26, 2000
Posts: 82
I quote from 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):
Keyword: one of
abstractdefaultifprivatethrow
booleandoimplementsprotectedthrows
breakdoubleimportpublictransient
byteelseinstanceofreturntry
caseextendsintshortvoid
catchfinalinterfacestaticvolatile
charfinallylongsuperwhile
classfloatnativeswitch
constfornewsynchronized
continuegotopackagethis
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).
and the question explicitly says keywords
also, the syllabus states:
Identify all Java programming language keywords and correctly constructed identifiers.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Rolf's post got in just before mine, so now I'm back to agreeing with him (Rolf that is).
Mughal and Rasmussen define null, true and false as "reserved literals" on a table separate from the list of keywords, which led me to believe that they are NOT keywords. Also that question came up on the Jaworski mock test, and that exam did not consider null, true or false to be keywords. Bill Brogden's Java Exam Cram lists these words together with the other keywords in a table called "All Java reserved words". Maybe the wording of the question on the exam will give us a clue (reserved vs keyword) as to the correct answer.
[This message has been edited by Joe Java (edited March 01, 2000).]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hi
according to
http://indigo.ie/~dywalsh/certification/javacert.htm
only 1234 are key words.
and not "true" and "then"
could u be more specific tony.
thanxx
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
More specific? I don't know how to be. Please read my post again and look at the emphasis/fonts used, thanks.
OK: One more time. Forget about the questions "What are Java keywords" and learn only that you cannot use null, true or false as your own identifiers. That's what you will be tested for.
Ramana Namuduri
Greenhorn

Joined: Mar 02, 2000
Posts: 16
I agree with Saritha Pilla.
Jave keywords are those which you cannot use as a variable to store any value for that. So, one cannot create null, true,false variables of whatever may be the type, to contain any value of that type. My answer is 12345
Divakar
Greenhorn

Joined: Mar 01, 2000
Posts: 25
True is not a java keyword.
true is java keyword. I think you haven't noticed the case of t in True.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks!
Going to have the SCJP next week
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: True, false and null = keyword or identifier?