1. Introduction to Java [Basic]

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:

image-20230711201342973

Among them, LTS is a relatively stable version, and the newer LTS17 version is recommended.

JDK Downloads: JDK Development Kit 17.0.7 downloads

image-20230711202233788

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

image-20230711203545992

After the installation is complete, you can see the bin directory under the installation directory , and there are java和javactwo 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

image-20230711203144727

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 Pathvariables. 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:

image-20230711230200332

Open the directory as shown in the figure:

image-20230711230226808

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

image-20230711211317961

  1. Create HelloWorld.java, the code is as follows
public class HelloWorld{
    
    
	public static void main(String[] args){
    
    
		System.out.println("Hello World");
	}
}
  1. Compile:javac HelloWorld.java

    After the compilation is successful, a file will appear in the same directory HelloWorld.class.

  2. run:java HelloWorld

    Console prints:

    image-20230711213830633

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)

image-20230711215535386

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.

image-20230711215710465

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.

image-20230711220339909

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 chromethe browser.

  1. Before it is configured, chromeit is useless for us to enter on the command line.

    image-20230711220651457

  2. After configuration, we enter it on the command line chrome, and the system will directly open the chrome browser

    image-20230711220915296

    image-20230711220830064

When manually configuring the JDK, environment variables generally need to be configured Pathand JAVA_HOMEtwo items.

JAVA_HOME:D:\develop\Java\jdk-17.0.7

Path:%JAVA_HOME%\bin

Guess you like

Origin blog.csdn.net/bobo789456123/article/details/131739132