Classes |
Use PascalCase for class names. |
MyClass |
|
Use nouns or noun phrases to name a class. |
CarFactory , StudentController , AddressValidator |
|
Suffix Activity classes with Activity . |
com.hit.playpal.MainActivity , SettingsActivity , AuthActivity |
|
Suffix Fragment classes with Fragment . |
LoginFragment , SignUpFragment , ProfileFragment |
|
Suffix Adapter classes with Adapter . |
UserAdapter , UserListAdapter , UserDetailsAdapter |
|
Suffix Dialog classes with Dialog . |
FeedbackDialog , ConfirmationDialog , UserDetailsDialog |
Variables |
Prefix member variables with m followed by PascalCase for non-public instance fields. |
mPackagePrivate , mPrivate , mProtected |
|
Prefix static fields with s followed by PascalCase . |
sSomeStaticField |
|
Use lowercase for public instance fields (should be avoided if possible). |
publicField |
|
Use ALL_CAPS_WITH_UNDERSCORES for constant names (local, static, public, private, etc.). |
SOME_CONSTANT , public static final int SOME_CONSTANT = 0; |
|
Use camelCase for regular local variables. |
someLocalVariable |
Methods |
Use camelCase for method names. |
myMethod |
|
Use descriptive verb names that convey the purpose of the method (even if they come out long). |
calculateTotalPriceOfItemsInCart , showConfirmationDialog , validateEmailAddress |
|
Use get and set prefixes for methods that act as getters and setters. |
getSomeField , setSomeField |
|
Use is prefix for methods that return a boolean value. |
isUserLoggedIn , isEmailValid |
|
Prefix all parameter names with i followed by PascalCase . |
void doSomething(int iSomeParameter) |
Packages |
Use lowercase for package names. |
|
|
Use a reverse domain name convention for package naming. |
com.example.myapp , com.example.myapp.ui , com.example.myapp.ui.activities , com.example.myapp.ui.fragments |
Enums |
Use PascalCase for enum types. |
DayOfWeek |
|
Use ALL_CAPS_WITH_UNDERSCORES for enum constants. |
```java |
|
|
public enum DayOfWeek { |
|
|
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY |
|
|
} |
Interfaces |
Use PascalCase prefixed with I for interface names. |
IMyInterface |
|
Use nouns or noun phrases to name an interface. |
IUserRepository , IUserDetailsView , IUserDetailsPresenter |
|
Use adjectives to name an interface if it is an adjective. |
IParcelable , ISerializable , IValidatable |
|
Use camelCase for method names in interfaces. |
void myMethod() , int calculateTotalPrice() |