This chapter describes the Java compilation tool 'javac'. Topics include listing of 'javac' options, specifying class path with '-classpath', specifying source path with '-sourcpath', processing 'import' statements, generating debugging information with '-g'.
If you are writing a real Java application, you will organize your Java classes into packages.
The Java source files must be stored in a directory with the path names match the package names.
For example, if a source file, Some.java, is defined in a package name as: "com.herong.util", it must be
stored in a directory named as: .\com\herong\util\Some.java.
By default, "javac" will output the class file in the same directory as the source file.
But you can change this default behavior by using the "-d" option. It will make "javac"
to output the class files into the specified directory.
To test this option, I wrote the following Java source file: PackagedHello.java
/**
* PackagedHello.java
* Copyright (c) 2006 by Dr. Herong Yang, http://www.herongyang.com/
*/
package com.herong.util;
public class PackagedHello {
public static void main(String[] a) {
System.out.println("Packaged: Hello world!");
}
}
Test 1 - Storing PackagedHello.java in the wrong directory: