Interview Q&A · Java · 7 questions in this topic

Java Coding Standards & Naming Conventions — Java Interview Q&A

All Java topics

Interviewers ask about conventions because readable code is reviewable code — class names, method names, constants and the tools that enforce them. Part of Coding Standards · 294 questions in the Java bank.

What are the Java coding standards for classes?

Answer

Class names are nouns in UpperCamelCase, starting with an uppercase letter, with each inner word capitalised. A source file containing a public class must be named after it, and one top-level public class per file is the rule. Modern teams enforce these conventions automatically with formatters and checkers rather than by review discipline alone.

Key points

  1. 1Classes: UpperCamelCase nouns (ArrayList, HashMap, EmployeeDetails).
  2. 2Interfaces/enums/records follow the same class convention; annotations too.
  3. 3Tooling: google-java-format, Spotless or Checkstyle encode the standard so humans do not have to memorise it.

Example

Example.javajava
public class EmployeeDetails { }   // noun, UpperCamelCase
// file must be EmployeeDetails.java

What are the Java coding standards for interfaces?

Answer

Interface names use the same UpperCamelCase as classes and are usually adjectives describing a capability — Runnable, Serializable, Comparable, Cloneable. Marker interfaces (no methods) like Serializable and functional interfaces (exactly one abstract method) follow the same convention; the difference is in what the name promises, not how it is spelled.

Key points

  1. 1Adjective-style names signal "can-do": Readable, Iterable, AutoCloseable.
  2. 2Avoid Hungarian prefixes like "I" (IFoo) — modern Java style omits them.
  3. 3A @FunctionalInterface documents that the interface is intended for lambdas.

What are the Java coding standards for methods?

Answer

Method names start lowercase in lowerCamelCase and are usually verb phrases — getName(), calculateTotal(), isEmpty(). A boolean-returning method conventionally starts with is/has/can/should. Overloaded methods share one name across compatible parameter lists, and accessors follow the JavaBeans get/set/is pattern that frameworks rely on.

Key points

  1. 1lowerCamelCase verbs: toString(), addFirst(), computeIfAbsent().
  2. 2Booleans read as questions: isValid(), hasNext(), canRead().
  3. 3Getters/setters follow getX/setX/isX so reflection-based frameworks find them.

Example

Example.javajava
public String getCarName() { return carName; }
public boolean isEmpty() { return size == 0; }

Recommended resourcesAffiliate links · may earn us a commission

Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits