JavaFormatter Free Online Java Formatter
Education

Java Code Conventions: The Rules That Still Matter

2026-08-13 · 6 min read

The Java code conventions are the formatting and naming rules that most Java code follows. Four spaces of indentation, camelCase method names, PascalCase classes, and braces on the same line as the statement that opens them. Oracle formalized these in the Java Code Conventions document, and while tools and tastes have moved, the core rules have barely moved in two decades.

The Conventions That Still Matter

  • Indentation: four spaces per level, spaces rather than tabs
  • Brace style: opening brace on the same line (KandR style), closing brace aligned with the statement that opened the block
  • Naming: PascalCase for classes, camelCase for methods and variables, UPPER_SNAKE_CASE for constants
  • Imports: no wildcard imports, java.* packages first, then third party, then project code
  • Line length: 100 to 120 characters, wrapped at commas or operators

These five rules cover most of what makes Java code look like Java code. A file that follows them reads the same whether it was written at Google, at a startup, or in a university course.

Where the Conventions Come From

The Oracle Java Code Conventions document has been the reference since the late 1990s. It is short, opinionated, and it matches what the major IDEs do by default. IntelliJ IDEA and Eclipse both default to four space indentation and KandR braces, which is why so much Java looks the same without anyone having read the document.

The Google Java Style Guide is the other major reference. It agrees with Oracle on almost everything, with two differences worth knowing: it uses two space indentation and a 100 character line limit. Both are fine. Pick one and apply it everywhere.

Which Rules Have Faded

  • The 80 column limit. It comes from VT100 terminals. Modern Java projects use 100 to 140.
  • Hungarian notation. Prefixes like strName and iCount are gone from Java. Types are visible in the declaration.
  • Tab indentation. Java standardized on spaces decades ago.
  • Allman braces. Valid Java, but rare enough that it reads as foreign to most Java developers.

Coding Conventions vs Formatting Conventions

Naming and structure are conventions you apply by hand: what to call a class, where to put a constant, how to split a method. Whitespace and indentation are formatting, and a formatter applies those for you. The practical workflow is to decide your naming rules once, then let a formatter handle everything else. For a deeper treatment of the formatting half, see our Java code style guide.

How to Apply the Conventions Fast

Paste your Java into the Java Formatter and it applies the formatting conventions in seconds: indentation, brace placement, spacing, and import ordering. The naming rules stay your job, but the formatter removes the tedious half of compliance.

Related guides

More Free Developer Tools

DevToolCore

JSON formatter, regex tester, Base64, URL encoder, and 15+ more dev tools.

FontGenerator

14 Unicode font styles for social media, Discord, and anywhere you paste text.

CyberFengShui

Online Feng Shui compass with flying star analysis and AI interpretation.