CSC 305 Laboratory Activity
Checkstyle Lab
While the following directions refer to the BlueJ IDE, you may use
any IDE of your choice (or no IDE) to complete this
assignment.
Part 1
- Login to your account on a CSL workstation.
- If you haven't setup your account to run BlueJ, then make
a launcher for BlueJ.
- Download the Checkstyle
extension
for BlueJ that contains the custom checks for our class
coding standard.
The extension is installed by placing the extension jar file
into an extensions directory. <USER_HOME>/.bluej/extensions
(Note, if the extensions folder doesn't exist, you'll have to create it.)
Restart BlueJ.
- From the Tools menu, select Preferences. The preferences
dialog appears. Click on the Extensions tab. Locate the
Checkstyle panel. For Configuration File enter the location of
the class configuration XML file: /home/graderjd/bin/bluej/lib/extensions/103style.xml
- From the "Project" menu select "New Project". (You may name it
"Lab1".)
- Click the "New Class" button to create a new Java class named
MinMaxTime.
- Right-click on the newly created MinMaxTime
class in the diagram and select "Open Editor". Observe that
BlueJ creates the skeleton code for a class. You may select all
(Ctrl-A) and delete the skeleton code.
- Copy and paste the source code for MinMaxTime.java
into the editor window.
- Click the "Compile" button. In the status window you
should see the message "Class compiled - no syntax errors."
Part 2
- From the main window (not the editor) open the Tools menu and
select Checkstyle. In the window that appears, click on
"MinMaxTime" in the left-hand panel. A list of checkstyle
violations appears along with the corresponding line number.
- Your assignment is to learn about the class coding standard by
correcting the errors that Checkstyle has identified. Leave both
the Checkstyle window and the editor window open. When you make
a a change in the editor and click "Compile" the Checkstyle
window will automatically refresh itself. The following strategy
is suggested:
- Look for errors whose message is immediately obvious. For
example, on line 57, "'{'
should be on a new line" needs no further
explanation.
- Consult the
coding standard checklist or coding standard
definition if you aren't sure how to fix the error or
what the correct standard requires.
- Read an explanation for a few of the most
common errors.
- If the error message doesn't make sense to you, consult the
Checkstyle
documentation for an explanation of the error message.
- As a last resort, consult the instructor.
- Write meaningful comments for the class header, method
headers, and logic comments. This will require that you
spend a little time studying the code to comprehend what it
does.
- Review the
coding standard checklist and study the MinMaxTime code to
see if there are any violations of our class standard that
Checkstyle does not catch. (Checkstyle is not
perfect). Correct any violations you discover.
Part 3
- Make sure the program compiles correctly.
- Add a javadoc @author tag in the class header for each student.
- Each student submits a copy of your finished .java source code file to PolyLearn.
- Both partners should configure their CSL account with the
BlueJ launcher.
Summary
Since maintenance accounts for 80% of most organizations software
budget, writing readable code can produce significant cost savings
for a software team.
You may find that correcting Checkstyle violations is somewhat
tedious. To avoid this, familiarize yourself with the class coding standard
and write your code in the correct style at the outset. That
will save a lot of time because you won't have to go back and
correct it when you are finished.
For Home Use:
The recommended version of BlueJ for CPE 305 is version 3.1.
Here are some directions
for
installing
BlueJ
and Checkstyle on your personal workstation.
Also, on Unix, Checkstyle is installed in the grader account.
To run the command line version:
~graderjd/bin/stylechecker myprogram.java
There is a draft version of a layout formatter extension for Bluej
which will auto-format the layout of your source code.
View website
It's a student project; if you find errors please inform the instructor.
Also, Ostrich
Software created the BlueJalopy code formatter. It's a student
project; if you find errors please inform the instructor.
NetBeans is a more powerful
(and complicated) IDE that has a plugin that allows it to open BlueJ
projects directly. If you have a lot of refactoring to do on a BlueJ
project, you might want to use the more powerful NetBeans IDE. Read more...
Here is a page about automatic
code formatting in NetBeans.
BlueJ FAQ