One thing to know first: Oracle has archived this document and says it isn't actively maintained. Its last revision was made in April 1999. The naming rules haven't changed in practice, and the Java platform's own APIs follow them, which is why they're still the reference.
The naming table
| Identifier | Convention | Example |
|---|---|---|
| Packages | all lowercase, starting with a top-level domain or a two-letter country code | com.apple.quicktime.v2 |
| Classes | nouns, mixed case with each internal word capitalized | ImageSprite |
| Interfaces | capitalized like classes | RasterDelegate |
| Methods | verbs, mixed case starting lowercase | runFast() |
| Variables | mixed case starting lowercase; don't start with _ or $ | myWidth |
| Constants | all uppercase, words separated by underscores | MAX_WIDTH |
Packages use your domain name in reverse
A package name starts with a top-level domain such as com, edu, gov, net or org, or a two-letter country code, followed by your organization's own components. That's why Java packages look like com.example.billing: the reversed domain keeps package names unique.
Classes are nouns, methods are verbs
The conventions ask for class names that are simple, descriptive nouns made of whole words. Avoid acronyms and abbreviations unless the abbreviation is far more common than the long form, the document's examples being URL and HTML. Method names should be verbs: run(), getBackground().
Short variable names
Variable names should be short but meaningful. One-letter names are fine only for throwaway variables: i, j, k for integers and c, d, e for characters.
What the conventions don't settle
The Oracle document doesn't say how to write an acronym inside a class name, so both HTMLParser and HtmlParser appear in real Java code, including the JDK itself (HttpURLConnection uses both styles in one name). Pick one for your project and keep to it.
Converting names with Transform Case
Our snake_case, camelCase, PascalCase and CONSTANT_CASE converters treat an acronym as one word, so HTTP server error becomes HttpServerError and http_server_error. That gives Java-style method, variable and constant names directly. For a class name, decide whether your project writes acronyms as Http or HTTP and adjust if needed.
Naming conventions in other languages: Python, C#, Go (Golang), Rust, Kotlin, Swift, Dart, PHP. All side by side: 20 languages compared.
Sources
Questions
Are Oracle's Java code conventions still current?
Oracle has archived them and no longer maintains them; the last revision was in 1999. The naming rules in them still match how the Java platform and most Java code name things.
How should Java constants be named?
All uppercase with words separated by underscores, as in static final int MAX_WIDTH = 999;.
Can a Java variable start with an underscore?
The conventions say variable names shouldn't start with _ or $, even though both are legal.