01-Java language overview

JAVA language overview

1. Java history

Java was born in SUN (Stanford University Network), and SUN was acquired by Oracle (Oracle) in 2009.

The father of Java is James Gosling.

JDK 1.0 version was released in 1996.

Java Development Kit
1.0.2
1.1.1 -> 1.1.6 -> 1.1.7 -> 1.1.8
1.2.1
Java 2 SDK
1.2.2
1.3.0 -> 1.3.1
1.4.0 -> 1.4.1- > 1.4.2 -> 1.5.0 (5.0 launched in 2004) -> 1.6.0 (6.0 retired in 2006) -> 1.7.0 (7.0 launched in 2011)
jdk8 (launched in 2014) version is backward compatible

The latest version is Java12.

2. The main features of Java language

  • Feature 1: Object-oriented

Two basic concepts: class, object

Three characteristics: encapsulation, inheritance, polymorphism

  • Feature 2: Robustness

Absorbs the advantages of the C/C++ language, but removes the parts that affect the robustness of the program (such as pointers, memory application and release, etc.), providing a relatively safe memory management and access mechanism

  • Feature 3: Cross-platform

Cross-platform: Applications written in Java language can run on different system platforms. "Write once, Run Anywhere" write once, run everywhere.

Principle: Just install a Java Virtual Machine (JVM Java Virtual Machine) on the operating system that needs to run java applications. The JVM is responsible for the running of Java programs in the system. Because of the JVM, the same Java program can be executed on three different operating systems. In this way, the cross-platform nature of Java programs is realized.
Insert picture description here

3.Java two core mechanisms

  • Java Virtual Machine (Java Virtal Machine)

The JVM is a virtual computer with an instruction set and different storage areas. Responsible for executing instructions, managing data, memory, and registers.

For different platforms, there are different virtual machines.

The Java virtual machine mechanism shields the difference between the underlying operating platforms and realizes "compile once, run everywhere".

  • Garbage Collection Mechanism (Garbage Collection)
  1. The memory space that is no longer used should be reclaimed-garbage collection.

In languages ​​such as C/C++, the programmer is responsible for recycling useless memory.

The Java language eliminates the programmer's responsibility to reclaim useless memory space: it provides a system-level thread to track the allocation of storage space, and when the JVM is idle, it checks and releases the storage space that can be released.

2) Garbage collection is automatically carried out during the running of the Java program, and the programmer cannot precisely control and intervene.

Insert picture description here

4. Commonly used DOS commands in Windows operating system

  • dir: List files and folders in the current directory
  • md: create directory
  • rd: delete directory
  • cd: enter the specified directory
  • cd...: Return to the previous directory
  • cd\: return to the root directory
  • del: delete files
  • exit: Exit the dos command line
  • cls : (clear screen)清屏
  • ipconfig /all View information such as the physical address of the local IP network card
  • calc open the calculator
  • mspaint open the drawing board
  • notepad Open notepad
  • hostname get the computer name
  • getmac get the physical network card address

5. Java environment setup

4.1 Introduction to JDK, JRE, and JVM

Java developers need to install JDK. If you are only running Java programs, you only need to follow the JRE.

JDK (Java Development kits): Java development kits.

JRE (Java Runtime Environment): Java runtime environment.

JVM (Java Virtual Machine): Java virtual machine.

JDK = JRE + development tools (javac.exe, java.exe, javadoc.exe, etc.)

JRE = JVM + core class library (common classes: String, date and time, math, collection, IO, network, multithreading, etc.)

Insert picture description here

4.2 Java environment construction

1. Install JDK
Insert picture description here

Note: JRE is included in the JDK, so the installation of JRE can be omitted
Insert picture description here

2. Configure the JDK development tool directory to the path environment variable

例如:D:\Master\ruanjian\JDK\bin;

注意:这个安装目录以你自己的安装目录为准

(1) Why configure path?

希望在命令行使用javac.exe等工具时,任意目录下都可以找到这个工具所在的目录。

(2) How to configure environment variables?

【计算机】右键【属性】,选择【高级系统设置】,选择【高级】,选择【环境变量】,选择【系统环境变量】,编辑path;

6. The first Java application

class HelloWorld{
    
    
    public static void main(String[] args){
    
    
        System.out.print("Hello World!");
    }
}

5.1 Development steps of Java programs

Three steps:

1. Edit/write source code

Requirements: The source file must be a .java file

2. Compile

Purpose: compile the source file into a .class bytecode file (because JVM only recognizes bytecode)

Tool: javac.exe

format:

javac 源文件名.java

3. Run

Tool: java.exe

format:

java 类名
java 字节码文件名

7. Java Notes

Role: explain the program, help us debug the program

1. Single-line comments

//注释内容

2. Multi-line comments

/*
注释内容
*/

3. Documentation comments The
content of the comments can be parsed by the tool javadoc provided by the JDK to generate a set of documentation for the program in the form of web pages.

/**
文档注释
*/

8. Issues that should be paid attention to when writing Java programs

1. Character encoding problem

When the character encoding of the cmd command line window is inconsistent with the character encoding of the .java source file, how to solve it?

Insert picture description here

Solution one:

在Notepad++等编辑器中,修改源文件的字符编码

Insert picture description here

Solution two:

在使用javac命令式,可以指定源文件的字符编码
javac -encoding utf-8 Review01.java

2. Capitalization issues

(1) Source file name:

不区分大小写,建议还是区分

(2) Bytecode file name and class name

区分大小写

(3) In the code

区分大小写

3. Is the source file name consistent with the class name?

(1) Does the source file name have to be consistent with the class name? public?

If the class is not public, then the source file name can be inconsistent with the class name.

If the class is public, the source file name must be consistent with the class name.

Suggestion: Whether it is public or not, keep it consistent with the source file name, and try to write only one class in a source file for better maintenance.

(2) Can there be multiple classes in one source file? public?

There can be multiple classes in a source file, and multiple .class bytecode files will be generated after compilation.

But a source file can only have one public class.

(3) Does main have to be in the public class?

It's not.

But when writing code later, basically the main habit is in the public class.

Guess you like

Origin blog.csdn.net/m0_46988935/article/details/109515299