The Elements of Java Style

The Elements of Java Style describes a collect of consistent style conventions for Java.

The syntax of a programming language tells you what code it is possible to write—what the machine will understand. Style tells you what you ought to write—what the humans reading the code will understand. Code written with a consistent, simple style will be maintainable, robust, and contain fewer bugs. Code written with no regard to style will contain more bugs. It may simply be thrown away and rewritten rather than maintained.

Our two favorite style guides are classics: Strunk and White’s The Elements of Style and Kernighan and Plauger’s The Elements of Programming Style. These small books work because they are simple—a list of rules, each containing a brief explanation and examples of correct, and sometimes incorrect, use. We followed the same pattern in this book. This simple treatment—a series of rules—enabled us to keep this book short and easy to understand. The idea is to provide a clear standard to follow, so programmers can spend their time on solving the problems of their customers, instead of worrying about naming conventions and formatting.

This book was written by a team of senior developers from RogueWave Software and myself. Seven people to write a 140-page book? It must be good!

The Strengths of The Elements of Java Style

  • It presents proven practices for writing robust Java code — this isn’t an academic wish list
  • It is written by developers for developers — you can immediately see how to put these coding guidelines to use
  • It increases your productivity during development — it is easier to write code when it is written in a consistent manner
  • In increases your productivity during maintenance — you always have to update your code, and the easier it is to understand the easier it is to update
  • It is short and to the point — it is paperback-sized and 140 pages in length
  • It includes a plethora of source code examples — you immediately see how to apply the guidelines
  • It includes a summary listing of the guidelines — you have an easy to read quick reference
  • It explains why each guideline is important — you gain an understanding of the principles of writing robust Java code
  • It is based on existing industry practices — it summarizes, explains, and expands on common Java conventions in use by the best Java software engineers

Published: January 2000

Status: Out of date

Where to Buy This Book:

Book Organization

The book is organized into 6 major sections:

  1. General Principles. While it is important to write software that performs well, many other issues should concern the professional Java developer. All good software performs well. But great software, written with style, is predictable, robust, maintainable, supportable, and extensible. This section presents fundamental principles and practices for writing high-quality code, principles and practices that are built upon through the rest of the book.
  2. Formatting Conventions. This section describes approaches to formatting your code to make it more readable, such as indenting (paragraphing) rules, the proper use of white space, and how to effectively break up long lines. Simple practices that have a big payoff when used consistently.
  3. Naming Conventions. This section presents the standard Java naming conventions for classes, member functions, fields, getter and setter operations, local variables, parameters to member functions, and more. Many development teams waste hours, if not days, arguing about how to name the various aspects of their code. Do you really want to spend your time doing this, or spend it writing code? We’ve documented the standard naming conventions right here so that you don’t have to.
  4. Documentation Conventions. Few programs are so simple, so trivial, that they don’t need to be documented. In this section we present a collection of principles and guidelines for writing effective source code documentation.
  5. Programming Conventions. This section presents a collection of tips, techniques, and programming idioms for writing superior Java code. Techniques for improving the performance and efficiency of your code are presented, as well as conventions to improve the readability and quality of your code.
  6. Packaging Conventions. The section presents a collection of packaging conventions for distributing your Java code.

Books Similar to Elements of Java Style

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.