current position:Home>Java foundation - environment variable configuration

Java foundation - environment variable configuration

2022-01-26 22:58:15 #HashMap#

One : first HelloWorld Program

java Programming languages originally belonged to SUN company ,2009 By the Oracle Company purchase .
To complete the first program, you need to install JDK, The latest version is JDK13, But the most common is JDK8, Most companies use JDK1.7, For our current study, it is recommended to install JDK8 Download address (https://www.oracle.com/cn/index.html)

1.1 JDK Installation

1.1.1 JDK(java development kit) Include JRE And technical support for development ( Components and class libraries ).
JRE: If it's just running on a computer java You don't need to JDK, It only needs JRE, The whole process is equivalent to fish in the water , The environment in which fish live is water , Water is equivalent to JRE, yes java The environment in which the file runs .
JVM:java virtual machine , It's the realization of java Cross platform foundation , One java After the file is run, it will produce .class file ( Bytecode file ), Bytecode files need to be in JVM Explained in , This is also java The reason why cross platform can be realized ( Be careful :java Files cannot cross platform ,.class The file in JVM The process is )
1.1.2 Follow the tutorial to install , Configure environment variables ( Environment variables will be discussed later , Just follow the tutorial here ), After installation, test whether it is successful. The steps are as follows :
i)win+R Input cmd
ii) Enter the command java -version
 Insert picture description here

1.2 Write the first java Program

1.2.1 Installation writing java Program tools (notepad++,editerplus,eclipse,idea) You can also use Notepad , Here we use notepad++ For example , open notepad++, Write the first HelloWorld Program

public class HelloWorld{
    
	public static void main(String[] args){
    
		System.out.println("Hello World,I am  Liao Zhongmin ");
	}
}

1.2.2 Save the file after writing , Note that when saving, the file name should be the same as your class name , The suffix of the file name should be .java ending
 Insert picture description here
1.2.3 Here, after saving the file, you will generate .java file , And then we open up cmd, Compile and run the file , I put the papers in E On the plate code In the folder , So use "E:" Order to enter , And then use "cd code" Order to enter code Folder , then javac HelloWorld.java Compiling Files , Last use java HelloWorld To interpret and execute
 Insert picture description here
TIPS: perform java.HelloWorld And then the result is .class file , You can't add another suffix .class

1.3 Java Cross platform implementation

First, let's analyze the whole Java The compilation and interpretation process of the program , We all know , We wrote .java File by calling JDKbin Compiler generation under path .class file ( Bytecode file ), Bytecode files need to be interpreted as binary files that can be recognized by the computer , So through JVM namely java Virtual machine to achieve , Such a java The file is compiled from and then interpreted and executed
 Insert picture description here

1.4 Problems in writing the first program

1.4.1 Not configured path Before , stay "C:\User\linkinpark>“ Next use javac On command , The computer first finds the current directory (C:\User\linkinpark) Is there a javac compiler , If so, you can execute , Otherwise, look for... In user variables and system variables , and javac The compiler is installed in "C:\Program Files\Java\jdk1.8.0_131" Under the path , Because the environment variable is not configured , So in "C:\User\linkinpark" I can't find javac compiler , Therefore, an error was reported
 Insert picture description here
i) Solution one : Configure environment variables , First click on " Computer " Right click " attribute ”, Click on " Advanced system setup "
 Insert picture description here
ii) Solution two : Without configuring environment variables , utilize "cd C:\Program Files\Java\jdk1.8.0_131 " The command enters the path
 Insert picture description here
1.4.2 Question two : stay C:\Program Files\Java\jdk1.8.0_131 Compile under path .java File error , The reason is that although javac Compiler call succeeded , however .java I stored the documents in E:\code, Cannot find... Under the current path , Therefore, it cannot be compiled into .exe file
 Insert picture description here
i) terms of settlement :javac After add E:\code route
 Insert picture description here
1.4.3 Question 3 : When running, even when E:\code I'll report a mistake next time , The reason is that the explanation is executed only in the current path , There is no executable file in the current path
 Insert picture description here
i) terms of settlement : add to -classpath command
 Insert picture description here
1.4.4 After the environment variable is configured, there is no need for the above troublesome operation
 Insert picture description here
TIPS:1. First new JAVA_HOME, The content is C:\Program Files\Java\jdk1.8.0_131
2. stay path Add %JAVA_HOME%\bin
3.JDK1.5 Before classpath New configuration required classpath, Content by .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar
 Insert picture description here

copyright notice
author[#HashMap#],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262258126080.html

Random recommended