How to set Java environment variables
Download the jdk required for java environment variable setting and install it. Download address: http://download.oracle.com/otn-pub/java/jdk/7u2-b13/jdk-7u2-windows-i586.exe
1, java environment variable setting-lite version
1. Right-click to open My Computer->Properties->Advanced->Environment Variables
2. Create a new system Variables JAVA_HOME and CLASSPATH
Variable name (N): JAVA_HOME
Variable value (V): C:\Program Files\Java\jdk1.7.0
Variable name (N ): CLASSPATH
Variable value (V): .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;
3. Select "System Variables" In the environment variable named "Path", double-click the variable, add the absolute path of the bin directory in the jdk installation path to the value of the Path variable, and use a half-width English semicolon to separate it from the existing path.
Variable name (N): Path
Variable value (V): %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;
2, java environment variables Settings - Detailed version
After installing jdk to the computer (here jdk1.7 is used to install it, the same is true for other versions), and then setting it up, the java environment can take effect.
First, right-click My Computer. Open properties. Then select "Environment Variables" in "Advanced". In the newly opened interface, you need to set three system variable attributes "JAVA_HOME", "Path", and "CLASSPATH". Before jdk was installed, the path attribute originally existed, but the two system variables
JAVA_HOME and CLASSPATH did not exist and needed to be created.
Click "New", and then write JAVA_HOME in "Variable Name (N)". The JAVA_HOME variable represents the installation path of java. Then write the path just installed "C:\jdk1.7" in the change value (N).
(Note: If the installation path is not disk C or is not in the jdk1.7 folder, it can be modified accordingly. The following text is assumed to be installed in C:\jdk1.7.)
Second, find Path in the system variable, and then click "Edit". The Path variable indicates that the system can recognize the java command in any path. Then write ".;%JAVA_HOME%\bin" in the change value (N) (where "%JAVA_HOME%" means the value of JAVA_HOME just set), or directly write "C:\jdk1 .7\bin", it is recommended to use the former because of its high reusability.
Third, click "New" again, and then write CLASSPATH on the variable name. The CLASSPATH variable represents the java loading class (class or lib) path. Only the class is in CLASSPATH , the java command can recognize it. Then write ".;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\toos.jar" in the change value (N) (add . to indicate the current path)
Finally, after the java environment variable is set, press "OK" until the properties window disappears, that is, the save is successful.
Verify whether the java environment variable is set successfully. First open "Start"->"Run" and type "cmd" to enter the DOS system interface. Then enter "java -version" if the installation is successful. The system will display java version jdk "1.7.0". This way the java environment variable setting is OK!
Summary, the purpose of setting java environment variables:
1,JAVA_HOME
(1) For the convenience of reference, for example, your jdk is installed in C:\ In the Program Files\Java\jdk1.7.0 directory, set JAVA_HOME as the directory path. Then when you want to use this path in the future, you only need to enter %JAVA_HOME% to avoid entering a long path string for each reference;
(2) Normalization principle, when your jdk path needs to be changed, you only need to change the variable value of JAVA_HOME, otherwise you will have to change any document that uses an absolute path to reference the jdk directory. If you fail to change everything and a certain program cannot find jdk, the consequence may be that the program crashes;
(3) The third-party software will reference the agreed JAVA_HOME variable so that the software can be used normally. After using JAVA for a long time, you will know that if a certain software cannot be used normally, it is probably caused by the incorrect JAVA_HOME setting;
2, CLASSPATH
The purpose of setting CLASSPATH is In order for the program to find the corresponding ".class" file, for example: Compile a JAVA program ---A.java, and you will get an A.class class file. Execute java A in the current directory, and you will get the corresponding Result (provided that
CLASSPATH has been set to "."). Now, move A.class to another directory (for example: "e:\"), execute java A, and java will be thrown .lang.NoClassDefFoundError exception, the reason is that the .class file cannot be found. Now you increase CLASSPATH to: ".;e:\" and then run java A. The result is that everything is normal. The java command found the .class file through CLASSPATH!
3,PATH
Do you want to use %JAVA_HOME%\bin\java to execute java commands at any time? Of course not, so you can choose to add %JAVA_HOME%\bin to the PATH path, so that we can You can just use java to execute commands under the path. (When you enter your code in the command prompt window, the operating system will search for the corresponding application in the current directory and the PATH variable directory, and execute it.
Three, java environment variable setting - error case
Error: java.lang.NoClassDefFoundError
Description: When the Java virtual machine or ClassLoader instance attempts to define a class This exception is thrown when the class is loaded (as part of a normal method call or as part of a new instance created using a new expression), but the definition of the class cannot be found.
Cause: The java environment variable is set incorrectly.
The above is the detailed content of How to set Java environment variables. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.
