Skip to main content

Java

Casing Rules

ElementConventionExample
ClassesPascalCaseOrderService, UserRepository
InterfacesPascalCasePaymentProcessor, UserRepository
EnumsPascalCasePaymentMethod, OrderStatus
Enum constantsSCREAMING_SNAKE_CASECREDIT_CARD, IN_PROGRESS
MethodscamelCasegetUserById, processPayment
VariablescamelCaseuserCount, isActive
Constants (static final)SCREAMING_SNAKE_CASEMAX_RETRY_COUNT, DEFAULT_TIMEOUT_MS
Packageslowercase.dot.separatedcom.acmeco.retail.orders

File Naming

One public class per file. The file name must match the class name exactly.

# Good:
OrderService.java
UserRepository.java
PaymentProcessor.java

# Test files mirror the source:
OrderServiceTest.java
UserRepositoryIT.java # integration test suffix
OrderWorkflowE2ETest.java

Package Naming

Packages follow a reverse-domain hierarchy:

com.{company}.{org}.{solution}.{layer}

com.acmeco.retail.orders.service
com.acmeco.retail.orders.repository
com.acmeco.retail.orders.model

Keep packages lowercase with no underscores or hyphens. Each segment should be a single meaningful word.