Understanding and configuration of Java environment variables

Source: Internet
Author: User

(1) cross-platform Java: Windows has a win version JVM, Linux has a Lin version JVM, and Mac has a Mac version JVM. With JVM, the same Java program can be executed in three different operating systems. In this way, Java's cross-platform nature has been realized and Java has become highly portable.

(2) JRE (Java Runtime Environment) Java Runtime Environment, including the core class libraries required by Java Virtual Machine (JVM Java Virtual Machine) and Java programs. If you want to run a developed Java program, you only need to install JRE on your computer.

JDK (Java Development Kit) Java Development Kit. JDK is provided for Java developers, including Java development tools and JRE. Therefore, JDK is installed, you don't need to install JRE (you can choose to install the JRE directory again when installing JDK. In fact, the content is the same. After installation, it means that you have a registration on the registry of your local machine, which can be connected to the Internet for regular updates ). Among them, the development tool is javac.exe, and jar.exe. In short: Use the Java program developed by JDK to run it with JRE.

(3) Tools in JDK

Open the BIND files in the jdkinstallation directory, with many executable files. These are all DOS commands, not the user GUI. To run the command, you must run the doscommand on the local machine. Switch to execute the javac.exe command. Specify the file path D: \ Program Files \ Java \ jdk1.6.0 _ 21 \ bin. Do we need to specify the command file path every time we execute a Java program? If the javac command is not executed in the Directory D: \ Program Files \ Java \ jdk1.6.0 _ 21 \ bin, the system will prompt that it is not an internal or external command. We can play a small example in DOS to open the Mine Clearance program. In the current directory D: \ Program
Files \ Java \ jdk1.6.0 _ 21 \ bin and run winmine. The game is started. Think about why? Let's take a look at where the winmine.exe program is located? Originally under C: \ Windows/system32, I thought that C: \ Windows/system32. exists in path in my computer -- "properties-" advanced-"system variable .. So, we only need to take the bin path under the JDK Installation Directory D: \ Program Files \ Java \ jdk1.6.0 _ 21 \ bin as the variable value of path, that is, in the path attribute value, the cursor is positioned at the beginning and pasted D: \ Program.
Files \ Java \ jdk1.6.0 _ 21 \ bin; OK. In this way, you can run the javac command in any path under DOS.

The JDK installation path is updated, converted to another disk, or the installed file name is changed. When the path in the path changes, those javac commands cannot be executed. However, we think that the bin directory remains unchanged, so we should set the path that may change earlier, such as D: \ Program Files \ Java \ jdk1.6.0 _ 21, as the value of a variable, in the future, we can change it in the path area to avoid other path names being deleted. Therefore, we add a system variable value Java with the value D: \ Program Files \ Java \ jdk1.6.0 _ 21. Get % java_home % in path.

Temporary configuration of environment variables: This occurs when Java programs are developed on other people's computers. Because someone else's computer is used, it is best not to modify the configurations on someone else's computer. SET command to view the environment variable values of all commands. You can view the value of path in set path. Set Path = ??? Set the PATH value. (Set is only valid in the face-to-face window ). You only need to set Path = D: \ Program Files \ Java \ jdk1.6.0 _ 21 \ bin in DOS to use all the commands in this directory. Set Path = ???; % PATH % get the original path value.

(4) Steps for running the Java program

*. Java file --> javac -->. Class file --> JAVA --> running result.

Executing the. Class file using Java commands is only executed in the current folder, and returning to the upper-level directory cannot run the Java command. So we can also put the class file path executed by Java into the environment variable. Define the path of the class file using the environment variable classpath. When the program executes the Java command, the system starts to start JVM to search for class files. You can use set classpath = to clear the image. This means that you can switch to the path where the class file is located and run the. Class file in the current directory by executing the Java command.

    

   

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.