What is the correct name for the following Java class:
DVDPlayer or DvdPlayer?
What is the correct name for the following Java class: DVDPlayer or DvdPlayer ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since it looks like the answer is that there is no single standard for this in Java, I’d like to note that the .NET Framework Design Guidelines do specify this.
Now before slamming me for being off topic, please remember that the class naming guidelines for Java and the .NET Framework are quite similar, which makes the .NET guidelines useful as a persuasive reference.
General Rules
Both guidelines recommend only using acronyms when the acronym is widely known and well understood. DVD or XML are excellent examples of this, as while you will recognize them immediately, it would take a bit longer to recognize the expanded version.
Abbreviations
The .NET Framework Guidelines recommend not to use abbreviations (as opposed to acronyms), except that two common abbreviations
IDandOKmay be used in identifiers. When using an abbreviation, mixed caseIdis always used except for the first word of a camelCase identifier (as opposed to a PascalCase identifier).In Java this convention is followed only some of the time. Take a look at how mixed the spellings
getIDandgetIdare in the JCL. (Scroll partway down that page). In the Java 8 version though,getIdis used more and more, which hints the PascalCase convention is preferred nowadays. It is best to just avoid abbreviations entirely when possible.Short Acronyms
The .NET Framework Guidelines say that two letter acronyms like
IO, should have the same case for both letters. So for PascalCase identifiers (like a class name) you would getDBRate, while for a camelCase identifier (like a local variable) you might haveioChannel.This definitely seems to be the prevailing convention in Java as well.
Long Acronyms
The .NET Framework guidelines recommend that acronyms three letters or longer use mixed case for PascalCase and camelCase identifiers, except for the first word of a camelCase identifier. Thus for a class name you might have
XmlDocument, while a local variable might be namedhttpRequest.This convention is not always followed in Java. Four character acronyms do seem to usually use mixed case, but even the JCL is not consistent about three letter acronyms. Most of them seem to be all uppercase, like
URL,XML,SQL, andDOM, but there are some exceptions likeJar.Conclusion
For Java:
For 4+ letter acronyms, use mixed case. The standard library does this, and it just makes good sense.
For 3 letter acronyms, you can use all uppercase like the JCL, or you can use mixed case like the .NET Framework does. Either way, be consistent.
For 2 letter acronyms, use all uppercase.
For 2 letter abbreviations, Java does not really have a standard, but I suggest using mixed case, unless consistency with other names would make all uppercase look better.