Close

Java - By default what debug information is added in class file?

[Last Updated: May 20, 2018]

Java Tools & Commands 

By default javac includes only line number and source file information in the compiled class file which is equivalent to
-g:source,lines.
Also check out what is -g option?.

Let's confirm what debug info is included in the class file with an example.

public class Test {

  public void execute(int myNumber, String message) {
  }
}
D:\java-class-default-debug-info>javac Test.java

Let's use javap command with -l option (-l option prints line and local variable tables).

D:\java-class-default-debug-info>javap -l Test
Compiled from "Test.java"
public class Test {
public Test();
LineNumberTable:
line 2: 0

public void execute(int, java.lang.String);
LineNumberTable:
line 5: 0
}

No local variable names are included.

Let's compile with vars and other information included:

D:\java-class-default-debug-info>javac -g:vars,source,lines Test.java
D:\java-class-default-debug-info>javap -l Test
Compiled from "Test.java"
public class Test {
public Test();
LineNumberTable:
line 2: 0
LocalVariableTable:
Start Length Slot Name Signature
0 5 0 this LTest;

public void execute(int, java.lang.String);
LineNumberTable:
line 5: 0
LocalVariableTable:
Start Length Slot Name Signature
0 1 0 this LTest;
0 1 1 myNumber I
0 1 2 message Ljava/lang/String;
}

As seen this time local variables names are also included.

See Also