CSC 103 Laboratory Activity
Checkstyle Lab

Part 1

  1. Login to your account on a CSL workstation.
  2. If you haven't setup your account to run BlueJ, then make a launcher for BlueJ.
  3. 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. /home/yourusername/.bluej/extensions
    (In the file manager, View -> Show hidden files will reveal "dot" folders. You should create the extensions directory if it doesn't exist. )
    Restart BlueJ.
  4. 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/easystyleBlueJ.xml
  5. From the "Project" menu select "New Project". (You may name it "Lab1".)
  6. Click the "New Class" button to create a new Java class named GridGuess.
  7. Right-click on the newly created GridGuess 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.
  8. Copy and paste the source code for GridGuess.java into the editor window.
  9. Click the "Compile" button. In the status window you should see the message "Class compiled - no syntax errors."
  10. In BlueJ's main window, right click on the GridGuess class in the diagram and select "Run Applet". In the dialog which appears, select the radio button for "Run Applet in appletviewer" and click "OK".
  11. The applet should execute, displaying a 5 by 5 grid. You may may play the game, clicking on cells trying to discover the green one. Quit the Applet when you are finished.

Part 2

  1. From the main window (not the editor) open the Tools menu and select Checkstyle. In the window that appears, click on "GridGuess" in the left-hand panel. A list of checkstyle violations appears along with the corresponding line number. (You might want to turn on line numbering in BlueJ: Tools -> Preferences -> Editor -> Display line numbers.)
  2. 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 change in the editor and click "Compile" the Checkstyle window will automatically refresh itself. The following strategy is suggested:
    1. Look for errors whose message is immediately obvious. For example, on line 15, "'{' should be on a new line" needs no further explanation.
    2. From the Edit menu, select Auto-Layout to fix indentation errors.
    3. Where comments are required, provide a meaningful comment.
    4. 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.
    5. Read an explanation for a few of the most common errors.
    6. If the error message doesn't make sense to you, consult the Checkstyle documentation for an explanation of the error message.
    7. As a last resort, consult the instructor.
  3. Review the coding standard checklist and study the GridGuess 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

  1. Make sure the program compiles and executes correctly.
  2. Add a javadoc @author tag in the class header with your name.
  3. Print out your finished source code (as described in the syllabus) and bring it to the next class meeting.
  4. Both partners should configure their CSL account with the BlueJ launcher.
  5. Buy a blank lab notebook and prepare it for use according to the lab notebook guidelines. For the first lab entry in your notebook, make any notes about Checkstyle and the coding standard that you will want to refer to during future programming assignments.

Notes

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.


Instructor