First knowledge of Java (data types)

Some people say that Java is a simple language. In fact, there is no simple language, only relatively simple.
Java is an object-oriented language

To learn Java, you must first understand JDK
JDK : Java Developer Tools
JRM : Java Runtime Environment
JVM : Java Virtual Machine

Insert picture description here

Interview question: What do the parameters of the main function mean?
The args array stores the function runtime parameters

public class Means {
    
    
    public static void main(String[] args) {
    
    
        for(int i = 0;i < args.length;i++){
    
    
            System.out.println(args[i]);
        }
        System.out.println("cool");
    }
}

Data types in Java :
1. Basic data types:

int : integer, 4 bytes
Packing class: Integer

int num = 10;//定义一个整型变量
System.out.println(num);

long : Long integer, 8 bytes
Packing class: Long

long num = 10L;//初始化设定值为10L,表示一个长整型数字 (10的类型是int)
               //L 和 l 均可,但推荐使用 L
System.out.println(num);

double : double-precision floating-point type, 8 bytes.
Wrapping class: Double
In Java, the value of int divided by int is still int, so if you want a decimal in the quotient, you have to use the double type to calculate

double num = 1.0;
System.out.println(num);

Float : Single-precision floating-point type, 4 bytes.
Packing type: Float
* Generally, floating-point numbers are used in engineering. Double is preferred, and float is not recommended.

float num = 1.0f; // 1.0F 也可以
System.out.println(num);

char : character, 2 bytes (negative absence)
packaging: Character
Note: **
(1) the use of Java in single quotes + single letter form indicates the character literals
(2) on the computer character is essentially An integer, ASCII is used to represent characters in C language, and Unicode is used to represent characters in Java. Therefore, one character occupies two bytes, indicating that there are many types of characters, including Chinese.

char ch = 'A';
System.out.println(ch); 
char ch = '帅'; // 一个变量只能对应一个汉字
System.out.println(ch);

byte : byte type, 1 byte
Packing type: Byte
byte type also represents an integer, and the character type is not related to each other

byte value = 0 ;
System.out.println(value);

short : short integer, 2 bytes.
Packaging: Short
range is relatively small, generally not recommended

short value = 0;
System.out.println(value);

boolean : Boolean
wrapper class: Boolean
Note: **
(1) boolean type variable has only two values, true for true, false false representation;
(2) in the Java boolean type int and can not be transformed into each other, not There are 1 for true and 0 for false.
(3) Some boolean types in JVM are 1 byte, and some are 1 bit (not clearly specified)

boolean value = true;
System.out.println(value);
// System.out.println(value+1);// 是错误的

2. Reference type: String, array, class, enumeration, abstract class, interface
pointer ---is a variable used to store address
references ---is also a variable used to store addresses

String : string type variable
in Java using double quote character + some way represents the string literals

String name = "观众老爷都是帅哥";
System.out.println(name);

Guess you like

Origin blog.csdn.net/qq_45658339/article/details/108745540