'javac' - The Java Compiler
Part:
1
2
3
4
5
6
This chapter describes:
- "javac" Command
- Hello.class - My First Class File
- "-classpath" - Specifying Class Path
- "-sourcepath" - Specifying Source Path
- "-d" - Specifying Output Directory
- "import" Statements
- "-g" Controlling Debugging Information
"javac" Command
"javac": A command line tool that reads Java source files and compiles them into bytecode class files.
"javac" is distributed as part of the Sun JDK package. It has the following syntax:
javac [options] [sourcefiles]
where "options" is a list of options and "sourcefiles" is a list of Java source files.
Commonly used options are:
- "-help" - Displays a short help text.
- "-verbose" - Generates verbose output to standard output.
- "-classpath classpath" - Specifies a list of path names where the compiler will search for compiled type definitions.
If "-classpath" is not specified, the current directory will be used as the class path.
- "-sourcepath sourcepath" - Specifies a list of path names where the compiler will search for source type definitions.
If "-source" is not specified, the current directory will be used as the source path.
- "-d directory" - Specifies the directory where the compiler will store the generated class files.
If "-d" is not specified, the class files will be stored in the same places as the source files.
- "-g | -g:none" - Asks the compiler to generate debugging information into the class files
or generates no debugging information at all.
Hello.class - My First Class File
To test the compiler, I wrote the following Java file, Hello.java:
class Hello {
public static void main(String[] a) {
System.out.println("Hello world!");
}
}
Here is what I did in a command window to compile Hello.java into Hello.class:
>javac Hello.java
>dir Hello.*
416 Hello.class
116 Hello.java
>java Hello
Hello world!
(Continued on next part...)
Part:
1
2
3
4
5
6
|