As the question is, first we start on the desktop, start -> Run -> type cmd to enter, and enter the windows command line. Enter the screen as shown in the picture:
It can be seen that the current default directory is the Administrator folder under the Users folder of the C drive. Generally speaking, we are used to changing the current directory. Since Windows has disk partitions, there are several ways to jump to other disks, such as E disk:
1. Enter the command: pushd path (this command can set the current directory to any existing path you want)
2. Enter the command: e: transfer to e disk, and then enter cd to transfer to the desired known path.
As shown in the picture:
If you want to use javac, java, javap and other commands on the windows command line, then the current computer must have jdk installed and add the bin directory of jdk to the environment variable path. Needless to say, this is not a big deal. So let's take a look at how to use javac, java, and javap.
1. javac
javac is used to compile .java files. By directly entering javac on the command line, you can see a lot of prompt information, prompting the usage of javac commands, I only know the commonly used ones.
javac -d destdir srcFile
Among them: 1. -d destdir is used to specify the path to store the compiled and generated .class files. (If this option is omitted, then the .class file is generated in the current directory by default, and no package folder is generated; the current directory can be represented by ".", that is: javac -d . srcFile )
Note: In addition to specifying the path of the compiled .class file, the biggest difference is that the package name under the package keyword in the first line of the source file can be generated in the current path.
2. srcFile is the path to the source file.java file.
For example: There is such a simple java class with the path E:/test/JavacTest.java:
The code copy 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 + "]");
}
}
In the current path, enter javac JavacTest.java, and a JavacTest.class file is generated under the current path, as shown in the figure:
Note: JavacTest.java is a java file with package marked on the first line, and the directory on the hard disk does not correspond to its package name. Therefore, the runtime using java com.stopTalking.test.JavacTest cannot be found. java.
If you enter, javac d. JavacTest.java, then the generated JavacTest.class will be in the package file generated in the current directory, as shown in the figure:
2. Java
At this time, we hope to run this class. In most textbooks, we can run it directly using java JavacTest, but we found such an error:
This is because most of the textbooks use the default package name, that is, the first line of the source file does not have the package name specified by the package. Using a class, we know that it needs to use its fully qualified class name.
So, we enter: java com/stopTalking/test/JavacTest on the command line to see the correct result:
Summary: To run a .class file using a simple java command, you not only need to use the fully qualified class name of the class, but also need to have the package hierarchy folder of the class in the current path. This must require the -d option to be used at compile time. Otherwise, you need to create the package hierarchy folder yourself.
3. Javap
Javap is mainly used to help developers understand the mechanism of Java compiler in depth. The main options are:
-c Decompose method code, that is, display the specific byte code of each method
-public | protected | package | private Used to specify which level of class members to display
-verbose Specifies to display further details
Enter javap -c com/stopTalking/test/JavacTest, and the display is as shown in the figure: