• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

keywords confusion

 
Ranch Hand
Posts: 3851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java 5 has added enum.

I think that enum is only reserved if you have "-source 1.5" in your javac command.
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much Mike .
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ankur rathi
Ranch Hand
Posts: 3851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jim .
 
Can you shoot lasers out of your eyes? Don't look at this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic