Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is null a keyword?

 
Rajiv KumarRai
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is null a keyword?

Thanks in advance to all ranchers
 
William Cantree
Greenhorn
Posts: 4
Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If by keyword you mean reserved word? Yes.

Here are all of the reserved words in Java: http://java.about.com/od/javasyntax/a/reservedwords.htm

Otherwise, I have no idea with what you mean...
 
Rajiv KumarRai
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i meant to say that whether null is a reserved word in Java
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
No, it is not a keyword. It is a reserved word used as a literal. The details are in the Java Language Specification.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to be specific with what you ask. It may appear pedantic, but you are working with programming and the machine will be very pedantic with you.
 
Mike Simmons
Ranch Hand
Posts: 3078
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although I'm usually on the side of the pedants, I'm not sure how it really matters here. It's certainly true that the JLS says null is not a keyword, and that you can't use null as an identifier. They never appear to describe null as "reserved".

More importantly though, is there any useful consequence of this distinction? I mean, if the JLS had just added null, true and false to the list of keywords, and omitted any mention of the null literal or boolean literals (referring instead to the "keyword null" and the "keywords true and false" respectively) would Java behave any differently? I think the answer is no. Perhaps there's some subtle distinction at work here, but so far I can't see what it is.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree it would have made no difference if they had called null a keyword. But oddly enough, as you said, it doesn’t actually say null is a reserved word. The Java5 version of the JLS says exactly the same.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic