Java Naming Standards
Introduction
I guess I run with whatever the linter tells me but wanted to capture a way here
Naming Standards
Here we go.
Type | Convention | Example |
---|---|---|
Variables | camelCase | String userName = "John";
|
Methods | camelCase | public void calculateTotal() { ... }
|
Parameters | camelCase | public User getUser(String userId) { ... }
|
Classes | PascalCase | public class UserAccount { ... }
|
Interfaces | PascalCase | public interface UserProfile { ... }
|
Enums | PascalCase | public enum UserRole { ADMIN, EDITOR, VIEWER }
|
Enum constants | UPPER_SNAKE_CASE | public enum UserRole { ADMIN, EDITOR, VIEWER }
|
Constants | UPPER_SNAKE_CASE | public static final int MAX_RETRY_ATTEMPTS = 3;
|
Package names | lowercase | package com.example.project;
|
Instance fields | camelCase | private int accountBalance;
|
Static fields | camelCase (non-final) | private static int userCount;
|
Generic type parameters | Single uppercase letter | public <T> void process(T item) { ... }
|
File names | PascalCase.java (match class name) | UserAccount.java
|
Test class names | PascalCase with Test suffix | UserAccountTest.java
|
JUnit test methods | camelCase with descriptive names | void shouldThrowExceptionWhenInvalidInput() { ... }
|