• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static char in the files given from Sun

 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I was given several files as part of initial assignment from Sun. When I read the codes, I found that there is a static data member in each of the Data, DataInfo, and FieldInfo classes.
The static data member is:
final static char sc = 'A';
I could not find the use of it in the programs given. I am wondering if anybody receives the same kind of code as me. Can anybody can tell me what it is used for ? Can I ignore it when I implement the code change ?
Thanks,
John Chien
 
BJ Grau
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can ignore it. You can even take it out.
Also, there are two issues with this field:
1) It is suggested (but not required) in the Java Lang Spec that it should be static final, not final static.
2) It is required in the JLS that static final fields should not be named with lowercase letters.
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

2) It is required in the JLS that static final fields should not be named with lowercase letters.

Well, it's not really required, and it's not in JLS, but in Java Coding Conventions. Just to make it clear...
Eugene.
 
BJ Grau
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eugene Kononov:

Well, it's not really required, and it's not in JLS, but in Java Coding Conventions. Just to make it clear...
Eugene.

Eugene -
Did you check the spec? It "clearly" says it right here:
JLS Naming of Constants
In both the JLS and the Conventions docs they refer to it as a convention. I would follow it just as you probably follow the suggestions for method and class naming. If you do follow some other convention, I would make sure that it is consistently followed throughout all of your code. (i.e. - if you leave that constant as "sc", then don't use the Sun convention everywhere else)
-BJ
[ February 20, 2003: Message edited by: BJ Grau ]
 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Now, I get the idea.
I asked the same question to Sun. They won't tell me anything about it.
John Chien
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Did you check the spec? It "clearly" says it right here:

I followed your link, and there two clauses there regarding the use of uppercase letters in constants:
"The names of constants in interface types should be, and final variables of class types may conventionally be (my emphasis), a sequence of one or more words, acronyms, or abbreviations, all uppercase, with components separated by underscore "_" characters."
"Constant names normally (my emphasis again) have no lowercase letters, so they will not normally obscure names of packages or types, nor will they normally shadow fields, whose names typically contain at least one lowercase letter.
So it is certailnly not a requirement, rather a convention. After all, if it compiles, then it conforms to JLS. But let's not argue about it, -- of course one should follow the conventions.
Eugene.
[ February 20, 2003: Message edited by: Eugene Kononov ]
 
BJ Grau
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point. There is a big difference between a requirement and a convention. I noticed the error after my first post and tried to clarify by saying they refer to it as a convention. I hope I didn't mislead anyone.
Interestingly enough, I was looking for something in the 1.2.2 source today and noticed that there is no 100% consistent application of a naming style for constants, so perhaps the whole point is moot anyway.
I don't think anyone's arguing, we're just having a healthy discussion on the smaller details of style.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic