Java
Naming Convention
Acronyms
Programming
Code Standards

Java naming conventions with acronyms: HttpClient or HTTPClient?

Codemia Knowledge Hub ·

Treat acronyms as ordinary words in camel case: HttpClient, XmlParser, getUserId, parseHtml. The exception is established platform types such as URL, URI and UUID, which you keep as the JDK spells them. Beyond that, consistency across the codebase matters more than any single rule.

Write acronyms as words by default

  • classes: HttpClient, XmlParser
  • methods: getUserId, parseHtml
  • fields: apiKey, dbUrl
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}

Identifiers read like normal Java instead of blocks of capitals. Names like HTTPRequestHandler used everywhere are heavier and harder to scan.

Keep JDK types like URL and UUID as they are

The JDK itself uses URL, URI, UUID and XMLStreamReader. Once a type is an established platform concept, matching its spelling is clearer than forcing another 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}

The type names stay URL and UUID, while the surrounding names read as getUrl() and requestId. That is usually easier to read than getURL() or requestID(). Copying JDK acronym style into every project-specific name, though, tends to hurt readability.

userId versus userID in getters

Accessors and JSON-style identifiers are where acronym style matters most:

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 fits Java naming expectations better and causes less friction with frameworks that infer bean properties from method names; ignoring those conventions can make frameworks behave unexpectedly. The same applies when an identifier has several acronyms: prefer parseJsonResponse over parseJSONResponse unless your team strongly prefers otherwise.

Pick a team rule and document the exceptions

No acronym rule is perfect, because real code mixes official style guides, JDK history, generated code and team preference. Mixing userId, userID and UserID in one codebase is what actually causes confusion. So:

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

For example:

  • use Http, Xml and Json in ordinary names
  • keep URL, URI and UUID when referring to JDK types

That rule is easy to understand and enforce in reviews, and writing it down saves having the same argument again later.

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

URL stays uppercase as a type, while the other identifiers follow the camel-case rule.


Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms