Lab 01
Setup
Write a simple program to conform to
the Google
Java Coding Conventions.
-
Set up your Eclipse environment to conform to Google's styleguide
-
Set up the checkstyle tool to automatically verify your code
- Write a simple program to conform to the Google styleguide
-
Verify your program conforms to the guidelines by using checkstyle
-
Download the
xml settings file
- Open Eclipse
- Navigate to Window→Preferences
- In the tree on the left, click Java→Code Style→Formatter
- Click Import, and import the xml file downloaded from step 1
Eclipse will now use Google Formatting by default.
- Create a folder title 'Checkstyle' on your Desktop
- Download the latest version of checkstyle
here, and place it in the folder you just created
-
Download the
xml configuration file
and place it in the same folder
Write a program Greetings.java
that gives a proper greeting, and introduce yourself. Also
answer the following questions on each line:
- What’s your favorite color?
- Are you a cat, dog, or armadillo person?
- Do you like tacos?
Verify your code conforms to the guidelines by doing the following:
- Open a run dialog by pressing Win-R (hold the windows key and press R)
- Type cmd and press ENTER to open a command prompt
- Navigate to the location of your source code
- You can find the current folder you are located in
by typing 'cd ,' and pressing enter
- You can see the contents of the current folder by
typing 'dir'
- You can change directories by typing 'cd «name
of directory»'
- If the name of the directory is long, you can use
TAB to autocomplete
-
Type the following (all on one line!) to check your code:
java -jar C:\Users\«your name»\Desktop\Checkstyle\checkstyle-6.9-all.jar
-c C:\Users\«your name»\Desktop\Checkstyle\google_checks.xml
«java file»
If you see anything other than:
Starting audit...
Audit done.
Your code did not pass. Fix the errors and
try again
Greetings!
I am Dan.
My favorite color is neon brown.
I am a cat person.
I love tacos.
Upload the .java file to the dropbox under Lab01
Make sure it conforms to the style guidelines