[Twelve days to learn java] day01-Java Basic Grammar

day01 - Java Basic Grammar

1. Human-computer interaction

1.1 What is cmd?

It is in the windows operating system, using the command line to operate the computer.

We can use cmd commands to operate the computer, such as: open files, open folders, create folders, etc.

1.2 How to open the CMD window?

  1. Press the shortcut key: win + R.
 此时会出现运行窗口。
  1. Output cmd in the run window
  1. Output carriage return.

Confused:

cmd operates the XXX folder under the users folder under the C drive by default. (XXX is the computer name)

1.3 Commonly used CMD commands

To expand a little bit:

In many materials, it is said to be a DOS command, but it is actually wrong. The real DOS command is the command in the MS-DOS operating system produced by Microsoft and IBM in 1981, which is called the DOS command.

In Windows, the operating system before win98 is based on non-graphical DOS, which can be called DOS commands. After 2000, windows gradually became dominated by a graphical interface. At this time, it cannot be called a DOS command. It only simulates the DOS environment. Many original DOS commands can no longer be used, so it is called a CMD command at this time. will be more accurate.

Common CMD commands are as follows:

operate illustrate
Drive letter name: Drive letter switching. E: Enter, means to switch to the E drive.
dir View the contents of the current directory.
cd directory Enter a single-level directory. cd itheima
cd … Return to the previous directory.
cd directory1\directory2... Enter the multi-level directory. cd itheima\JavaSE
cd \ Return to the drive letter directory.
cls Qingping.
exit Exit the command prompt window.

1.4 CMD exercises

need:

Use the cmd command to open QQ on your computer.

Complete steps:

1,确定自己电脑上的QQ安装在哪里
2,启动cmd
3,进入到启动程序QQ.exe所在的路径。
4,输出qq.exe加回车表示启动qq。

Confused:

In the Windows operating system, file names or folder names are case-insensitive.

1.5 Environment variables

effect:

If I want to start a certain software in any directory of CMD, then I can configure the path of this software to PATH in the environment variable.

When starting the software, the operating system will first look for it in the current path, if there is no path in the current recording class, then look for it in the path of the environment variable. If you can't find it, it will prompt you can't start.

step:

  • Right click on My Computer, select Properties.
  • Click on Advanced System Settings on the left
  • Select Advanced, and then click Environment Variables below.
  • Find the PATH in the system variable
  • Just configure the full path of the software to PATH.
  • (Can be done or not) is to move the path configured by yourself to the top.

Graphical examples are as follows:

Step 1: Right click on My Computer and select Properties.

(If the second step interface cannot appear, you can right-click on the blank space after opening My Computer)

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-2MOEyzyj-1679127321384)(null)]

Step 2: Click Advanced System Settings.

Step 3: Select Advanced, and then click Environment Variables below.

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-O4w2a3uo-1679127321428)(null)]

Step 4: Find the PATH in the system variable

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-zM0iNyi9-1679127321364)(null)]

Step 5: Click New, configure the complete path of the software to PATH, and then click OK.

Step 6: (optional) Click Move Up to move the currently configured path to the top.

The advantage of moving: When opening the software in CMD, it will first find the current path, and then look for the environment variables. The environment variables are searched from top to bottom. If the path is placed at the top, the search speed will be faster.

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-fiFpcuK3-1679127321404)(null)]

2. Java overview

1.1 What is Java?

Language: the way people communicate with each other

Computer language: a special language for information exchange between humans and computers

Java is a very popular computer language. (also called programming language)

We want the computer to do something, so we can tell the computer through the Java language

1.2 Download and install

1.2.1 Download

Get the JDK through the official website

http://www.oracle.com

Note 1 : For different operating systems, you need to download the corresponding version of JDK.

Note 2 :

If your computer is windows32-bit, it is recommended to reinstall the system to a 64-bit operating system.

Because Java has not provided a 32-bit version of the installation package since version 9.

If you don't want to download it yourself, there is also a corresponding installation package in today's day01 data file.

1.2.2 Installation

Fool-style installation, just the next step. The default installation path is under C:\Program Files.

suggestion:

  • The installation path should not contain Chinese characters, spaces or other special symbols.
  • In the future, all software suggestions related to development will be installed in the same folder for easy management.

1.2.3 JDK installation directory introduction

directory name illustrate
bin Various tool commands of the JDK are stored in this path. javac and java are placed in this directory.
conf The relevant configuration files of the JDK are stored in this path.
include Some platform-specific header files are stored in this path.
jmods Various modules of JDK are stored under this path.
legal The authorization documents of each module of the JDK are stored in this path.
lib Some supplementary JAR packages of JDK tools are stored in this path.

1.3 HelloWorld small case

The HelloWorld case refers to outputting the line "HelloWorld" on the computer screen. It is customary for various computer languages ​​to use this case as the first demonstration case.

2.3.1 Java program development and running process

Developing a Java program requires three steps: writing the program, compiling the program, and running the program.

2.3.2 Compilation of HelloWorld case

  1. Create a new text document file and modify the name to HelloWorld.java.

Note : The suffix java is the java file.

  1. Open the HelloWorld.java file with Notepad, and enter the program content.

Note : The code should be exactly the same as what I wrote.

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

Note : Unsaved files will be marked with a * symbol in the upper left corner

  1. Compile the file. After compilation, a class file will be generated.
    java file: the code written by the programmer himself.
    class file: a file handed over to the computer for execution.

  1. Note when running the code : What is running is the compiled class file.

Two commands are used:

javac + file name + suffix (that is, to compile java files)

java + file name (class file after running compilation)

1.4 HelloWorld case FAQ

1.4.1 BUG

In a computer system or program, some hidden defects or problems that have not been discovered are collectively called bugs (loopholes).

1.4.2 BUG solution

  1. Ability to identify bugs: see more
  1. Have the ability to analyze BUG: think more, check more information
  1. Have the ability to solve BUG: try more, summarize more

1.4.3 HelloWorld Frequently Asked Questions

1. Illegal character problem. Symbols in Java are in English format.

2. Case problem. The Java language is case sensitive (case sensitive).

3. Display the extension of the file in the system to avoid the HelloWorld.java.txt file.

4. The java file name after the compilation command needs to have the file suffix .java

5. The class file name (class name) after running the command does not have the file suffix .class

Common error code 1:

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

question:

There is a space missing between public and class.

Tip: Generally speaking, spaces between words cannot be omitted.

Spaces between words and symbols can be omitted.

Common error code 2:

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

question:

The first letter of system must be capitalized.

Skill:

Java code is strictly case-sensitive.

Therefore, the place that should be capitalized must be capitalized, and the place that should be lowercase must be lowercase. Practice a lot.

Common error code 3:

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

question:

The HelloWorld in the third line of code must be enclosed in double quotation marks, otherwise there will be problems.

Common error code 4:

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

question:

In the future code, all punctuation marks must be in English.

Skill:

Corresponding settings can be made in the input method.

1.5 Environment variables

1.5.1 Why configure environment variables

To develop Java programs, you need to use the development tools provided by JDK (such as javac.exe, java.exe and other commands), and these tools are in the bin directory of the JDK installation directory. If you do not configure environment variables, then these commands can only be used in the bin directory. directory, and we want to be able to use it in any directory, so we need to configure environment variables.

Note: Now the latest JDK downloaded from the official website will automatically configure the path of the javac and java commands to the Path environment variable during installation, so javac and java can be used directly.

1.5.2 Configuration method

The old version of JDK downloaded before is not automatically configured, and the automatically configured one only contains 4 tools, so we need to delete the configured ones and reconfigure the Path environment variable again.

JAVA_HOME : Tell the operating system where the JDK is installed (in the future, other technologies will use this to find the JDK)

Path : Tell the operating system where the javac (compilation) and java (execution) commands provided by the JDK are installed

1.5.3 Win10 bugs

When the computer is restarted, the environment variable becomes invalid. Indicates that the operating system does not support custom environment variables.

step:

  • Still need to configure JAVA_HOME for future related software to use
  • We can configure the full path of java and javac to PATH.
    E:\develop\JDK\bin

1.6 Notepad++

1.6.1 Download

Open Baidu and search for notepad++.

There is also a corresponding installation package in the data folder of day01.

1.6.2 Installation

For fool-proof installation, just click Next.

There are two small suggestions for the installation path:

  • The path should not contain Chinese characters, spaces or special symbols
  • It is recommended to put all the development-related software together for easy management.

1.6.3 Settings

Right click on the java file and select edit with notepad++.

Click Settings, then click Preferences. In the pop-up page, select New on the left, Java in the middle, and ANSI on the right.

1.6.4 Exercises

Use notepad++ to write a HelloWorld and compile and run successfully.

1.7 Development of Java language

Three versions:

  • Java5.0: This is the first major version update of Java.
  • Java8.0: This is the version currently used by most companies. Because this version is the most stable.
  • Java15.0: This is the version we learned in the course.

Confused:

What we learn is not the same as the version we use at work. Will it affect my future work?

backward compatible. The new version just adds some new functions on the basis of the original.

Example:

Can the code developed with version 8 run with version 11? It must be possible.

Can the code developed with version 11 run with version 8? uncertain.

If the code developed in version 11 does not use the new features of 9~11, then it can be run with 8.

If the code developed in version 11 uses the new features of 9~11, it cannot be run with 8.

1.8 Three platforms of Java

JavaSE、JavaME、JavaEE

1.8.1 Java SE

is the basis for the other two versions.

1.8.2 Java ME

A small version of the Java language for the development of embedded consumer electronics or small mobile devices.

Chief among these is the development of small mobile devices (cell phones). It has gradually declined and has been replaced by Android and IOS.

However, Android can also be developed in Java.

1.8.3 JavaEE

Website development for the web direction. (Mainly engaged in background server development)

In the server field, Java is the well-deserved leader.

1.9 Major Features of Java

  • object oriented
  • safety
  • Multithreading
  • easy to use
  • open source
  • Cross-platform

1.9.1 The principle of cross-platform Java language

  • The operating system itself does not actually know the Java language.
  • But for different operating systems, Java provides different virtual machines.

The virtual machine translates the Java language into a language that the operating system can understand.

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-SsH23Akl-1679127321342)(null)]

1.10 JRE and JDK

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-r0tgpR2x-1679127321448)(null)]

JVM (Java Virtual Machine), Java virtual machine

JRE (Java Runtime Environment), the Java runtime environment, includes the core class library of JVM and Java (Java API)

JDK (Java Development Kit) is called Java development tools, including JRE and development tools

Summary: We only need to install JDK, which contains the java operating environment and virtual machine.

Guess you like

Origin blog.csdn.net/weixin_60257072/article/details/129638534