Java Tool Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 5.00

Option "-g" - Controlling Debugging Information

This section provides a tutorial example on how to use the '-g' option to generate debugging information into the class output files. Debugging information in class file can be used by any debugging tools.

As we see earlier, the "-g" compiler option can be used to control how much debugging information should be generated into the class files. Here are the choices on how to use this option:

Choice   Option                 Information generated in class
     1   -g:none                No debug information
     2   -g:lines               Line number only
     3   -g:lines,source        Line number & source file
     4   (default)              Same as #3
     5   -g:lines,source,vars   Line number, source file & variables
     6   -g                     Same as #5

Of course, the more debugging information you generate in a class file, the more debugging power you will get when you debug this class. However, once your source code is fully debugged, you should recompile your code with "-g:none", so that you don't distribute you class file will any debugging information.

Leaving debugging information in your class file will have the following negative effects:

  • Class file will be larger - Harder to distribute. Longer time to load.
  • Easier for others to reverse engineer your source code.

Sections in This Chapter

'javac' - Java Compilation Command and Options

Compiling Hello.java - My First Java Program

Option '-classpath' - Specifying Class Path

Option '-sourcepath' - Specifying Source Path

Option '-d' - Specifying Output Directory

Two Types of 'import' Statements

'import' Statements Processed by 'javac'

Option "-g" - Controlling Debugging Information

Dr. Herong Yang, updated in 2008
Option "-g" - Controlling Debugging Information