Autograding Java code projects on code quality, code style and bad practices using Checkstyle and PMD
May 10, 2021

Autograding Code Quality and Common Bad Practices in Java Assignments

In 30 seconds...

  • Java is one of the most popular and commonly taught languages. You’ll come across it in courses like Introduction to Programming, Object Oriented Programming, Data Structures and Mobile Development;
  • So it’s important to eliminate common bad practices! Plus we’ll show you autograde Java code quality;
  • CodeGrade’s code quality step is perfect for this  - it provides instant feedback on the style, quality and structure of code. It’s efficient - it doesn’t require any configuration - and flexible, as it allows for fully custom tools and style guides;
  • Learn how to use industry standard tools like PMD and Checkstyle effectively in your classroom!

Java is one of the world’s most popular and most taught programming languages. Most, if not all Computer Science students, will have had a course on Java sometime during their academic career, often even during their introductory courses. Next to using Java as a means to teach Introduction to Programming, Object Oriented Programming, Data Structures or Mobile Development, it is also important to teach good Java practices and code quality. Perhaps especially for such a frequently occurring programming language such as Java, a programming language that is pre-eminently used for larger software projects in which good team work, adherence to a strict style guide and good coding practices are crucial.

In this guide, I will cover ways to autograde Java code quality and eliminate common bad practices. Not only will I cover two very useful tools for this, Checkstyle and PMD, I will also discuss how you can design your own style guides to fit your courses’ learning objectives and how to customize the feedback messages generated by these tools to be more understandable and meaningful for your students. 

Prefer to watch a webinar instead? Most material covered in this guide is discussed in our webinar on Java Autograding, which you can watch on demand here.

Java Code Quality tests in CodeGrade

One of the types of tests offered in CodeGrade AutoTest is the Code Quality step, a way to provide instant feedback on the style, quality and structure of code. This step makes it really easy to set up default quality checks without any configuration, but allows for fully custom tools and style guides too. The feedback generated in this step is not only shown in the AutoTest tab, but also directly on the lines of code, making it very intuitive for students to use and understand their code quality feedback!

Automatic Java code quality feedback to a programming assignment in CodeGrade

You can use any custom tool or linter in a Code Quality step, but also use one that is built-in. For Java, we offer Checkstyle and PMD. These two code analysis tools (or linters) are used for different purposes, but are both very powerful (and even more so when combined). After briefly reviewing both tools, I will show how you can use them in a basic Code Quality test, which we will further customize in the following chapters.

Checkstyle

Checkstyle is a static code analysis tool for Java that is built-in to CodeGrade. It is a traditional linter: it checks if the code style and presentation conform to a style guide, but it does not check or confirm code correctness or completeness. 

Amongst other things, Checkstyle can detect:

  • Use of naming conventions (variables, methods, etc.)
  • Completeness of documentation (think Javadoc)
  • Use of vertical and horizontal whitespace
  • Conventions for parameters, headers and imports

While at first glance it may seem somewhat unnecessary to teach, it is very important for students to learn working with a style guide, as this is very common practice in their later career and in group projects. Furthermore, enforcing a style guide in beginner courses helps students develop with a solid code style following the conventions.

PMD

PMD (probably but unofficially standing for Programming Mistake Detector) is a cross-language source code analyzer that is built-in to CodeGrade. It not only works with Java, but also with JavaScript, XML and PL/SQL. In comparison to Checkstyle, PMD actually detects bad coding practices and potential bugs, but does not assess style.

Amongst other things, PMD can be used to detect:

  • Inefficient code
  • Bad programming habits
  • Overcomplicated expressions that can be simplified
  • Potential bugs
  • Dead code
  • Duplicate code (via the included Copy-Paste-Detector, which also works for Python, C-languages, Ruby, PHP and many other languages)

PMD is often a little bit more advanced than Checkstyle and very useful in more advanced courses where bad practices are harder to spot by eye. Furthermore, it has rules for many very specific bad practices, allowing you to make custom style guides specifically for an OOP course, a multithreading course or another advanced course. Moreover, PMD has an option to create totally custom rules, which is outside the scope of this guide, but can make it very powerful for any advanced Java course.

Start autograding Java Code Quality and common bad practices easily and effectively now!

Continue reading

Best Paid Autograders for University Programming Courses (2026)

A side-by-side comparison of the best paid autograders for university programming courses in 2026 — CodeGrade, Gradescope, Codio, and Vocareum — covering pricing, features, and LMS integration.

Best Autograders for University Programming Courses You Can Start Using for Free (2026)

A practical comparison of six free autograders for university programming courses in 2026 — including CodeGrade, GitHub Classroom, Gradescope, Autograder.io, Otter Grader, and nbgrader.

How to Grade Code Quality, Not Just Correctness

Learn how to automate code quality checks in CodeGrade using Flake8, Checkstyle, Semgrep, and clang-tidy — no manual review or custom YAML required.

Sign up to our newsletter