2. Basic data types and expressions

1. The amount of text

Literal quantities are quantities that appear directly in the program and are used directly by the compiler, and are immutable during their lifetime.

2. Identifier

An identifier is a name, usually corresponding to an address in memory. Its first letter must be one of the following characters: uppercase letter (AZ), lowercase letter (az), underscore (_), dollar sign ($); subsequent characters can be any of the above characters and numbers (0-9).

3. Constants and Variables

A variable is an item of a certain type named by an identifier whose value can be changed.

A constant cannot be changed once it is initialized.

4. Data Types

byte: signed micro-integer, 8 bits, -128~127;

short: signed short integer, 16 bits, -2^15~2^15-1 (one bit is used as the sign bit);

int: signed integer, 32 bits;

long: signed long integer, 64 bits;

float: single-precision floating-point number, 32 bits;

double: double-precision floating-point number, 64 bits;

bool: true or false;

char: including single quote characters and escape sequences, using 16-bit Unicode encoding;

5. Arithmetic factor operator

Increment and decrement operators: ++, --;

Unary operators: +, -;

Addition operators: +, -;

Multiplication operators: *, \, %.

6. Assignment operator

Simple assignment operator: =;

Compound assignment operators: *=, /=, +=, -=, <<=, >>=, >>>=, &=, ^=, |=.

7. Relational Operators

The type of relational operators is always boolean;

Arithmetic comparison operators: <, <=, >, >=;

Type comparison operator: instanceof;

Equality relational operators: ==, !=.

8. Logical Operators

That is, and or not, respectively &&, ||, !.

9. Conditional Operators

ExpressionA ? ExpressionB : ExpressionC

First, the value of expression A is calculated. If the value of A is true, the value of expression B is selected. If the value of A is false, the value of table C is selected.

10. Type conversion

Extended conversion: Conversion from a low type (small range) to a high type (large range) may lose precision.

Narrowing conversion: conversion from high type (large range) to low type (small range), which may lose information.

Implicit conversion: The expression type does not match the context, and the compiler may perform an implicit conversion:

                ①Assignment conversion: Convert the expression type to the type of the specified variable;

                ②Method call conversion: applicable to each parameter in the method or constructor call;

                ③ String type conversion: It is a Java-specific conversion; any type can be converted into a string type.

Explicit conversion: Also known as coercion, an expression is coerced into a specified data type.

Guess you like

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