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:

Last update: 2015.

Table of Contents

 About This Book

 Java Tools Terminology

 Installing Java 8 on Windows

'javac' - The Java Program Compiler

 '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

 'java' - The Java Program Launcher

 'jdb' - The Java Debugger

 'jconsole' - Java Monitoring and Management Console

 'jstat' - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 jvisualvm (Java VisualVM) - JVM Visual Tool

 'jar' - The JAR File Tool

 'javap' - The Java Class File Disassembler

 'keytool' - Public Key Certificate Tool

 'native2ascii' - Native-to-ASCII Encoding Converter

 Outdated Tutorials

 References

 PDF Printing Version