There are many articles on the construction of Java environments on the Internet, including correct and wrong, original and copy, and some outdated.
I happened to have time today, so I briefly summarized the configuration of Java environment variables and added some instructions, hoping to help some newbies.
1. First of all, you need to understand what JVM, JRE, and JDK are
I have seen some programmers who have worked for one or two years and cannot explain these three concepts clearly.
JVM: java virtual machine
JRE: Java running environment simply put JRE = java virtual machine + core class library (files that assist java virtual machine running)
JDK: Java development tools collection can also be understood as JDK = JRE + Java development tools
2. Configure environment variables
When we search for Java environment variables online, we generally require the configuration of three variables JAVA_HOME, Path, and CLASSPATH.
I won't take a screenshot here. I installed jdk7 under D drive
①JAVA_HOME configuration
JAVA_HOME=D:/Java/jdk1.7.0_25
JAVA_HOME represents your jdk path. The reason why you need to configure a JAVA_HOME variable separately is to avoid frequent modification of path environment variable information, and it should be used in path.
②Path configuration
Add [%JAVA_HOME%/bin;%JAVA_HOME%/jre/bin;] or directly [%JAVA_HOME%/bin;] in the starting position of the Path "Variable Value" text box.
Path variable function: In order to enable the console to find Java development tools under any path. In this way, when we call commands like java or javac, we don’t need to locate the bin directory of jdk first.
③CLASSPATH
Generally, the following configuration is required online
CLASSPATH=.;%JAVA_HOME%/lib/dt.jar;%JAVA_HOME%/lib/tools.jar;
First of all, we need to understand what CLASSPATH is useful. CLASSPATH sets the path information of the class file.
In fact, after jdk1.5, sun companies no longer recommend configuring CLASSPATH, because in the early jdk versions, if CLASSPATH is not configured, the virtual machine cannot find the required core class library, such as dt.jar.
The new version can be found automatically because many tutorials on the Internet are relatively old, and everyone reprints and copies them, so the old tutorial still requires configuration, and we do not recommend configuring CLASSPATH here.
OK, if the configuration is correct, enter java -version to see the following version information.
We can also write a "Hello World" to see it.
Find a folder and create a new Demo.java file
Edit with notepad and write java code.
public class Demo { public static void main(String[] args) { System.out.println("Hello World!"); } } After saving, open the console and locate it to the current folder.
Execute javac Demo.java first
Execute java demo again
We can see the classic Hello World, as shown in the figure below.
By the way, the two commands of javac and java
javac: Start the java compiler to compile the specified java source file
java: Start the java virtual machine to interpret and execute the corresponding class file
OK, so we have completed the introduction to Java.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.