• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

keyword vs reserved word

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the difference between a key word and a reserved word.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JLS - 3.9 Keywords...

The keywords const and goto are reserved, even though they are not currently used. This may allow a Java compiler to produce better error messages if these C++ keywords incorrectly appear in programs.

 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The way I understand it:
Reserved words are those words that the Java langauge restricts you from use as the names of variables, classes, methods etc.

Keywords are reserved words that have special meaning within the Java, such as abstract, class and private.

So while you use keywords to define your Java code you can NEVER use reserved words.

At least thats my understanding.
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say they can be used interchangeably. Here's a link.
 
Rao Raghu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for your replies.

 
Marshal
Posts: 75666
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quoted by Anupham Sinha:-

I would say they can be used interchangeably. Here's a link.

No, they are not synonymous. It says specifically on the list of keywords on that list that "null" "true" and "false" are "literals." That means they have symantic content; they actually represent a value.

A reserved word is one which can only be used in a pre-specified context.

Keywords control the flow and running of the programming; they are a little like operators in that respect.

All the keywords in Java are reserved words in the respect that they can only be used in the context they are designed for.
 
Campbell Ritchie
Marshal
Posts: 75666
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quoted by Gavin Tranter:-

So while you use keywords to define your Java code you can NEVER use reserved words.

Yes, you do. You use the reserved words "null" "true" and "false" all the time.

What it means is that the two keywords "const" and "goto" which are in common use in the C and C++ languages were set as keywords when Java was developed. They are not used; the compiler throws an error if they are. The idea was to prevent people using those concepts at all.

[Edit for minor spelling errors]
[ March 08, 2007: Message edited by: Campbell Ritchie ]
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Campbell Ritchie:
Quoted by Gavin Tranter:- Yes, you do. You use the reserved words "null" "true" and "false" all the time.



Not wishing to argue, but Sun defines "null" "true" and "false" as literals:

true, false, and null might seem like keywords, but they are actually literals;



In thier list of keywords, Sun do not list "null", "true" or "false" but they do list the reserved words "const" and "goto".
Keywords

So now I am more confused then ever, I think i will reread what I need to know about keywords for the SCJP. :S

G
 
Campbell Ritchie
Marshal
Posts: 75666
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It actually says in the JLS page you quoted ". . . are reserved for use as keywords."

In the sense that "true" "false" and "null" can only be used in the context they were designed for, they are "reserved" although the JLS doesn't say "reserved."

In most languages keywords are reserved words as well; Java is no exception. It says that "const" and "goto" are "reserved" without ever being used. As it says in the JLS page quoted, this is to allow for better error messages.

I think I actually agree completely with the first half of your post I quoted from.
And we can go on splitting hairs about what "reserved" means until the cows come home.
 
author and cow tipper
Posts: 5006
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you ever see that WKRP in Cincinati episode where Artur Carlson throws the turkeys out of a helicopter? The timeless line was As God is my witness, I thought that Turkeys could fly.

Well, I'd like to add, As God is my witness, I thought that null, false and true were keywords.

Interesting thread.

-Cameron McKenzie
 
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic