1. Environment construction
First of all, the java product is called JDK , and JDK must be installed to use Java.
The history of Java development:
Among them, LTS is a relatively stable version, and the newer LTS17 version is recommended.
JDK Downloads: JDK Development Kit 17.0.7 downloads
After the download is complete, we double-click the installation package to install. When installing, we need to pay attention to:
- Do not install in the Chinese directory
- Do not install in directories containing spaces
After the installation is complete, you can see the bin directory under the installation directory , and there are java和javac
two executable files.
java.exe
: execute tool
javac.exe
: compile tools
To verify that the installation was successful, use the following two command lines:
java -version
javac -version
As you can see, the display is normal, and the version number is also consistent with what we installed. Here JDK has been installed successfully.
The .exe installation package I downloaded here is automatically installed, and the environment variables will be automatically configured into the
Path
variables. If it is a downloaded compressed package, you need to manually configure the environment variables.
The environment variables automatically configured by the exe installation package are shown in the figure:
Open the directory as shown in the figure:
2. Common commands
Common commands | effect |
---|---|
D: | Switch to D:, C: under a certain disk |
dir | View file information in the current path |
cd | Enter single-level directory: cd itfeiniu |
cd … | Go back one level |
cd \ | Return to the root directory of the drive letter |
cls | clear screen |
3. Development steps
- Create HelloWorld.java, the code is as follows
public class HelloWorld{
public static void main(String[] args){
System.out.println("Hello World");
}
}
-
Compile:
javac HelloWorld.java
After the compilation is successful, a file will appear in the same directory
HelloWorld.class
. -
run:
java HelloWorld
Console prints:
4. Composition of JDK
-
JVM: Java virtual machine, where Java programs actually run
-
Core class library: The program written by Java itself is called by the programmer's own program
-
JRE: Java runtime environment
-
JDK: Java Development Kit (includes all of the above)
5. Cross-platform working principle
Compile once, use everywhere. The main reason is that Sun has written different JVMs to adapt to different operating systems. So our compiled code can run on various operating systems.
6. Path environment variable
The path environment variable is used to remember the program path, so that it is convenient to start the program in any directory in the command line window.
The Path in the user variable is only valid for the currently logged in user. The Path in the system variable is valid for all users.
For example, configure the command line to directly open chrome
the browser.
-
Before it is configured,
chrome
it is useless for us to enter on the command line. -
After configuration, we enter it on the command line
chrome
, and the system will directly open the chrome browser
When manually configuring the JDK, environment variables generally need to be configured
Path
andJAVA_HOME
two items.JAVA_HOME:D:\develop\Java\jdk-17.0.7
Path:%JAVA_HOME%\bin