first, the data type
The default integer type in 1.java is int, but a value that is small in the range of byte and short can be assigned to change the data type, for example: byte=12;short=15; If the value is too large to exceed the value range of int, Java does not default to a long type, you need to add "L" after the data to declare the data as long data, for example: long = 254564894654849L;
The default floating-point type in 2.java is double, and when declaring a float constant, you need to add "f" or "f" to the data;
There are three types of data in the 3.char type: 1) a single character enclosed in single quotation marks, such as char C1 = ' a ', char c2 = ' Medium ', char c3= ' 9 ', 2) with the escape character \ To convert the subsequent character to a special character constant, such as char B1 = ' \ n ' here \ n Represents a newline character; 3) uses Unicode values directly to denote character constants;
4. Boolean Type boolean value only two, one is true one is false, applies to logical operations, generally used for process control, can not use 0 or Non-zero to replace true and False.
Ii. Conversion of data types
1. Automatic conversion: the type with small capacity automatically goes to a large capacity type.
byte, short, and Char do not convert to each other, and they convert to type int before Conversion. The floating-point conversions are all removed from the integer fractional Portion.
Note: the "+" will be overloaded after encountering a string, acting as a connector, such as System.out.println ("5+5=" +5+5), at which time the output is 5+5=55,system.out.println (5+5+ "=5+5") and the output is 10=5+ 5.
2 forced type conversion, automatic conversion of the inverse process, the large capacity of the data into small capacity of the data, the need to strengthen the conversion symbol "()", but may result in loss of precision or overflow. The basic data can be converted in addition to the other types of boolean, except that there are some mandatory automatic.
third, the binary
1. The form of the binary representation:
Binary: 0, 1 full 2 in 1, starting with 0b or 0 b
Octal: 0-7 full 8 in 1, beginning with 0 '
Decimal: 0-9 full 10 in 1
Hex: 0-9 a-f full 16 in 1, starting with 0 x or 0x
2. Conversions between the Binaries:
Decimal to any binary in addition to the binary number, the remainder is inverted row
The arbitrary binary is converted to decimal, multiplied by the number of digits on the corresponding bit (the right = number of Binary)
Binary is converted to octal, converting every three bits of the binary to one of the eight binary
Binary to hexadecimal, converting every four bits of the binary to one of the hexadecimal
Octal conversion to hexadecimal requires an octet to be converted to a binary and then hexadecimal
3. Negative numbers in the Computer's form of representation
Example: 13 in the Computer's form of expression, first found 13 of the binary representation of 0000 1101, the complement of 1111 0011, which is-13 in the computer representation
Summary of the law: the complement of negative numbers: the first number of the right is not 0 of the number of reservations, all the rest of the Negation.
4. To find the corresponding integer according to the binary
1) If the binary number is positive, the binary conversion decimal method is used directly;
2) if the binary is negative, you need to use the above rule to find the complement, and then use the binary conversion decimal to Decimal.
four, arithmetic operators
five, Assignment operators
1. "=" is used to assign values to variables, can also be used to assign values between two variables, when the data types are inconsistent on both sides can be converted using the principle of automatic conversion or coercion, and support continuous assignment, such as int a; int b; int c;a+b+c=20;
2. Extended assignment operator: "+ =" "-=" "*=" "/=" "%=", a+=10 meaning a=a+10, keeping the data type left on the operation data is Unchanged.
six, comparison Operators
seven, logical operators
1 Types of logical operators
2. Short-circuit and, short-circuit or meaning
Short circuit and (&&): if the left is true, the right side participates in the operation, if the left is false, the right does not participate in the operation;
Short Circuit or (| | ): the left side is true when the right side does not participate in the operation;
Eight-bit operators
1. Types of bitwise operators
2. The meaning of the signed right shift >>: move the binary number overall to the right, the highest before the move is 0 after the shift in the vacancy 0, if the highest bit before the move is 1 after the shift in the vacancy of 1, keep the data symbol unchanged
Signed right shift >>>: moves the binary number whole to the right, regardless of whether the binary number is up to 0 or 1, and the empty space is filled with zero.
For a positive number, the symbol is shifted to the right and the unsigned right shifts to the same digits, with the same result. Unsigned right-shift results are always Positive.
For a negative number, the symbol is shifted to the right, and the unsigned right shifts the same digits, and the result is definitely not the Same.
3.^ the use of XOR operators:
Summary rule:
The result of the XOR operation and the original number can be different or the other value will be Obtained.
Such as: 12^5^12=5
Day02 Java Basics Learning Notes