The second day of Java basic learning (Java environment construction, writing simple Java programs)

First, the Java environment to build

jre: java operating environment [jre = java virtual machine + core class library (files that assist Java virtual machine running)]
jdk: java development toolset [jdk = jre + java development tools] [path: cannot contain Chinese path or space]

Second, the introduction of the jdk directory

1. bin: It stores the development tools of java.
① java.exe starts the Java virtual machine to interpret and execute the specified class file
② javac.exe starts the Java compiler to compile the specified java source file [javac usage format: javac java Source File]

2. db: a lightweight database that comes with JDK7, named Derby

3. include: the stored interface file for calling system resources

4. jre: java runtime environment

5, lib: core class library

6. src.zip: java source code

3. Write the first program in Java

Step 1: Create a new .txt file and change the suffix name to .java
Step 2: All java codes are written on the class. Use a keyword class to define a class [format: class class name { } curly brackets indicate the scope of a class, code can be written within the scope of the class]
Step 3: Write a main method. The writing method of the main method is fixed, it is the entry point of a program, and the code is executed from the main method

class aaa{     
     public static void main(String[] args){
       System.out.println("HelloWorld~");
    }
}

Fourth, configure environment variables (path > JAVA_HOME, temporary environment variables, classpath)

1. Purpose: Java development tools can be found in any path

2. Principle: Write the file name of an executable file in the console, then the system will first search for the existence of the file in the current path of the console,
① If the specified file can be found, then execute the file
② If not found If the file is found, the system will also search for the specified file according to the path information stored in the path environment variable. If it can be found, then execute the file.

3. Find the environment variable of path
My Computer > Properties > Advanced System Settings > Advanced > Environment Variables > path
[copy the path where javac is located to the path environment variable]

4. Better > JAVA_HOME environment configuration
① Function: avoid frequent modification of the path environment variable information
② Solution: create a variable of JAVA_HOME > the installation directory of JDK > configure the path path: %JAVA_HOME%/bin
[Note: it will be required later When changing the directory of JDK, you only need to change the directory of JAVA_HOME]

5. Configure temporary environment variables
① Purpose: In real development, sometimes it will only be used once or a few times and then no longer used. We generally configure temporary environment variables through the set command. [Temporary environment variable: only works for the current console window. Once the window is closed, the configured temporary environment variable information will disappear]
② The usage of the set command
set [view all environment variable information]
set the name of the environment variable [view the specified environment variable information]
set environment variable name = path information [set the specified environment variable information]
set environment variable name = [clear the specified environment variable information]
set environment variable name = new path; % environment variable name% [in the original Add new path information based on]

6. Configure the classpath environment variable (permanent configuration is not recommended)
① When starting the jvm (java virtual machine), the jvm will search for the corresponding class file according to the path information saved in the
classpath environment variable ② Set the classpath environment variable information with semicolons and There is no semicolon difference:
<no semicolon> the java virtual machine will only search for the corresponding class file in the path saved in the classpath, and will not search in the current path
<plus a semicolon> the java virtual machine will first be saved in the classpath Go to the path to search for the corresponding class file, and then search in the current path.
③ Function: Set the path information of the class file

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324607447&siteId=291194637