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

'javac' - The Java Compiler

Part:   1  2  3  4  5  6  

Java Tool Tutorials

© 2006 Dr. Herong Yang

Latest updates:

  'javac' - The Java Compiler

  'java' - The Java Launcher

  'jdb' - The Java Debugger

  JAR File & 'jar' Tool

  Certificates and 'keytool'

  Installing J2SE 1.5.0

... Table of Contents

(Continued from previous part...)

Of course, we know how to fix the problem. Just remove ClsA.java and ClsB.java from the current directory. "javac" will continue to search for the ClsA in the package specified in "import com.herong.util;".

This test shows us that:

  • "Single type import" statements load classes immediately.
  • "javac" searches for definitions of new types first in the loaded classes, then in the source path, and finally in the packages specified in the "On-demand type import" statements.

"-g" Controlling Debugging Information

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 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.

Conclusions

  • "javac" is the standard compiler in JDK.
  • "-sourcepath" specifies places where to search for source definitions of new types.
  • "-classpath" specifies places where to search for class definitions of new types.
  • Two types of "import" statements behave differently with "javac".
  • Never distribute your class files with debugging information in them.

Part:   1  2  3  4  5  6  

Dr. Herong Yang, updated in 2006
Java Tool Tutorials - Herong's Tutorial Notes - 'javac' - The Java Compiler