Click to enter _ more _java thousand ask
1. What is Javac?
The JAVAC is the Java programming language compiler, located in the Jdk/bin directory, which reads source files (. java) written in the Java programming language and compiles them into bytecode class files (. Class). The compiler compiles the annotations (annotations) in the source code together, but removes the comments.
See note comments here: [What is the difference between annotations and annotations][2]
Javac can also implicitly compile some source files that are not mentioned in the command line. When compiling a source file, the compiler often requires information about a type that it does not yet recognize. For each class or interface that is used, extended, or implemented in the source file, the compiler requires its type information. This includes classes and interfaces that are not explicitly mentioned in the source file, but that provide information through inheritance.
Understanding inheritance See here: what is the meaning of the inheritance of Java classes
2. How to use Javac
The Javac tool can then be executed in the operating system where the JDK is installed. Learn how to install the JDK here: How to install and configure the JDK
Open the command terminal of the operating system, enter the appropriate command line, you can use the Javac, the specific syntax is as follows:
Javac [Options] [SourceFiles] [@files]
Where parameters can be arranged in any order. The parameters are described as follows:
Options
command-line options, direct execution of Javac or javac-help will show all options operations, mainly:
-classpath
Class path, which sets the path of the user class, overwriting the user class path in the CLASSPATH environment variable. If neither classpath is specified and no-classpath is specified, the user class path is composed of the current directory. Multiple path items with a semicolon ";" to separate.
-sourcepath
The source path that specifies the source code path that is used to find the class, interface definition. They can be directories, jars, or zip. Note that the Classpath lookup, if its source file is found, is automatically recompiled. As with the user class path, multiple source path entries are separated by a semicolon ";" to separate.
If you use a package, the local path name in the directory or archive must reflect the package name. For example, to introduce a package that is a source file for com.test (COM in the SRC folder), you need to specify a top-level directory for COM:
Javac-sourcepath src Test.java
-D
Specifies the location where the generated class file is stored, and if not specified, the class file is placed in the source file directory. You need to specify an existing directory, and you cannot create folders automatically.
-encoding
Sets the source file encoding, such as Utf-8. If the-encoding option is not specified, the platform default encoding is used.
-G
Generates all debugging information, including local variables. By default, only the row number and source file information are born.
-g:none
No debug information is generated.
-verbose
Outputs a message about the operation the compiler is performing. It includes information about each loaded class and each compiled source file.
-version
Print Javac version information, which is the version of the JDK.
SourceFiles, @files
One or more source files to compile.
Compile a file and write the source file name directly, for example:
Execute: Javac test.java, generate compiled file Test.class.
To compile multiple files, you need to create a new file (without a suffix), write the source file that needs to be compiled, and then add the prefix @. For example:
New file: Javalist, its contents:
Test1.java
Test2.java
Test3.java
Execute: Javac @javaList, generate compiled Files Test1.class, Test2.class, Test3.class.
3. How to execute Javac through code
For Javac, not only can we execute directly in the operating system, it also provides several APIs that you can use to write code to complete the compilation.
See here: [How to use Javacapi to compile source files by code][5]
Java thousand asked _08jdk detailed (007) _javac is what