[JAVA] Basic knowledge points

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

Java tutorial, introduction, development environment configuration

Insert picture description here

Java basic syntax

Basic syntax When
writing Java programs, you should pay attention to the following points:

Case sensitive: Java is case sensitive, which means that the identifier Hello and hello are different.

Class name: For all classes, the first letter of the class name should be capitalized. If the class name consists of several words, then the first letter of each word should be capitalized, such as MyFirstJavaClass.

Method name: All method names should start with a lowercase letter. If the method name contains several words, capitalize the first letter of each subsequent word.

Source file name: The source file name must be the same as the class name. When saving the file, you should use the class name as the file name (remember that Java is case sensitive), and the file name suffix is ​​.java. (If the file name and the class name are not the same, it will cause a compilation error).

Main method entrance: all Java programs are executed by the public static void main(String[] args) method.

Java Identifiers
All components of Java require names. Class names, variable names, and method names are all called identifiers.

Regarding Java identifiers, there are the following points to note:

1. All identifiers should start with a letter (AZ or az), dollar sign ($), or underscore (_)

2. The first character can be any combination of letters (AZ or az), dollar sign ($), underscore (_) or numbers

3. Keywords cannot be used as identifiers

4. Identifiers are case sensitive

5. Examples of legal identifiers: age, $salary, _value, __1_value

5. Examples of illegal identifiers: 123abc, -salary

Java comments are
similar to C/C++, Java also supports single-line and multi-line comments. The characters in the comment will be ignored by the Java compiler.

public class HelloWorld {
    
    
   /* 这是第一个Java程序
    * 它将输出 Hello World
    * 这是一个多行注释的示例
    */
    public static void main(String[] args){
    
    
       // 这是单行注释的示例
       /* 这个也是单行注释的示例 */
       System.out.println("Hello World"); 
    }
}

Java objects and classes

Scanner keyboard input:

import java.util.Scanner;
//获得键盘输入,Scanner类
public class TestScanner {
    
      
    public static void main(String[] args) {
    
      
		Scanner s = new Scanner(System.in);
		String name = s.nextLine();
		System.out.println("用户名:"+name);
		
    }  
}

Java basic data types

byte: The byte data type is 8-bit, signed, an integer represented by two's complement, which occupies 1 byte;

short: The short data type is a 16-bit, signed integer represented by two's complement, which occupies 2 bytes;

int: The int data type is a 32-bit, signed integer represented by two's complement, which occupies 4 bytes;

long: The long data type is a 64-bit, signed integer represented by two's complement, 8 bytes;

float: The float data type is a single-precision, 32-bit, floating-point number conforming to the IEEE 754 standard, occupying 4 bytes

double: The double data type is a double-precision, 64-bit, floating-point number conforming to the IEEE 754 standard, occupying 8 bytes

char: The char type is a single 16-bit Unicode character

Java variable types

The variable types supported by the Java language are:

Class variables (static variables): Variables independent of methods, modified with static.
Instance variables: variables independent of methods, but without static modification.
Local variables: variables in the methods of the class.

public class Variable{
    
    
    static int allClicks=0;    // 类变量
 
    String str="hello world";  // 实例变量
 
    public void method(){
    
    
 
        int i =0;  // 局部变量
 
    }
}

Java modifiers

Java modifiers
Like other languages, Java can use modifiers to modify methods and properties in a class. There are two main types of modifiers:

Access control modifiers: default, public, protected, private

Non-access control modifiers: final, abstract, static, synchronized

We will discuss Java modifiers in depth in later chapters.

Java operators

Insert picture description here

Insert picture description here

Java loop structure

Java conditional statements

Guess you like

Origin blog.csdn.net/m0_37882192/article/details/115271667