▷ Download JDK
JDK(Java Development Kit):
is the developer toolkit ofjava
and must be installedJDK
to useJava
- 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
versionJDK-17
to download
▷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
▷ Verify whether the installation is successful
JDK
The installation of requires verification of successful installation ofJava
andJavac
- can be verified by using the
java -version
andJavac -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.
▷ 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 toD盘
cd+目录:
switches to the directory, for example:cd tinygeeker
switches to the lower part of thetinygeeker
folder;cd ..
switches to the upper folder In one level of directorydir:
Displays all files and folders in the current directory
▷ Set environment variables
- Because
JDK-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 JAVA_HOME variable
- If there are multiple local versions
Java
, it is recommended to set theJAVA_HOME
variable, which is very convenient and fast for switching local versions JAVA_HOME
is set toJDK的安装目录
, then the environment variable ofJDK
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 inPATH
▷ First program
- Create a new text document and rename it to
HelloWorld.java
- Copy the following code into it and save it. First run the compilation command
javac HelloWorld.java
, and then run the execution commandjava HelloWorld
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
▷ 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 asHelloWolrd
;main
is written asmian
第二:
is incorrectly capitalized, for example,public
is written instead ofPublic
第三:
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 useCtrl+S
to save the file第五:
errors occur during execution. After writing the code, you must first usejavac
to compile the code. After compilation, a.class
file will be generated, and then usejava
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
▷ 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.
▷ Customize the theme
- This editor supports custom themes, please set according to your personal usage habits
- You can set it by clicking
Settings
►Appearance
►Theme
. Remember to click the save button below to take effect a>
▷ 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
Settings
►Font
►Size
. Remember to click the save button below to take effect a>
▷ IDEA shortcut keys
main/psvm、sout:
Can quickly type relevant codeCtrl + D:
Copy the current row data to the next rowCtrl + Y:
Delete current rowCtrl + ALT + L:
Format codeALT + SHIFT + 方向键上下:
Move current code up or downCtrl + /、Ctrl + Shift + /:
Make quick comments on your code