〔001〕Java basic environment installation and writing the first program

▷ Download JDK

  • JDK(Java Development Kit): is the developer toolkit of java and must be installed JDK to use Java
  • It is recommended to download the official long-term maintenance version, it is recommended to download JDK-8, JDK-11, JDK-17, < a i=4> These versionsJDK-21
  • Official website address:https://www.oracle.com/
  • In the download interface, select the system and version number to download. Here, Feitu Brother himself chooses the window version JDK-17 to download

Download JDK
download button
Download JDK

▷Install JDK

  • In the installation interface, you can change the installation path. What you need to pay attention to is 不要有中文 in the path, and then click 下一步 all the way

Installation settings

▷ Verify whether the installation is successful

  • JDKThe installation of requires verification of successful installation of Java and Javac
  • can be verified by using the java -version and Javac -version commands in the command line window
  • If no error is reported, it means the installation is successful. You need to pay attention to check whether the version number is consistent with the download.

Verify installation

▷ Common commands for black windows

  • Two verification commands are used above. In fact, there are some common commands in black windows that will be used frequently in the future and need to be mastered.
  • 盘符+冒号: switches to a different drive letter, for example: D: switches to D盘
  • cd+目录: switches to the directory, for example: cd tinygeeker switches to the lower part of the tinygeeker folder; cd .. switches to the upper folder In one level of directory
  • dir:Displays all files and folders in the current directory

Common commands

▷ Set environment variables

  • BecauseJDK-17 and above versions will automatically set environment variables. If it is other lower versions, environment variables need to be set before executionjava -version and < /span>Javac -version command
  • Just add JDK安装根目录/bin to the system environment variables

Set environment variables

▷ Set JAVA_HOME variable

  • If there are multiple local versionsJava, it is recommended to set the JAVA_HOME variable, which is very convenient and fast for switching local versions
  • JAVA_HOME is set to JDK的安装目录, then the environment variable of JDK can be modified to %JAVA_HOME%\bin
  • If you want to switch to a different version, you only need to modify the value in JAVA_HOME instead of modifying the value in PATH

Add JAVA_HOME variable

▷ First program

  • Create a new text document and rename it toHelloWorld.java
  • Copy the following code into it and save it. First run the compilation command javac HelloWorld.java, and then run the execution command java HelloWorld
public class HelloWorld {
    
    
	public static void main(String[] args) {
    
    
		System.out.println("Hello World");
	}
}

first program

▷ Common mistakes

  • Although it is the first program, writing it for the first time may cause various problems.
  • 第一: word spelling errors, this is the most common problem, for example, HelloWorld is written as HelloWolrd; main is written as mian
  • 第二: is incorrectly capitalized, for example, public is written instead of Public
  • 第三:The file name must be the same as the class name. For example, here the file name and class name are bothHelloWorld
  • 第四: is not saved. After writing the code, you need to use Ctrl+S to save the file
  • 第五: errors occur during execution. After writing the code, you must first use javac to compile the code. After compilation, a .class file will be generated, and then use java Run this file without adding suffix
  • 第六: Be sure to turn on the suffix name display. Otherwise, the modified file will appear to end with .java, but in fact it will end with .java.txt, but it will not be displayed. The file suffix is ​​just invisible

Common mistakes

▷ Use IntelliJ IDEA

  • It is very inconvenient to write code using text documents. If there are few codes, it is fine. If there are many codes, errors can only be prompted during compilation and then modified, which is very inefficient.
  • At this time, you need a special editor for writing code. It is recommended to download it here.IntelliJ IDEA
  • This software can remind you of code errors in real time, and can also be edited with one click. The page is also more user-friendly and very convenient.

Error reminder

▷ Customize the theme

  • This editor supports custom themes, please set according to your personal usage habits
  • You can set it by clicking SettingsAppearanceTheme. Remember to click the save button below to take effect a>

Theme settings

▷ Modify font

  • Of course, you can also modify the font size and other parameters, such as font size, line spacing, etc.
  • You can set it by clicking SettingsFontSize. Remember to click the save button below to take effect a>

Modify font size

▷ IDEA shortcut keys

  • main/psvm、sout:Can quickly type relevant code
  • Ctrl + D:Copy the current row data to the next row
  • Ctrl + Y:Delete current row
  • Ctrl + ALT + L:Format code
  • ALT + SHIFT + 方向键上下:Move current code up or down
  • Ctrl + /、Ctrl + Shift + /:Make quick comments on your code

shortcut key

Guess you like

Origin blog.csdn.net/weixin_41635750/article/details/134290623