wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes keywords confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "keywords confusion" Watch "keywords confusion" New topic
Author

keywords confusion

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
There are 49 reserved keywords and 3 reserved literals ( null,true and false ) in 1.4 , that we can't use in our code as an identifier for variable , method or class etc .

My question is , 1.5 also has the same 52 reserved words ? ( although in my opinion , sun can't reserve any new word now for keyword because it might break code of lots of people ( if they have used that name in their project ) , but just wanted to confirm )

I read some online resources mentioned in this site only , they are mentioning more than 52 reserved words , what is truth ?

Thanks a lot .
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
Java 5 has added enum.

I think that enum is only reserved if you have "-source 1.5" in your javac command.


Mike Gershman
SCJP 1.4, SCWCD in process
Jay Ashar
Ranch Hand

Joined: Oct 13, 2002
Posts: 208
Originally posted by rathi ji:

My question is , 1.5 also has the same 52 reserved words ? ( although in my opinion , sun can't reserve any new word now for keyword because it might break code of lots of people ( if they have used that name in their project ) , but just wanted to confirm )


Why can't sun add new keyword, they added assert keyword when 1.4 was released.


SCJP 1.4<br />SCWCD 1.3
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
Notice that assert was an optional reserved word in Java 1.4 and is a default reserved word in Java 1.5. I expect that enum will be a default reserved word in Java 1.6.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
So Mike , If suppose any company moves their project to 1.5 ( they have made in 1.3 ) and they have used assert as their costom identifier , then does they have to change their code ?? ( although possibilities are very low )

enum is the only keyword added by 1.5 ?

please comment anybody ..

thanks a lot .
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
javac 1.5 supports "-source 1.3" and "-source 1.4" as well as "-source 1.5". That protects legacy code.

BTW, the default is "-source 1.5", so beware if you may have used enum as an identifier in your code.

enum is the only new reserved word in Java 1.5.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Thank you very much Mike .
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Why can't sun add new keyword, they added assert keyword when 1.4 was released.

They can add keywords, but they try very hard not to, because it can break code for people who used the new keyword as an identifier. Indeed, I remember seeing code like this:

Such code now breaks. Of course, most people who used Enumerations have moved on to iterators by now, but still...

I imagine Sun wanted to avoid this situation, but they couldn't find a better solution to support enumerated types without creating a new keyword. So they bit the bullet, and created the keyword.

In contrast, the enhanced for loop might have looked nicer if they'd chosen a syntax like this:

or

However these would have required new keywords to be created. (And I personally use "in" as an identifier for an InputStream quite frequently.) Instead, Sun was able to find an alternative syntax:

This isn't quite as easy to understand the first time you see it - but it doesn't require any new keywords. So we see that Sun is willing to create new keywords on rare occasions, but they usually choose not to, if they can avoid it.


"I'm not back." - Bill Harding, Twister
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Thanks Jim .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: keywords confusion
 
Similar Threads
keywords vs. reserved words
keywords and identifiers - Which is correct..
keywords
How to discriminate Keyword and Reserved Word?
reserved and keywords