Skip to Content
Java Power Tools
book

Java Power Tools

by John Ferguson Smart
April 2008
Intermediate to advanced
912 pages
27h 44m
English
O'Reilly Media, Inc.
Content preview from Java Power Tools

Chapter 21. Detecting and Enforcing Coding Standards with Checkstyle[18]

Using Checkstyle to Enforce Coding Standards

Checkstyle is an open source tool that enforces coding conventions and best practice rules for Java code. Although it was originally designed to enforce coding standards, it now lets you verify coding best practices as well, in much the same way as PMD (Chapter 22) and FindBugs (Chapter 23). It works by analyzing Java source code and reporting any breach of standards. It can be integrated into your favorite IDE via a plug-in so that developers can immediately see and correct any breaches of the official standards. It can also be used to generate project-wide reports that summarize the breaches found.

Checkstyle comes “out-of-the-box” with the standard Sun conventions, including more than 120 rules and standards, dealing with issues that range from code formatting and naming conventions to Enterprise JavaBean (EJB) best practices and code complexity metrics. Checkstyle supports standards related to the following:

  • Javadoc comments

  • Naming conventions

  • File headers

  • Import statements

  • Whitespace

  • Modifiers

  • Blocks

  • Coding problems

  • Class design

  • J2EE (Java 2 Platform, Enterprise Edition)

  • And other miscellaneous issues

You can run Checkstyle from the command line, if you are so inclined. Download the Checkstyle distribution from the web site[*] and extract it in a convenient place. Then run the checkstyle-all-4.3.jar file as shown here:

$ java -jar checkstyle-all-4.3.jar -c sun_checks.xml -r ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Java Projects - Second Edition

Java Projects - Second Edition

Peter Verhas
RESTful Java Web Services - Third Edition

RESTful Java Web Services - Third Edition

Balachandar Bogunuva Mohanram
Learning Scala

Learning Scala

Jason Swartz

Publisher Resources

ISBN: 9780596527938Errata Page