Javac-----Java programming language compiler

Source: Internet
Author: User
Tags command line keyword list variables
Programming | Compiling JAVAC-----Java programming language compiler





* Summary


* Description


* Lookup Type


* File List


* Option


* Example


* Please refer to





synopsis[Summary]


javac [Options] [SourceFiles] [@files]


Oldjavac [Options] [soucefiles] [@files]


parameter suspicious bit arbitrary order


Options


Command line Options


SourceFiles


one or more of the original files


@files


one or more files with a list of original files





description[Description]

The
Javac Tool reads the definitions of classes (class) and Interfaces (interface) written by the Java programming language and compiles them into class files of byte code


There are two ways to pass the original file name to Javac


* A small number of documents, you can simply put file names on the command line


* A large number of files, the file name in a file, the filename is separated by a space (including tab) or a newline. After you add the "@" character to the file, use Javac to compile the





the original file must have a. java suffix name, and the class (class) file must have a. class suffix name. The original file and class file must have a root file name that locates the class (that is, the filename that removes the suffix). For example: A class named MyClass, The original file name should be Myclass.java, which will be compiled into a byte-code class file called Myclass.class.





The definition of a nested class (inner Class) produces additional class files. The file names of these classes are merged with the external class name (outer class names) and the nested class name. For example, Myclass$myinnerclass.class





you should place the original file in a directory that responds to their package tree. For example, if you place all the original files in the/workspace directory, the Com.mysoft.mypack.MyClass class's original file (that is, the. java file) should be/ Workspace/com/mysoft/mypack/myclass.java


[to Windows: above should be. For example, you put all the original files in the C:\workspace directory, the Com.mysoft.mypack.MyClass class of the original file should be C:\workspace\com\mysoft\mypack \myclass.java]





by default, the compiler places the class file (. class file) in the same directory as the original (. java) file. You can specify the target directory by using the-D option (see the description of the option)





Lookup Type


when compiling a file, the compiler usually needs information about types that it is temporarily unable to authenticate. The compiler requires the type information for each class or interface that is used in the file, extened or implemented. It includes classes or interfaces that are not significantly promotions in a file, but that may provide information through inheritance.


For example: When you inherit Java.applet.Applet, you also use the ancestors of the Applet class: Java.awt.Panel,


java.awt.container,java.awt.component and Java.awt.Object.


When the compiler needs type information, it looks for the original file or class file that defines the type information. The compiler first looks for the boottrap and extension classes (which, unless you use the compiler option, do not need to be concerned), and then finds the user's classpath. The user's classpath is defined by CLASSPATH environment variables or by using command-line option-classpath. (Details, please see * Set class path*), if you use the-sourcepath command-line option, the compiler will look for the original file under the path, otherwise the compiler will look for both the class file and the original file under the user classpath. You can set different bootstrap and extension classes by using the-bootclasspath and-extdirs command-line options; see cross-compilation options below





A successful lookup will find a class file, the original file, or both. Here's how Javac handles each situation


* Find a class file (. class file) but no original (. java file): Javac used the class file


* Find an original file but no class file: Javac will compile the original file and then use the generated class file


* Find both: Javac determines whether the class file expires. If the class file expires, Javac will recompile the original file and will use the updated class file. Otherwise, Javac will use the class file (no expiration)


By default, Javac determines whether a class file expires by comparing the date of the change of the original file and the class file. (The-xdepend option provides a slower but more reliable method)





idea: Javac will silently (without outputting information):-) compile those files that are not specified on the command line. Use the-verbose option to track the automatic compilation process.





[filelist] File list


to make the Javac command line short or simpler, you can specify one or more files, each containing a file name. At the command line, use the ' @ ' character before these files to specify that they are a list of files. When Javac encounters a name that begins with a "@", It will think that the file in the file name is the name of the file that needs to be processed


For example: You can list all the original files in a file called SourceFile. This file may be the case:





Myclass1.java


Myclass2.java


Myclass3.java


You can pass


% Javac @sourcefiles


[Windows:c:\jdk1.4\bin\javac @sourcefiles]


Compile Myclass1.java,myclass2.java,myclass3.java





options[Options]


Javac has a range of standard options that are supported by the current development environment and will continue to be supported in future releases. Some non-standard options are implemented specifically for current virtual machines and compilations. They will change in the future. (Non-standard option begins with-X)





Standard options[standard option]





1:-classpath <classpath>


sets the user classpath, overwriting the user class path in the CLASSPATH environment variable, and if Classpath and-classpath are not specified, the user path contains the current directory. (See Setup path for more details)


If the-sourcepath option is not specified, look for the class file under the user's classpath, and also look for the original file.


2:-D <directory>


sets the target directory for the class file. If a class is part of a package. Place the class file in the subdirectory of the reaction package name. (The directory will be created, if required.) For example: If you specify-d/home/myclasses and the class is Com.mypackage.myClass, then the class will be called/home/myclasses/com/mypackage/myclass.class


[windows: D c:\workspace, will produce C:\workspace\com\mypackage\MyClass.class]


If-D is not specified, Javac places the class file in the same directory as the original file


Note: Directories specified with the-D option are not automatically added to your user classpath.


3:-deprecation


displays each use or overload of "no reuse" members or classes, and if no-deprecation,javac will display only the original file names that use those classes or members.


4:-encoding


sets the encoding name of the original file, such as Eucjis/sjis (Japanese encoding), and uses the platform default conversion if-encoding is not specified


5:-G


produces all debugging information, including local variables. By default, debug information includes only line numbers and original file information. (Recommended use)


6:-g:none


does not produce debug information


7:-g:{keyword list}














Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.