views:

384

answers:

8

What is the correct name for the following Java class: DVDPlayer or DvdPlayer?

+4  A: 

DVDPlayer 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).

Tom Hawtin - tackline
I don't think this is really a standard, but it is probably the most common.
Bruno Rothgiesser
It's in the Sun Java Coding Standard, IIRC. Although not in the JLS.
Tom Hawtin - tackline
HyperTextTransferProtocolUniformResourceLocatorConnection
flybywire
I'm pretty sure most people use ID as an abbreviation of Identifier...i.e. in a database the table ID is referring to the table identifier to the identity document.
DD
DVDPlayer is definitely not the standard; even the JDK is wildly inconsistent in their approach to this.
Kevin Bourrillion
The Java library is inconsistent in a number of ways (my favourite example is `javax.xml.parsers` vs `javax.xml.transform`). However, it is quite consistent with initials using caps, as in `DOMURIReference`. I guess most of the counterexamples come through JSRs where there spec lead has gone off and done something odd.
Tom Hawtin - tackline
@Kevin And then there is CORBA, which is "special" with regards to naming.
Tom Hawtin - tackline
+5  A: 

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.

jk
+3  A: 

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).

codaddict
That doesnt really say anything about whether it should be upper or camel case.
DD
+8  A: 

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.

alt text

flybywire
oooo that's a useful eclipse tip. Thanks!
Peter Perháč
(+1) a good tip. that answers the question for me :-)
Asaf
Just "SIO" is sufficient to find that class.
finnw
This also works elsewhere in Eclipse - auto-complete for instance. Have a method/variable named 'myDvdCoverImage'? - just type mDCI Ctrl+Space
teabot
there is also some shortcuts already set, like sysout Ctrl+Space, gives you System.out.println. same goes for (try) and (for)
medopal
That works in IntelliJ too with Ctrl+N
Bruno Rothgiesser
+4  A: 

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.

Peter Perháč
+2  A: 

Some examples from the JavaSE classes, apache commons and spring:

  • HttpURLConnection
  • HTTPAddress
  • UrlPathHelper
  • AopProxy
  • ISBNValidator

So - it doesn't really matter.

Bozho
Agreed. Just be consistent in your code base.
JamesC
A: 

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.

duffymo
I believe the HTTP protocol name in URLs should be written in lower case (although it may be accepted in upper case by browsers).
Tom Hawtin - tackline
+1  A: 

Effective Java seems to prefer DvdPlayer.

Brian Harris