Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is correct Java naming convention for id?

Tags:

If I have user id variable, what is correct java naming convention for it?

userId or userID

like image 859
newbie Avatar asked Nov 09 '09 09:11

newbie


People also ask

What is the naming convention in Java?

For variables, the Java naming convention is to always start with a lowercase letter and then capitalize the first letter of every subsequent word. Variables in Java are not allowed to contain white space, so variables made from compound words are to be written with a lower camel case syntax.

Which is the right naming convention for class in Java?

Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).

Should ID be capitalized in code?

If you are a programmer and you are referring to the row number of a record in a table, then you are referring to a Unique identity or Unique identifier, both of which can be referred to an Id. Because the letters are only representing a single word the "d" should never be capitalized.

What are some conventions for naming identifiers?

There are some rules you have to follow for naming identifiers: The first character of the identifier must be a letter of the alphabet (upper or lowercase) or an underscore ('_'). The rest of the identifier name can consist of letters (upper or lowercase), underscores ('_') or digits (0-9).


1 Answers

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.

like image 195
Edan Maor Avatar answered Sep 28 '22 14:09

Edan Maor