13 Quality
Oracle Academy Section
None
Textbook Chapters
Appendix F: Program Style, Formatting, and Documentation
Read the book using the SQ3R technique.
Java Foundations Certification Exam Topics
The content of this module is not on the certification exam.
Key Resources
Exercises
No exercises for this module.
Most Important Concepts / Code
SpotBugs
To install the SpotBugs plugin:
Help -> Eclipse Marketplace -> search for SpotBugs
To use SpotBugs Bugs:
Window -> Preferences -> Java -> SpotBugs -> slide "Minimum rank to report" all the way to the right (20)
Right click on a Java project in Package Explorer -> Spot Bugs -> Find Bugs
Problem markers will be displayed in source windows and in Window -> Show View -> Other -> SpotBugs -> Bug Explorer
If no bugs are being found, first make sure you have a bug by adding the following into a method: System.out.println("bug".substring(0)); then save the file and do Find Bugs
If that line doesn't show up as a bug, uninstall and reinstall SpotBugs using Help -> Installation Details
Scanner scan = new Scanner(System.in, "UTF-8");
Javadocs
Create / format documentation
In Eclipse: Source -> Generate Element Comment (Alt + Shift + J) when your cursor is on the line for every class, field, constructor, and method declaration
Description
A required component of every doc.
The first sentence (end in a period). It should be a summary sentence, concise but complete.
Optionally, include an additional <p> tag and a longer description.
Block tags:
More comprehensive information: How to Write Doc Comments
Create and access Javadoc file
Project -> Generate Javadoc
javadoc command is the path to your javadoc.exe. Probably in C:\Program Files\Java\jdk1.n.n_n\bin
Find generated web page at workspace/projectname/doc/index.html
Sample doc comments in a class
/**
* Represents a student enrolled in the school.
* A student can be enrolled in many courses.
* @author Your Name
*/
public class Student {
/**
* The first and last name of this student.
*/
private String name;
/**
* Gets the first and last name of this Student.
* @return this Student's name.
*/
public String getName() {
return name;
}
/**
* Changes the name of this Student.
* This may involve a lengthy legal process.
* @param newName This Student's new name.
* Should include both first
* and last name.
*/
public void setName(String newName) {
name = newName;
}
}
Checkstyle
To install the Checkstyle plugin: Checkstyle Installation
To use: right click on the project in the Package Explorer, find Checkstyle, then Check code with Checkstyle
Style errors will appear in the Problems tab. Eclipse: Window -> Show View -> Problems
Tips:
After each change to your code, save the file and go through the process to check the style again
If you don't see Checkstyle when you right click your project, update Eclipse.
See Style focus for Eclipse tips related to indentation.
You may need to highlight a tab character, and do Edit -> Find/Replace to replace with 2 spaces.
Hour 1
Quiz and Concepts Review
SpotBugs
Hour 2
Javadoc
CheckStyle
Integration Project
Adhere to Google Java Style (at least one substantial class with no CheckStyle warnings)
Demonstrate best practices for documentation (your name in each file, comments to explain any non-obvious code, cite sources, at least one substantial class with a doc comment for the class and all fields, constructors, and methods)