If you use the javac compiler to compile your code for debugging, you can set breakpoints and step through your source code without using any compiler options. Use the -g option if you want to examine local, class instance and static variables while debugging.
Here is a partial list of compiler options to consider when compiling your classes:
Option | Purpose |
-g | Compiles your code with debug information. Use this option if you want to examine the contents of local variables when debugging your classes. You can still set breakpoints and step through your code if you do not compile your classes with this option. |
-O | Compiles and optimizes your code. Do not use this option if you want to debug your classes. If you compile your code with this option all debugging information is removed from the class during optimization. |
|
Overrides the CLASSPATH environment variable with the path specified by <path>. Use this option when you want to try compiling something without modifying the CLASSPATH environment variable. |
|
Determines the root directory where compiled classes are stored. This is useful since classes are often organized in a hierarchical directory structure. With this option, the directories are created below the directory specified by <dir>. |
For a complete list of compiler options, refer to documentation provided with the JDK.