First, on the desktop, we go to Start->Run->type cmd and press Enter to enter the windows command line. Enter the screen as shown in the figure:
It can be seen that the current default directory is the Administrator folder under the Users folder on the C drive. Generally speaking, we are used to changing the current directory. Since Windows has disk partitions, if you want to jump to other disks, such as E drive, there are several methods:
1. Enter the command: pushd path (this command can set the current directory to any existing path you want)
2. Enter the command: e: to transfer to the e drive, 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 under the windows command line, then the current computer must have jdk installed, and add the jdk bin directory to the environment variable path. This goes without saying. So let's see how to use javac, java, javap.
1. javac
javac is used to compile .java files. If you directly enter javac on the command line, you can see a lot of prompt information, prompting the usage of the javac command. 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 .class file. (If this option is omitted, the .class file will be generated in the current directory by default, and no package folder will be generated; the current directory can be represented by ".", that is: javac -d . srcFile)
Note: In addition to adding the -d option to specify 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 used to generate a folder under the current path.
2. srcFile is the path of the source file .java file.
For example: There is such a simple java class with the path E:/test/JavacTest.java:
Copy the 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, enter javac JavacTest.java, and a JavacTest.class file will be generated under the current path, as shown in the figure:
Note: JavacTest.java is a java file with package marked on the first line. At this time, its directory on the hard disk does not correspond to its package name. Therefore, it cannot be found when running java com.stopTalking.test.JavacTest. 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 want to run this class. In most textbooks, it can be run directly using java JavacTest, but we found this error:
This is because most textbooks use classes with default package names, that is, the first line of the source file does not specify a package name. To use a class, we know that you need to use its fully qualified class name.
Therefore, we enter: java com/stopTalking/test/JavacTest on the command line and we can see the correct results:
Summary: To use a simple java command to run a .class file, you not only need to use the fully qualified class name of the class, but also need to have the package level folder of the class under the current path. This requires compiling with the -d option. Otherwise, you need to create the package hierarchy folder yourself.
3. javap
javap is mainly used to help developers deeply understand the mechanism of the Java compiler. The main options are:
-c decomposes the method code, that is, displays the specific bytecode of each method
-public | protected | package | private is used to specify which level of class members to display
-verbose specifies to display further detailed information
Enter javap -c com/stopTalking/test/JavacTest, as shown below: