What is the correct name for the following Java class:
DVDPlayer
or DvdPlayer
?
views:
384answers:
8DVDPlayer
is the standard, but DvdPlayer
is not uncommon.
You more often than not see getId
. That's probably due to thinking ID is a shortening of "Identity". It is actually the initials of Identity Document.
HttpURLConnection
is often given as an example of mixed convention. However, "http" used as protocol name in a URL should be lower case (although upper case is often accepted).
I've seen both of them used in the wild, and Sun seems to go for the DVDPlayer
style. I prefer DvdPlayer
, though, because that way it is clear where the word boundaries are even if there are multiple consecutive acronyms, as in HTTPURLConnection
.
From sun java docs:
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).
There is no "correct" answer. Just a set of practices and conventions that better play with your other tools.
Therefore I prefer DvdPlayer
. It is more helpful as in Eclipse you can do Ctrl+Shift+T and pick classes by the first letter of each word.
I like to define individual instances of classes in the following fashion:
Catalogue catalogue;
Person person;
Therefore, if I used DVDplayer
, what would I call an instance of that? dVDPlayer
? Hence I'd choose the DvdPlayer
class name, so you can name the instances like dvdPlayer
.
Some examples from the JavaSE classes, apache commons and spring:
HttpURLConnection
HTTPAddress
UrlPathHelper
AopProxy
ISBNValidator
So - it doesn't really matter.
There is no "correct", only preferences here.
Sun is consistent in the way they name classes containing "URL" and "HTML", but I see HTTP using both all caps and camel case in the javadocs.
Personally, I'd prefer DvdPlayer.