It Usually Begins with javac

While you can't overlook the fact that the standard Java compiler javac from Sun includes a lot of error checking that is mandated by the Java language, you can easily miss the fact that it has a bunch of extra checking that is yours for the asking. Simply add the command-line option -Xlint and you will see a number of additional warnings. You can optionally append a comma-separated list of categories to this option, as shown in the "javac Xlint options" table—for example, -Xlint:deprecation,unchecked will run the standard compiler with extra details on use of deprecated code and unchecked type conversions.

javac -Xlint options




Enable all optional warnings; default if -Xlint appears alone on the javac command (Sun's documentation reads, "Enable all recommended warnings. In this release, all available warnings are recommended.")


Disable all optional warnings; default if -Xlint is not present on the javac command.


Enable/disable warnings about deprecated code, code that is no longer a recommended part of the API.


Enable/disable detailed warnings about unchecked type conversions.


Enable/disable warnings about case labels that should be preceded by break or other flow control but are not.


Enable/disable warnings about missing/unreadable CLASSPATH entries (my favorite!)


Enable/disable warnings about missing "serial version unique identifiers" (discussed in the section "Enabling Useful Warnings" under Eclipse). ...

Get Checking Java Programs now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.