📅 2015-Feb-19 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ checkstyle, eclipse, findbugs ⬩ 📚 Archive
Prof. Sedgewick has written a popular Algorithms book and developed Algorithms I and II courses on Coursera. Both of these use Java and provide many source code files and assignments to the students. These have been developed for the Dr. Java IDE or to work from the commandline. If you prefer to work with Eclipse for this book or course, just follow these steps:
$ sudo apt install openjdk-7-jdk
Install Eclipse. Ubuntu ships with old versions of Eclipse. I prefer to install the latest from the Eclipse Downloads webpage. Get the one named Eclipse IDE for Java Developers.
Create a directory named
algs4 anywhere under your home directory. This directory will be used to store the packages and configuration files required to work with this book or course.
Download the algs4.jar and stdlib.jar packages to the
algs4 directory. These include the classes and methods you will need to work on the assignments.
Install the FindBugs plugin as described here. This will be useful to check your assignment code for bugs before you submit them. Download the findbugs.xml filter file to your
algs4 directory. In the FindBugs preferences dialog, add this file as an Exclude filter file.
Install the CheckStyle plugin as described here. Your assignment submission has to adhere to the coding standard of this book or course and this plugin makes it easy to check that. Download the checkstyle.xml configuration file to your
algs4 directory. Add this configuration file in the CheckStyle preferences.
Using this CheckStyle configuration file in Eclipse gave me these errors:
cannot initialize module TreeWalker - Unable to instantiate RedundantThrows cannot initialize module TreeWalker - Unable to instantiate JUnitTestCase
I removed the lines in
checkstyle.xml that used these modules and it worked after that. My version of this configuration file can be downloaded here.
You are now ready to work on the assignments! 😊 Create a new Java project in Eclipse to work on each new assignment. Use the
stdlib.jar packages in the project by adding them in Properties -> Java Build Path -> Libraries -> Add External JARs.
Each assignment provides a barebones template of one or more Java classes. Choose New -> Java class to create a new Java file for each of these classes under the project for that assignment.
Important: When creating the Java class, make sure the Package entry is empty. This puts it under the
default package. This is required since the
stdlib.jar also provides their classes under the
default package. If you do not do this, you will get a
cannot be resolved to a type error when you try to use any of the classes from this course.
Eclipse automatically compiles the code whenever you save the file. So, you can run the code as soon as you are done writing the code. Make sure to run the CheckStyle and FindBugs before you submit your code.
Tried with: CheckStyle 6.2, FindBugs 3.0.0, Eclipse 4.4.1 (Luna) and Ubuntu 14.04