Java开发环境搭建(Construction of java development environment)

Java开发环境搭建

1. JDK下载与安装

JDK下载

官网下载JDK

JDK官网下载(需要注册账号)

网址:https://www.oracle.com/java/technologies/downloads/#java8-windows

JDK清华大学开源软件镜像站下载

JDK清华大学开源软件镜像站下载(如果嫌官网太麻烦,可以尝试用这个)

网址:https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/

下载方法:

  • 选择JDK版本(推荐8)
  • 选择JDK
  • 根据电脑选择32位或者64位。
  • 选择适配电脑系统的版本
  • 选择合适的JDK版本下载

JDK安装

  • 提前选好存放JDK的路径。路径不能有中文和空格,
  • exe后缀的直接安装到选好的路径,zip后缀的解压到选好的路径。
  • 记住存放JDK的路径,例如 E:\jdk
  • 配置环境变量

    在桌面左下角的搜索框搜索环境变量(Win10系统)
    在环境变量的系统变量下点击“新建”,变量名写上 JAVA_HOME,变量值写上 JDK的路径,例如 E:\jdk,然后点击确定。
    配置 Path变量,双击打开环境变量的系统变量里的 Path,点击新建后写上 %JAVA_HOME%\bin

  • 在桌面左下角的搜索框搜索环境变量(Win10系统)
  • 在环境变量的系统变量下点击“新建”,变量名写上 JAVA_HOME,变量值写上 JDK的路径,例如 E:\jdk,然后点击确定。
  • 配置 Path变量,双击打开环境变量的系统变量里的 Path,点击新建后写上 %JAVA_HOME%\bin
  • 在 cmd中输入 java -version查看Java是否安装成功(显示 Java版本则安装成功)

2. HelloWorld 及 简单语法规则

  • 新建一个文件夹,在文件夹下创建 code文件夹用于存放代码。
  • 在 code文件夹下新建一个 Java文件

    文件后缀名为 .java
    文件名全称为 Hello.java
    注意:系统可能没有显示文件后缀名!需要在文件夹左上角“查看”下的“显示/隐藏”板块修改。

  • 文件后缀名为 .java
  • 文件名全称为 Hello.java
  • 注意:系统可能没有显示文件后缀名!需要在文件夹左上角“查看”下的“显示/隐藏”板块修改。
  • 在 Hello.java中写入如下代码:
public class Hello{
	public static void main(String[] args){
		System.out.print("Hello,World!");
	}
}
  • 在 code文件夹的路径前加入 cmd和一个空格然后回车进入 code路径下的cmd(如果用其他方式打开 cmd,请先进入 code文件夹所在的路径)。
  • 编译 .java文件

    在 cmd中输入 javac Hello.java,然后回车。如果没有报错,且 code文件夹下出现了 Hello.class,则说明编译成功。

  • 在 cmd中输入 javac Hello.java,然后回车。如果没有报错,且 code文件夹下出现了 Hello.class,则说明编译成功。
  • 运行 .class文件

    编译成功后在 cmd中输入 java Hello,回车后运行正常就能看到结果 Hello,World!

  • 编译成功后在 cmd中输入 java Hello,回车后运行正常就能看到结果 Hello,World!

可能遇到的问题

  • 每个单词的大小写不能出现问题,Java是大小写敏感的。
  • 输出字符尽量使用英文,中文可能会报错。
  • 文件名 和 类名必须保持一致,并且首字母大写。
  • 符号使用了中文字符也会报错
  • 报错:找不到或无法加载主类

    在“系统变量”栏,“新建”,“变量名”为“CLASSPATH”,“变量值”为“.;%Java_Home%\bin;%Java_Home%\lib\dt.jar;%Java_Home%\lib\tools.jar”,点击“确定”

  • 在“系统变量”栏,“新建”,“变量名”为“CLASSPATH”,“变量值”为“.;%Java_Home%\bin;%Java_Home%\lib\dt.jar;%Java_Home%\lib\tools.jar”,点击“确定”

3. Notepad++安装和使用

安装过程比较简单,在浏览器中搜索下载安装即可。

作为一个易于编辑代码的记事本使用。

4.卸载JDK

  • 删除Java的安装目录(可在环境变量中查看安装位置)
  • 删除JAVA_HOME
  • 删除path下关于Java的目录
  • 在 cmd中输入 java -version查看Java是否删除成功(报错即卸载成功)
————————

Construction of java development environment

1. JDK download and installation

JDK下载

Download JDK from the official website

Download from JDK official website (account registration required)

网址:https://www.oracle.com/java/technologies/downloads/#java8-windows

JDK Tsinghua University open source software mirror Download

JDK Tsinghua University open source software mirror download (if you think the official website is too troublesome, you can try this)

网址:https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/

Download method:

  • Select JDK Version (8 recommended)
  • 选择JDK
  • Select 32-bit or 64 bit according to the computer.
  • Select the version that fits your computer system
  • Select the appropriate JDK version to download

JDK安装

  • Select the path to store JDK in advance. The path cannot have Chinese and spaces,
  • The EXE suffix is directly installed to the selected path, and the zip suffix is decompressed to the selected path.
  • Remember the storage path, for example, JDK: \ JDK
  • Configure environment variables
    Search for environment variables (win10 system) in the search box in the lower left corner of the desktop
    Click “new” under the system variable of environment variable, and write java on the variable name_ Home, write the path of JDK in the variable value, such as e: \ JDK, and then click OK.
    Configure the path variable, double-click the path in the system variable of the environment variable, click new and write% Java_ HOME%\bin
  • Search for environment variables (win10 system) in the search box in the lower left corner of the desktop
  • Click “new” under the system variable of environment variable, and write java on the variable name_ Home, write the path of JDK in the variable value, such as e: \ JDK, and then click OK.
  • Configure the path variable, double-click the path in the system variable of the environment variable, click new and write% Java_ HOME%\bin
  • Enter Java – version in CMD to check whether Java is successfully installed (if the Java version is displayed, the installation is successful)

2. HelloWorld 及 简单语法规则

  • Create a new folder and create a code folder under the folder to store the code.
  • Create a new Java file in the code folder
    The file suffix is java
    The full name of the file is hello java
    Note: the system may not display the file suffix! It needs to be modified in the “show / hide” section under “view” in the upper left corner of the folder.
  • The file suffix is java
  • 文件名全称为 Hello.java
  • Note: the system may not display the file suffix! It needs to be modified in the “show / hide” section under “view” in the upper left corner of the folder.
  • In hello Write the following code in Java:
public class Hello{
	public static void main(String[] args){
		System.out.print("Hello,World!");
	}
}
  • Add CMD and a space before the path of the code folder, and then press enter to enter CMD under the code path (if you open CMD in other ways, please enter the path where the code folder is located first).
  • compile. Java file
    In CMD, enter javac hello Java, and then enter. If there is no error, and hello. Com appears in the code folder Class, the compilation is successful.
  • In CMD, enter javac hello Java, and then enter. If there is no error, and hello. Com appears in the code folder Class, the compilation is successful.
  • function. Class file
    After the compilation is successful, enter Java hello in CMD and run normally after entering. You can see the result Hello, world!
  • After the compilation is successful, enter Java hello in CMD and run normally after entering. You can see the result Hello, world!

Possible problems

  • There should be no problem with the case of each word. Java is case sensitive.
  • The output characters shall be in English as far as possible, and errors may be reported in Chinese.
  • The file name and class name must be consistent and capitalized.
  • Errors will also be reported if Chinese characters are used for symbols
  • Error: the main class cannot be found or loaded
    In the “system variable” column, “new”, “variable name” is “classpath”, “variable value” is “.;% java_home% \ bin;% java_home% \ lib \ dt.jar;% java_home% \ lib \ tools. Jar”, click “OK”
  • In the “system variable” column, “new”, “variable name” is “classpath”, “variable value” is “.;% java_home% \ bin;% java_home% \ lib \ dt.jar;% java_home% \ lib \ tools. Jar”, click “OK”

3. Notepad + + installation and use

The installation process is relatively simple. Search, download and install in the browser.

As a notepad for easy code editing.

4. Uninstall JDK

  • Delete the installation directory of Java (you can view the installation location in the environment variable)
  • 删除JAVA_HOME
  • Delete the directory about Java under path
  • Enter Java – version in CMD to check whether Java is deleted successfully (if an error is reported, the uninstall is successful)