Windows command line Java and Javac, JAVAP use in detail (Java compile command)

Source: Internet
Author: User

Recently reviewed the Java basics, here is how to compile, run, and decompile a class file. And let yourself deepen your impressions.

Title, first we are on the desktop, start-and-run, type cmd Enter, enter the Windows command line. Enter the screen:

The current default directory is the Administrator folder under the Users folder of the C drive. Generally, we are accustomed to changing the current directory. Because Windows has a disk partition, there are several ways to jump to another disk, such as E-drive:

1. Enter command: pushd path (This command can set the current directory to any existing path you want)

2. Enter the command: E: Transfer to E-drive, then enter the CD to move to the desired known path.

To use commands such as Javac, Java, JAVAP, and so on, at the Windows command line, the current computer must have the JDK installed and the JDK's Bin directory added to the environment variable path. That's not much to say. So let's look at how to use Javac, Java, JAVAP.

First, Javac

Javac is used to compile the. java file. Direct Input Javac command line can see a large number of prompt information, prompting the use of Javac command, I only know what is commonly used.

javac-d Destdir Srcfile

Where: 1,-D destdir is used to specify the path to the. class file where the compilation was generated. (If this option is omitted, the. class file is generated by default in the current directory, and no package folder is generated; The current directory can be used "." To express, namely: javac-d. Srcfile)

Note: To add the-D option, in addition to specifying the path to the. class file that is compiled, the biggest difference is that you can generate a folder under the current path for the package name under the Packages keyword on the first line of the source file.

2. Srcfile is the path of the source file. java file.

For example: There is a simple Java class with a path of E:\test\JavacTest.java:

Copy CodeThe code is as follows:
Package com.stopTalking.test; public class Javactest {public static void main (string[] args) {
byte a = 5;
Short B = 6;
System.out.println ("Javactest [a=" + A + ", b=" + B + "]");
}
}

Under current path, enter Javac Javactest.java, and a Javactest.class file is generated under the current path.

Note: Javactest.java is a Java file with the package in the first line, and its directory on the hard disk does not correspond to its packet name, so use Java The Com.stopTalking.test.JavacTest runtime is unable to find the Java.

If input, javac–d. Javactest.java, the generated javactest.class is in the package file generated in the current directory,

Second, Java

At this point, we want to run this class, in most of the textbooks, the use of Java Javactest can be run directly, but we found that there are errors:

This is because most textbooks use a class that is the default package name, that is, the first line of the source file does not have a package name assigned to it. Using a class, we know that it is necessary to use its fully qualified class name.

So, we can see the correct result on the command line: Java com/stoptalking/test/javactest:

Summary: Running a. class file with a simple Java command requires not only the fully qualified class name of the class, but also the package hierarchy folder for that class under the current path. This must require compile-time with the-D option. Otherwise you will need to create the package hierarchy folder yourself.

Third, JAVAP

JAVAP is primarily used to help developers understand the mechanics of the Java compiler, the main options are:

-C Decomposition method code, which shows the specific bytecode for each method

-public | protected | Package | Private to specify which level of class members to display

-VERBOSE Specifies that further details are displayed

Input Javap-c com/stoptalking/test/javactest, display

Windows command line Java and Javac, JAVAP usage details (Java Compile command) (RPM)

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.