JavaFormatter Free Online Java Formatter
Education

Spaces vs Tabs in Java: The Debate Is Over

2026-08-03 · 4 min read
Spaces vs Tabs in Java: Why the Debate Is Over The tabs-vs-spaces argument consumed developer energy for decades. In Java, the argument ended. The community standardized on spaces, and every major style guide agrees. Here is why and what it means for your code. The Standard: 4 Spaces The Oracle Java Code Conventions specify 4-space indentation. The Google Java Style Guide specifies 2-space indentation, but then adds a clarifying note that 4 spaces is acceptable and common. Both agree on one thing: spaces, not tabs. IntelliJ IDEA defaults to 4-space indentation. Eclipse defaults to 4-space indentation (with a mixed tab policy that most teams disable). VS Code Java extension pack defaults to 4 spaces. The tooling has spoken. Why Tabs Lost Tabs display at different widths in different editors. A file indented with tabs and viewed in an editor configured for 4-space tabs looks fine. The same file opened in an editor configured for 8-space tabs overflows the right margin. This inconsistency creates formatting chaos when different team members use different editor settings. Spaces render the same width everywhere. A 4-space indent is 4 spaces in IntelliJ, Eclipse, VS Code, vim, emacs, and cat on a terminal. No surprises. The Mixed Case: Makefiles Makefiles require tabs for recipe lines. This is the one place where tabs are not negotiable. Most Java developers configure their editor to use spaces by default and insert tabs manually when editing a Makefile. The Java formatter skips Makefiles entirely. What to Do with Legacy Tabbed Code If you inherit a Java project that uses tabs, convert it. Run the Java Formatter on every Java file. Commit the result as a single formatting-only commit with a message like "Convert tabs to spaces, apply standard formatting." After that commit, configure your IDE to use spaces and move on. The tabs-vs-spaces debate was never about Java. It was about editors, tooling, and personal preference colliding on a shared codebase. Java settled it by having one dominant style guide and three dominant IDEs that all default to spaces.

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.