"Configuration issues for Java environment variables"

Source: Internet
Author: User

The first is the relationship between the JVM, the JRE, and the JDK:

The cross-platform nature of Java relies on Java virtual machines: The JVM (Java Virtual machine), while the JRE (Java Runtime Environment, the Chinese name is called the Java Runtime Environment) includes the JVM and the core class libraries required by the Java program. The JDK (Java development ' Skit,java SDK) is for Java developers, which includes Java development tools (Javac, Java, Javadoc, etc.) and JRE, so the JDK is installed, There is no need to install the JRE separately.

Simply put: Use the JDK to develop a Java program and then run it using the JRE.

Configuration and troubleshooting of environment variables:

The simplest way is to add the bin path of the JRE directly to the PATH environment variable. This is a once and for all method, but there are potential risks, such as each upgrade of the JDK, you need to modify the environment variables, so you need to modify the contents of the path, because the PATH environment variable contains other important software path information in the system, if due to misoperation and delete, Modifying some or all of the information in a path is not worth the candle.

The workaround is to create a new system environment variable: java_home, the bread with the path information before the JRE, only need to add%java_home%\jre\bin in the PATH environment variable, so that even if the JDK upgrade, you only need to modify the Java_home variable, You do not need to modify the path. % here is just the default delimiter for the system, which indicates that a path named Java_home environment variable is referenced.

Use the SET command to modify, delete, and view environment variables.

You can see all the environment variables for the current system by typing set carriage return under the DOS command window.

Using the SET command does not affect the value of the actual environment variable, only valid until the current DOS window is closed.

To view the value of the PATH environment variable: set path

Add environment variable: set path= new environment variable;%Path%

Empty Path environment variable: set path=

The advantage of using the SET command is that when you want to develop a Java program on someone else's machine, you can add the path of the JRE for the USB flash drive to the TEMP environment variable, and the DOS window will revert back as it is closed.

Classpath settings for changing environment variables:


Assuming the C drive has c:/myclasses, and the current directory is d:/myclasses, if we want to run files in c:/myclasses, we need to switch folders, which is troublesome, we usually set the classpath path to solve this problem: set Classpath=c:/myclasses, so that we can run the file (. Class) in C:/myclasses even under the D drive. However, this can cause a problem: The file under the current path cannot be run, and the prompt cannot find the file (if there is no file with the same name under C:/myclasses), if we set myclasspath=c:/myclasses; The reason is that the former force the specified class of files, can not find the error, regardless of whether the current folder is not. Many people will want to use the latter, but this is not right, because we set the class folder, obviously does not have this file but out of the running results, this will lead to depressed very much. If you have to run the files in the current folder, use Set path=.; C:/myclasses, which. Represents the current folder and subdirectories.

If you are prompted for errors such as class names, the top priority is to consider two things:

1. Whether the file name and the main class name are the same (public)

2. Check the set Classpath to see if it ends.

"Configuration issues for Java environment variables"

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.