• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Questions on naming convention

 
shuba gopal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • 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?
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12101
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • 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.
 
Daniel Marti
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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: 76
  • Mark post as helpful
  • send pies
  • 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
  • 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:
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a keyword const in Java™. But it is never used.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The behaviour you are describing sounds more like the behaviour of const in C.
 
Matthew Brown
Bartender
Posts: 4566
8
  • Mark post as helpful
  • send pies
  • 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
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic