It is very important to make sure we have a successful compile before handing off code to others (or submitting).

Here are a couple different approaches to verify a successful compile.

Verification Approach #1 -- Error Check


Failed Compile -- Errors
C:\Work\Scratch>javac Foo.java
Foo.java:10: error: cannot find symbol
                computeWidth();
                ^
  symbol:   method computeWidth()
  location: class Foo
1 error

C:\Work\Scratch>


A failed compile will have errors as shown here.

We would then investigate and fix the errors. Note that Java helps us by telling us the line number of the error(s). Line "10" in the example.


Successful Compile -- No Errors
C:\Work\Scratch>javac Foo.java

C:\Work\Scratch>


A successful compile will not have errors as shown here. The compile comes out "clean".


For a successful compile, a CLASS file will be generated. For a failed compile a CLASS file will not be generated.

Steps:

  • Delete the existing CLASS file (if it exists).
  • Compile
  • Check to see if a CLASS file is generated. If so, that means we have a good (clean) compile. Otherwise, we have a failed compile that we need to investigate.

Note: The file timestamp of the ".class" file should be later than the ".java" file.