Java Learning - Identifiers, Data Types, Operators

identifier

The identifier consists of letters, numbers, underscore "_", dollar sign "$", and the first letter cannot be a number

Identifier Naming Rules

1. An identifier can be formed by connecting several words.
2. If it is a class name : the first letter of each word should be capitalized, and other letters should be lowercase.
3. If it is a method name or variable name : the first letter of the first word Lowercase, the first letter of other words must be capitalized
4, if it is a constant : all letters of all words are all uppercase, if it consists of multiple words, usually the words are separated by underscores
5, if it is a package name : all words All letters in lowercase

keywords

1, used for package, class, interface definition: package, class, interface
2, access control modifier: public, private, protected, default
3, data type: byte, char, int, double, boolean
4, flow control: if , else, while, switch, case, do, break, continue
5, exception handling: try, catch, finally, throw, throws
6, reference: this, supe
7, create object: new

basic data type

1. Integer type
(1) Byte type: byte
(2) Short integer type: short
(3) Integer type: int
(4) Long integer type: long
Note: When assigning a value to long, add an L after the assignment , if the data does not exceed the int type, L can be omitted

long t=1234567890L;
long t=123456;

2. Floating-point type
(1) Single-precision floating-point type: When float
is declared as a floating-point number of type float, add an F or f at the end, because the default type of floating-point type is double type

float i=11.234F;

(2) Double-precision floating-point type:
D and d at the end of double can be added or not added

double i=11.111111D;
double i=11.111111d;
double i=11.111111;

3. Character type (char)
The char type represents a character and is represented by single quotation marks. For example: 'hello','我','123'
4. Boolean type (boolean)
Boolean type is a data type used to represent logical values. There are only two values ​​​​of true or false, and the default is false .

operator

1. Arithmetic operators
(1) Addition operator: +
(2) Subtraction operator: -
(3) Multiplication operator: *
(4) Division operator: /
(5) Remainder operator: %
2, Assignment operation In
Java, assignment statements can be linked together to perform a series of assignments

x=y=z=1;

(1) x+=y: x=x+y
(2) x-=y: x=xy
(3) x*=y: x=x*y
(4) x/=y: x=x/y
( 5) x%=y: x=x%y
3, self-increment and self-decrement operator
x++
x- -
add or subtract 1 by itself, execute the program first and then add or subtract 1 by itself
++x
- -x
add or subtract 1 by itself, first perform the operation and then execute the program
4. Relational operator
(1) ==: equal to
(2) !=: not equal to
(3) >=: greater than or equal to
(4) <=: less than or equal to
(5) >: greater than
(6) <: less than
5, Logical operators
(1) AND: &&
(2) OR: ||
(3) NOT: !
6. Bitwise operators
Bitwise operators are mainly used to perform binary operations on integer types, convert the operands to binary, and then compare them bitwise
(1) Bitwise AND operator: &
If both binary values ​​are 1, then the operation The result is 1, that is: 0&0=0, 0&1=0, 1&0=0, 1&1=1
(2) Bitwise OR operator: |
If one of the two binary bits is 1, the result of the operation is 1, that is: 0|0=0, 0|1=1, 1|0=1, 1|1=1
(3) Bitwise XOR operator: ^
If the binary bits are the same, the value is 0, otherwise it is 1, that is: 1^1=0, 0^0=0, 1^0=1, 0^0=1
(4) Bitwise negation operator: ~
If the binary bit is 0, the negated value is 1; if it is 1, the negated value is 0, that is: ~0=1, ~1=0
(5) Left shift operator: <<
will all the operands The binary bit is shifted to the left by one bit. During operation, the empty space on the right side is filled with 0, and the left part is removed.
(6) Right shift operator: >>
Move all binary bits of the operand to the right by one bit. During operation, the left side is based on The sign bit of the original number is supplemented by 0 or 1 (negative number is supplemented by 1, positive number is supplemented by 0)
(7) Unsigned right shift: >>>
All binary bits of the operand are shifted to the right by one bit. During operation, the left blank is supplemented with 0

Guess you like

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