Java Development Environment (2)
In the previous blog article, get started with JavaSE 3: Set up a Java Development Environment (1). We have configured a Path variable.
Two configuration methods, which must be mastered.
Path environment variable configuration method 2
Why should we change the second configuration form? What are the disadvantages of the first configuration method? Assume that two jdks are installed on my computer.
The number is 1.7, and the number is 1.8. I Just configured 1.8, so I need to configure 1.7, and I need to reconfigure the Path environment variable. It is possible to modify the Path Environment
The first method is not recommended because other things are deleted by mistake at the same time.
To configure the path environment variables, follow these steps:
A) re-open the Path of the system environment variable and delete the Path of the first configuration.
B) create a new environment variable name: JAVA_HOME; Add the variable value to JAVA_HOME: JDK installation directory.
Yes: E: \ Java \ develop \ jdk1.8.0 _ 25
C) Change the JDK directory in the path environment variable to % JAVA_HOME % \ bin; (% path name % is equivalent to reference path name)
D) Restart DOS and use javac to compile the Java source file and java to run the bytecode file again.
In this way, when using other JDK, we can only modify the JAVA_HOME variable without modifying the Path variable, so that other things will not be deleted by mistake.
Some other programs cannot run.
Let's take a look at the problem that occurs during the Java program running process. The following running result is a good example. This requires the use of another
The configuration of the system variable classpath.
Classpath environment variable configuration
Why do we need to configure the classpath environment variable? What is the role of the classpath environment variable?
In future Java program development, we only need bytecode files. If we run bytecode files in other directories, the result is
Similarly, it cannot run. Therefore, the path environment variables configured above can only be used together. To run bytecode files in any directory,
You need to configure the classpath environment variable. Therefore, it enables the. class file in the classpath directory to run in any directory.
Classpath environment variable configuration method
A) create a new variable name: classpath
B) variable value: it is set to the specified directory containing the class file. multiple directories are separated by semicolons. The directory I specified is: E: \ Java \ JavaSE \ Code;
C) Restart DOS and run the bytecode file in java.
D) we re-edit a Java source file on the desktop and request the output: Hello, world. The saved name is HelloWorld. java. Continue compilation and
Run.
E) The problem we encountered above is that the classpath environment variable we configured only contains the bytecode file under the E: \ Java \ JavaSE \ Code directory,
Therefore, the solution is to add the.; configuration at the beginning of the configured directory. Even if the current directory is used, search for the current directory first when searching the. class file.
Then, you can find and run the files in the order of directory configuration. Therefore, the configuration in the classpath directory is sequential.
F) Restart DOS and run the bytecode file on the desktop again.
The configuration classpath values we found on the Internet may vary, but the most include the following three Java class library files: rt. jar is
JAVA base class library. dt. jar is the class library about the runtime environment, and tools. jar is the tool class library. Let's take a look at these class libraries.
1) rt. jar by default, the loading path of the root classloader is placed in the claspath. This is another option. You can go to the rt. jar file in classpath and then use
The java-verbose XXXX method runs a simple class and you will know that the path of the JVM system root Loader is not only rt. jar, but most of
Jar is in this path.
2) tools. jar is used by the system to compile a class, that is, javac XXX. java. It is actually running java-
Calsspath = % JAVA_HOME % \ lib \ tools. jar xx. xxx. Main XXX. javajavac is the encapsulation of the preceding command, so tools. jar is not required.
Classpath.
3) dt. jar is a class library about the runtime environment. It is best to add a swing package when you use swing.
Therefore, the value of the last configured classpath environment variable is:.; E: \ Java \ JavaSE \ Code; % JAVA_HOME % \ lib \ dt. jar;
Difference between path and classpath
The pathcontext variable records executable files, such as the. exe file. Find the executable files in the current path first.
Find the path configured in the Environment Variable
The classpath environment variable records the directory where the java class runtime files are located.
Java-version:
The configuration for building a Java development environment is here.