What is correct Java naming convention for id?

2019-02-08 09:20发布

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

userId or userID

8条回答
放我归山
2楼-- · 2019-02-08 09:37

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.

查看更多
相关推荐>>
3楼-- · 2019-02-08 09:41

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.

查看更多
登录 后发表回答