What is the right way to write the name of a class "VPNAPIs"? Is it VpnApis
, VPNAPIs
or VpnAPIs
?
VPN: Virtual Private Network.
API: Application Program Interface.
What is the right way to write the name of a class "VPNAPIs"? Is it VpnApis
, VPNAPIs
or VpnAPIs
?
VPN: Virtual Private Network.
API: Application Program Interface.
VpnApis
is correct.
As per java's naming convention,
All the classes, interfaces should start with uppercase letter and be a noun/adjective
Every Java class name must start by Capital Letter meanwhile if sub-word appear then it's also start by Capital.
The answer is that all three alternatives are legitimate1, depending on which coding standard you follow, and how you chose to interpret it.
My advice:
Original 1997 Sun Java Code Conventions (no longer "maintained").
"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)."
Important notes:
Therefore:
VpnApis
compliesVPNAPIs
complies (ugh!)VpnAPIs
compliesThis interpretation is reinforced by various examples of classnames using acronyms in the Java SE class library. Many of them were added well after 1997, belying the argument that they are "historical exceptions". (Note that 1997 was when JDK 1.1 was released!)
"Beginning with the prose form of the name:
- Convert the phrase to plain ASCII and remove any apostrophes. For example, "Müller's algorithm" might become "Muellers algorithm".
- Divide this result into words, splitting on spaces and any remaining punctuation (typically hyphens).
- Recommended: if any word already has a conventional camel-case appearance in common usage, split this into its constituent parts (e.g., "AdWords" becomes "ad words"). Note that a word such as "iOS" is not really in camel case per se; it defies any convention, so this recommendation does not apply.
- Now lowercase everything (including acronyms), then uppercase only the first character of:
- ... each word, to yield upper camel case, or
- ... each word except the first, to yield lower camel case
- Finally, join all the words into a single identifier."
This gives:
VpnApis
correct,VPNAPIs
incorrectVpnAPIs
incorrectwhich is reinforced by examples in the document.
Note however, these rules clearly would call out many Java SE class names as being incorrect.
1 - For what is is worth, my preferences would be 1) pick a different class name (this one does not clearly indicate the classes purpose ... though it might if there was more context), 2) use VpnApis
, 3) use VpnAPIs
.