We are having this discussion in our team about code conventions for Java for:
interface
: Foo
or IFoo
or FooInterface
?
abstract
: Foo
or AbstractFoo
?
Enums
: Foo
or FooEnum
?
I'm basically trying to put my personal preferences aside :) so reasons to back up one or other convention are very welcome.
Interface names should be capitalized like class names. Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter.
Using the right letter case is the key to following a naming convention: Lowercase is where all the letters in a word are written without any capitalization (e.g., while, if, mypackage). Uppercase is where all the letters in a word are written in capitals.
CamelCase in Java naming conventions Java follows camel-case syntax for naming the class, interface, method, and variable.
For variables, the Java naming convention is to always start with a lowercase letter and then capitalize the first letter of every subsequent word. Variables in Java are not allowed to contain white space, so variables made from compound words are to be written with a lower camel case syntax.
In Java: Foo
, AbstractFoo
and Foo
- although AbstractFoo
could just be Foo
.
Evidence:
java.util.List
(interface)java.util.AbstractList
(abstract class)java.util.Formatter.BigDecimalLayoutForm
(enum)For the interface part, see the Naming Conventions section of the Java Coding Conventions document. It doesn't talk about enums and abstract classes though.
From my blog:
The blog also discusses reasons against some of the other names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With