• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Keywords, reserved words and operators

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
G'day all!
These mock exams can get really frustrating ...
First I got a question wrong for saying instanceof IS a keyword (they argue it's not a keyword but an OPERATOR) ... so when I came across a similar question again I was confident to say it's not a keyword ... bang! wrong again! This time the author of the mock exam says it is a keyword ... and it must be, since it is in the list of keywords in the Java specification ... but it sure is an operator too ... for my own peace of mind I'm gonna look at it this way: the sequence of characters "instanceof" IS a keyword and it runs the instanceof operator when invoked ... if that makes any sense ...
As for true, false and null, after reading through previuos topics in this forum and the Java specification I came to this conclusion:
they are not KEYWORDS, they are literals and RESERVED WORDS ... BUT for the purpose of the exam you should consider them as keywords ...
that doesn't sound right to me ... if they're not keywords they're not keywords, end of story ... but previous topics on this subject are making be believe that for the exam I should think of them as such ...

So what do people out there reckon??
thanks
L.
 
stable boy
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As for instanceof this IS a keyword
true, false and null are NOT keywords they are literals. They represent a certain value.
I think the JLS is very clear about these cases: http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#229308
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For purposes of the SCJP exam, you do not need to make the differentiation between literals, keywords, and operators - you only need to know what the reserved words are.
For example, it's not essential that you realize true is a literal and not a keyword - just knowing that you can't use it as a variable name, etc. it enough.
I even found this little blurb amongst the exam objectives:


Identify all Java programming language keywords. Note: There will not be any questions regarding esoteric distinctions between keywords and manifest constants.


Corey
[ March 31, 2004: Message edited by: Corey McGlone ]
 
Lionel Orellana
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Identify all Java programming language keywords


So if you get something like:
Wich of these are java Keywords:
a) true
b) private
c) null
d) const
The answer is b,c .... that means you DO need to know that true and null are not keywords but literals ... so it's not enough just to know you can't use them as variables names ...
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lionel Orellana:

The answer is b,c ....


Actually, I believe the answer would be a, b, and c. Like that statement from the objectives says, you need not differentiate between keywords and constants - you only need to know which words are reserved. true, private, and null would all fall into that category.
Corey
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
excuse me, but for the example that Lionnel gave i think answers are
/b and /d
a and c are just literals!
what do you think?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lionel Orellana:

a) true
b) private
c) null
d) const


Ok, let me try to get this straight (and correct an error is my previous statement).
true and null are literals (as shown in the JLS, §3.10.3 Boolean Literals and §3.10.7 The Null Literal).
private and const are keywords (as shown in the JLS, §3.9 Keywords.
Foolishly, I forgot to include const as a keyword in Java earlier. const has no special meaning in Java, but it is included as a keyword to make Java more compatible with C/C++, which uses that keyword.
However, as I pointed out earlier, it states in the exam objectives that "There will not be any questions regarding esoteric distinctions between keywords and manifest constants." Therefore, it is not important to know that true and null are literals while private and const are keywords. Rather, it is sufficient, for the purpose of the SCJP exam, to know that all four are "reserved words" in Java and have a special meaning.
Corey
 
Bartender
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
don't forget the keyword "moose" it is a friendly keyword that can be used to decorate classes and methods. It makes the class or method move slowly and writes random messages to the screen about animal rights.

[ April 01, 2004: Message edited by: The Moose ]
 
Lionel Orellana
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it is sufficient, for the purpose of the SCJP exam, to know that all four are "reserved words" in Java and have a special meaning


Corey, that's exactly my problem. The question says "Which of these are java KEYWORDS" not RESERVED WORDS. So why should I include true and null in the answer??
Sorry to be so anal about this, but I don't understand why, for the purpose of the exam only, I should pretend some things are KEYWORDS when they're not. It just doesn't make sense.
By the way, in my sample question I meant to choose private and const as the only KEYWORDS.
Cheers
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lionel Orellana:

Wich of these are java Keywords:
a) true
b) private
c) null
d) const


According to the exam objectives, you should not get a question like this.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The point I've been trying to make, and Miles pointed out, as well, is that this question would never appear on the exam. You would never be asked which are keywords and which are literals - you'd only be asked which are reserved words.
I'm not asking you to "pretend" things are keywords - the exam will never ask which of these strings are keywords - the exam will only ask which are reserved words - keywords and literals fall into reserved words.
Corey
 
Good night. Drive safely. Here's a tiny ad for the road:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic