Java summary article 2

Chapter 02: Data Types and Operators

I. Overview:

1, data types: int, float, char, boolean

2, operators: arithmetic operators, assignment operators, relational operators, logic operators, bitwise operators (to understand), conditional operator

3, the basic data type converted to: automatic type conversions, casts.

Second, the key elements:

1, the identifier: You must be a letter, underscore characters at the beginning, the $, the rest of the letter can be any combination of underscores, dollar signs, numbers, does not recommend the use of Chinese. (Note: Java identifier can not be keywords)

2, ASCII English character set one byte, Unicode universal character set two international bytes.

3, Java is a strongly typed language is: there is constant data types, variables must declare its data type.

4, variable elements: variable name, variable type and scope. (Note: Only after the variable declaration in order to assign the appropriate length of the storage unit)

5, represents a hexadecimal number: decimal (e.g., 99), octal (beginning with 0 requirements, such as 015), hexadecimal (leading 0x or 0X required, such as 0x15)

6, the range of the data type and the number of bytes occupied:

Note: an eight-byte, 8-th power is equal to 2562, the other and so on.

7, scientific notation: double f = 314e2; //314*10^2--->31400.0 (or 314E2, if it is 314 * 10 ^ -2 is expressed as 314e2)

8, floating point roundoff errors, lot number may not accurately represented, if need be no rounding error exact figures, BigDecimal class required.

9, the escape character: backspace \ b newline \ n Enter \ r tab \ t double quotation marks \ "single quotation marks \ '

Backslash \\

10. Note: Try to remove all == fasle == true and if in the judgment or other statements, and not with the kind of thinking change! = It.

11, naming convention: the first letter lowercase and hump principle (the second word is capitalized, such as: monthSalary), constant (capital letters and underlined: MAX_VALUE), the class name (capitalized and hump rules, such as: GoodMan).

12, Note:% (modulo remainder, such as 6% 4 = 2), / in addition to (e.g., 6/4 = 1), +: string concatenation, as long as one of the operands is a string, automatically becomes strings attached

13, integer arithmetic:

① If the two operands are of a long, but also the result of long

② When there is no long, the result is int. Even operands are all short, byte, the result is int.

14, floating-point operations:

① If both operands have a double, the result is the double

② only two operands are float, the result was a float.

15, operator precedence: Assignment <trinocular <Logical <Relationship <arithmetic <monocular

16, two operands in integer arithmetic adjacent first converted to the same type, from lower to higher conversion, and then calculates, and so on.

17, automatic type conversions (conversion type direction): byte -> short, char -> int -> long -> float -> double (left to right)

18, cast: when strong rotation, careful data loss or distortion.

Guess you like

Origin www.cnblogs.com/cgntiger/p/10994138.html