If I have user id variable, what is correct java naming convention for it?
userId or userID
If I have user id variable, what is correct java naming convention for it?
userId or userID
It mainly depends on your naming convention together with your application (if there are any). For instance, userId is a preferred one with Java convention
I think I read somewhere that the best guideline is to always capitalize only the first letter of an acronym (i.e., if you have a user TTL where TTL is some random acronym in your project, then it's best to write userTtl).
This makes sense, since it solves some problems. For example, say you want a user id counter. Readability of userIDCounter is worse than userIdCounter. For a longer acronym, it gets even worse.
This is quite a handy resource for Java naming conventions http://geosoft.no/development/javastyle.html
This is a tough decision, even Sun isn't so sure what to do. Look at classes in JRE,
java.net.URL
java.security.acl.Acl
java.net.HttpURLConnection
java.awt.dnd.DnDConstants
java.awt.color.ICC_Profile
Personally, I prefer to use camel-case always to be consistent.
As far as the Java convention is concerned its there in lot of books that the first letter of each word is capatailsed and the all other letters are in small letters, So you have classes like AcademicStudent, and so is the UserId.
I consider the item described in: Effective Java by Joshua Bloch authoritative in this matter:
Adhere to generally accepted naming conventions
Class and interface names should consist of one or more words, with the first letter of each word capitalized [..] Abbreviations are to be avoided, except for acronyms and certain common abbreviations like max and min. [...] a strong argument can be made in favor of capitalizing only the first letter. [...] you can still tell where one word starts and the next word ends. Which class name would you rather see, HTTPURL or HttpUrl?
So, It should be userId
It's like this:
userID
, it suggests that a plain id would be iD
, and you sure as heck don't want to do that, so the winner is:userId
(as others have said).
So it ends up being treated like an acronym anyway.