Java and Javac, JAVAP usage in Windows command line (Java compilation command) _java

Source: Internet
Author: User

The title, first we on the desktop, start-> run-> type cmd Enter, enter the Windows command line. Enter the picture as shown:

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

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

2, enter the command: E: Transfer to E-disk, and then enter the CD transfer to the desired known path.

As shown in figure:

If you want to use the Javac, Java, JAVAP commands at the Windows command line, the current computer must have the JDK installed, and the JDK's Bin directory is added to the environment variable path. That's not much to say. So let's take a look at how to use Javac, Java, and JAVAP.

First, Javac

Javac is used to compile. java files. Direct input to the command line Javac can see a lot of hints, prompts javac command usage, I only know commonly used.

javac-d Destdir Srcfile

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

Note: Adding the-D option allows you to specify the path of a compiled. class file, the biggest difference being that you can generate a folder under the current path for the package name under the Package keyword in the first line of the source file.

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

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

Copy Code code 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 the current path, the input Javac Javactest.java generates a Javactest.class file under the current path, as shown in the figure:

Note: Javactest.java is a first line of package Java file, and at this point its directory on the hard disk does not correspond to its package name, so use the Java 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, as shown in the figure:

Second, Java

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

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

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

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 the class under the current path. This must require that the-D option be used at compile time. Otherwise, you need to build the package hierarchy folder yourself.

Third, JAVAP

JAVAP is mainly used to help developers understand the Java compiler's mechanism, the main options are:

-C Decomposition method code, which shows the byte code specific to each method

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

-VERBOSE Specifies to show further details

Enter Javap-c Com/stoptalking/test/javactest, as shown in figure:

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.