Configuring the Java environment and basic HelloWorld

First, what is JDK, JRE

JDK (Java Development Kit Java Development Kit)

JDK is available to Java developers, which contains the java development tools, including the JRE. So install the JDK, you do not have a separate installation of the JRE.
Which development tools: compiler tools (javac.exe) Packaging Tool (jar.exe) and so on.

JRE (Java Runtime Environment Java Runtime Environment)

Including the required Java Virtual Machine (JVM Java Virtual Machine) and core libraries and other Java programs, if you want to develop a good run Java programs, the computer can only need to install the JRE.

The relationship between them

Two, JDK download, install

download

Recommended download JDK1.8 version , because most companies are using this version. Check the "Accept", select "windows X64" version, orancle login account to download.

installation

Fool installation, has been point "Next" on the line, you need to look for special attention is the path to install software not contain Chinese, spaces.

Three, Path environment variable configuration

Right-click on the 'Properties' option "This computer" choose "Advanced System Settings" option, click on the following "environment variable" option, click the "System variables" below the "New" option;
fill in "variable name" Department JAVA_HOME, "variable value" for the JDK installation path, the author's path is C:\Java\jdk1.8.0_191
click "OK" option

to find "path" in "system variables", select the "path" click "edit" option, click the "New" option, enter the %JAVA_HOME%\bin

click "OK" options

Open a command prompt, enter the command java -version, if all goes well, you will see the following output:

PATH

PATH是操作系统用的,用来指定操作系统需要使用到的可执行程序的位置。对于Java来说,通常需要把JDK的bin目录添加进入PATH中,这样你就可以在任意目录下使用bin下面的可执行程序,如javac.exe、java.exe等。
这个变量一定要保证将JRE/JDK的bin纳入其中(这里我说的其实不严谨,你可以把javaw.exe等这类文件复制一份放到任意一个PATH路径下,不一定是JRE/JDK也行),这样很多Java程序才能启动,比如Eclipse。

JAVA_HOME

JAVA_HOME是一个约定,通常它指的是JDK的目录。如果需要JDK的话,大部分程序会默认去环境变量中取JAVA_HOME这个变量。
例如,Tomcat的.bat/.sh文件中就会默认去取JAVA_HOME来用。

四、第一个Java程序

编写

用记事本创建一个java源文件:HelloWorld.java

public class HelloChina{
    public static void main(String[] args){
        System.out.println("Hello,World!");
    }
}

编译:

打开命令提示符窗口,cd进入源文件所在目录
javac HelloWorld.java

运行:

java HelloChina

Guess you like

Origin www.cnblogs.com/vancenx/p/12199294.html