• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Questions on naming convention

 
Ranch Hand
Posts: 87
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Is there any reason for # being illegal in identifiers like - int e#. Is # used for anything else?

2) What is the keyword throw used for?
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not aware of '#' specifically used anywhere else right now, but that is not to say it won't be used for something someday.

'throw' is used to pass an exception up to the calling method. Look up "exception handling" or just "exceptions", and it should give you detailed info on it.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) I believe the reason for this one is pure convention. Java does not use # for anything, at least that i can remember or see in common documentation.

2) Throw is used to launch an exception. Is different than throws, which means that your method can throw an exception.

Example:
 
shuba gopal
Ranch Hand
Posts: 87
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fred,Daniel thanks. I came across one more keyword const. Looks like this is similar to final But with const the object value will not change. Am I right
 
Daniel Marti
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no const in java.
You can use the keyword "final" for generally the same effect only in primitive variables!
For objects you can create a new Object that is a clone of the object passed as parameter.
Example:
 
Marshal
Posts: 80612
467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a keyword const in Java™. But it is never used.
 
Campbell Ritchie
Marshal
Posts: 80612
467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The behaviour you are describing sounds more like the behaviour of const in C.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Marti wrote:
You can use the keyword "final" for generally the same effect only in primitive variables!


final still applies to reference variables. But it just means the reference cannot change, not that the object it's pointing at can't change (unless it's an immutable object).
 
Daniel Marti
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:There is a keyword const in Java™. But it is never used.


I stand corrected. There is a const keyword. Have to say it surprises me that i never even heard of it, not even in very boring and very extensive theoretical java classes(college)... Live and learn!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic