Java
Naming Convention
Acronyms
Programming
Code Standards

Java Naming Convention with Acronyms

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Acronyms make Java naming look simple until you have to choose between HttpClient, HTTPClient, userId, and userID. The real goal is not preserving every capital letter from the acronym, but keeping class, method, and field names readable and consistent across the codebase.

Treat Acronyms as Words by Default

The safest general rule is to treat acronyms like ordinary words in camel case. That means:

  • classes: HttpClient, XmlParser
  • methods: getUserId, parseHtml
  • fields: apiKey, dbUrl

Example:

java
1public final class HttpClientConfig {
2    private final String apiKey;
3    private final String serviceUrl;
4
5    public HttpClientConfig(String apiKey, String serviceUrl) {
6        this.apiKey = apiKey;
7        this.serviceUrl = serviceUrl;
8    }
9
10    public String getApiKey() {
11        return apiKey;
12    }
13
14    public String getServiceUrl() {
15        return serviceUrl;
16    }
17}

This style reads naturally because the identifier looks like normal Java, not like a block of shouting capitals.

Recognize the Exception: Established Platform Terms

Java codebases also contain names like URL, URI, UUID, and XMLStreamReader. These are common because the JDK itself uses them, and once a type becomes an established platform concept, matching that convention is often clearer than forcing a different one.

java
1import java.net.URL;
2import java.util.UUID;
3
4public final class ResourceLink {
5    private final URL url;
6    private final UUID requestId;
7
8    public ResourceLink(URL url, UUID requestId) {
9        this.url = url;
10        this.requestId = requestId;
11    }
12
13    public URL getUrl() {
14        return url;
15    }
16
17    public UUID getRequestId() {
18        return requestId;
19    }
20}

Notice the balance:

  • type names can remain URL or UUID
  • surrounding method names still read as getUrl() and requestId

This is usually easier to read than getURL() or requestID() in ordinary application code.

Keep Method and Field Names Predictable

The biggest readability problems appear in accessor methods and JSON-style identifiers. Compare these two styles:

java
1private String userId;
2
3public String getUserId() {
4    return userId;
5}

versus:

java
1private String userID;
2
3public String getUserID() {
4    return userID;
5}

The first version usually fits Java naming expectations better. It also reduces friction with frameworks that generate or infer bean properties from method names.

The same principle applies to multiple acronyms in one identifier. Prefer parseJsonResponse over parseJSONResponse unless your team has a very strong contrary convention.

Consistency Matters More Than Winning the Style Debate

There is no universally perfect acronym rule because real Java code lives between official style guides, JDK history, generated code, and team preference. The practical rule is:

  • pick one default convention
  • document exceptions
  • apply it uniformly

For example, a project might define:

  • use Http, Xml, and Json in ordinary names
  • preserve URL, URI, and UUID when referencing JDK types

That rule is understandable and easy to enforce in reviews.

A small example of consistent naming:

java
1public final class JsonUrlMapper {
2    public String mapUrlToJson(URL url) {
3        return "{\"url\":\"" + url + "\"}";
4    }
5}

Even though URL stays uppercase as a type, the surrounding identifiers still follow the project's readable camel-case rule.

Common Pitfalls

  • Writing HTTPRequestHandler everywhere makes identifiers heavy and harder to scan.
  • Mixing userId, userID, and UserID in one codebase creates unnecessary confusion.
  • Copying JDK acronym style into every project-specific name without considering readability usually hurts more than it helps.
  • Forgetting bean-property conventions can make frameworks behave unexpectedly with getter names.
  • Arguing about one acronym spelling without documenting a team-wide rule guarantees the same argument later.

Summary

  • Treat acronyms as words in camel case by default, such as HttpClient and getUserId.
  • Preserve fully uppercase forms mainly for established platform types such as URL and UUID.
  • Keep field and method naming consistent so frameworks and humans read the code the same way.
  • Define a team convention with a small set of explicit exceptions.
  • Readability and consistency matter more than preserving every original capital letter.

Course illustration
Course illustration

All Rights Reserved.