Java full reference manual (version 8th) Chapter 1st to Chapter 5th

Source: Internet
Author: User

Preface: This part is partial to basic knowledge, and some knowledge points are not very clear. list them.

1,The output of the Java compiler is not executable code, but bytecode. Bytecode is a collection of highly optimized commands that are executed by JVM (designed as a bytecode interpreter.

Cause: it is easy to execute in a variable environment. You only need to implement JVM for each platform. This helps to provide security. Although the execution speed is compiled into an intermediate form, however, the speed of JVM execution programs is faster. In terms of performance improvement, if the JVM contains the JIT compiler, You can compile the selected bytecode into executable code in real time as needed, that is, Dynamic Real-Time compilation.

2. When will byte integer data be used?When operating data streams from networks or files and operating raw binary data that is not directly compatible with other built-in JAVA types ,......

3,In Java, char and C/C ++ are different. In C/C ++, It is 8 bits, and in Java it is 16 bits (0 ~ 65536 ). Java uses Unicode to represent characters (www.unicode.org ).

4,To identify the long literal value, you must explicitly tell the compiler that the literal value is of the long type, for example, 0 xffffffffl.

The binary value specifies the literal value of an integer. 0b or 0b is the prefix, for example, 0b0010.

One or more underscores can be embedded in an integer. Underlines are ignored. Underlines can only be used to separate numbers and cannot start or end with a literal value, you can use multiple underscores (_) between two numbers, for example, 122.1644.

Float Type, standard counting method and scientific counting method. By default, float fonts are double-precision. If float is specified, F/F must be added, for example, 12.78f. Underlines can also be used. The hexadecimal floating point literal is supported. P or P (not E/E) is used. For example, 0x12. 2p2 indicates 72.5.

5,Character escape sequence: commonly used include, \ ', \ "(double quotation marks inserted in the string), \ (path name), \ r (carriage return), \ n (line break), \ t (Tab), \ B (return character );

Not commonly used, \ DDD indicates the octal character DDD, \ 141 indicates the letter A, (\ + three digits), \ uxxxx indicates the hexadecimal Unicode Character XXXX, \ ua432 is a Japanese Katakana character.

6,Java automatic type conversion: compatible type and wide conversion. When the expression is evaluated, the operands are converted to the highest type,This is prone to errors..

Forced conversion of incompatible types. For example, when int is converted to byte, the result is reduced by a modulo (remainder) within the byte type range, and the float type is converted to an integer value at the end of the truncation.

7,Array. Int A [] = new int [12]; int AB [] [] = new int [4] [5]; int [] A, B, C; int A [], B [], C [];

When allocating memory for multi-dimensional arrays, you only need to allocate memory for the first dimension. For example, int twod [] = new int [4] []; twod [0] = new int [5]; twod [1] = new int [4]; twod [2] = new int [5]; twod [3] = new int [4];.

8. Why cannot I use pointers in Java?If pointers are supported, the Java program will be able to break through the firewall between the Java execution environment and the host computer (any address in the memory can be assigned to the pointer, or even exceeds the address of the Java runtime system ).

9,Bit (By bit) Operator, used for integer types: Long, Int, short, Char, and byte. Commonly used,The leftmost bit uses the value filling at the top right shift.), <(Left shift, loss of high-order bit removal, right fill 0), <=, |=, ^=, >=, <=; not commonly used ,~ (Inverse of one dollar by bit), >>> (right shift and zero fill,No matter what the initial value of a higher-order bit is, 0 is added.),
>>>> =.

Java uses the complement code of 2 (take the inverse plus one) to indicate a negative number. Why? Specific analysis"0 cross problems". That is, the byte type 0 indicates 0000 0000. If the Reverse type is simple, 1111 1111 is created and-0 is created. If the 2's complement code is used, 1 0000 0000 is out of the range, to get the expected behavior, that is,-0 and 0 are equal, and-1 is encoded as 1111 1111.

When a byte or short value is shifted to the left, the automatic increase in the type will lead to unexpected results. In this case, the type conversion truncation should be forced to narrow down the range.For example, byte A = 64, B; int I; I = A <2; B = (byte) (a <2); the result is, I = 256, B is 0.

Shifts left is equivalent to multiplying 2, but note that if binary 1 is moved to a higher-order bit (31st or 63 bits), the result will change to a negative number.

Shifts-1 to the right, and the result is still-1. When the value is shifted to the right, you may not want to obtain the value after symbol extension. At this time, you can perform bitwise AND operation with 0x0f.Bit shielding(Byte type ).

10,Value chain. Int X, Y, Z, x = y = z = 100;

? Operator. Expression1? Expression2: expression3. Both expression2 and expression3 must return the same orCompatible (automatic conversion will be performed. Please note that)And cannot be void.

Operator priority. ++/-- (Suffix );

++/-- (Prefix ),~ ,! , +/-(Unary operator), (type conversion );

*,/, %;

+ ,-;

>>,>>>,<;

>,>=, <=, Instanceof

= ,! =

&

^

|

&&

|

? :

=

PS: instanceof (test whether the object on the left is an instance of the class on the right of it, and return boolean data. Can be used to determine whether the instance of the inherited subclass is the implementation of the parent class .)

11,Switch statement. Switch (exp) {Case value1:... break; Case value2:... break;... Default :...}

Exp is byte, short, Int, Char, orEnumeration type, which can also be string type.Each value in the case statement is different, and its type is different from that in Exp.Type compatibility. The default and break statements are optional. If not required, do not use strings in the switch statement. Switch statements can be nested.

When compiling a switch statement, the Java compiler checks each case constant,Create a jump table"This jump table is used to select the execution path based on the expression value. Therefore, it runs faster than if/else statements.

12,Some practices.While (++ I <-- J); do {...} while (-- N> 0 );When a conditional expression can process all the details, a short loop without a loop body is often used.

13. For-each statement.For (int x: Collection ){...}. You can use the break statement to terminate the loop in advance. Iteration variables are "read-only" and cannot change the content of the array set by modifying values for iteration variables.

During multi-dimensional array iteration, int Nums [] []... for (int x []: Nums) {for (int y: X ){...}}.

WhenSet defined by the collection frameworkThe for-each statement is particularly useful.

13,Break statement. The break statement in the inner loop only terminates the inner loop and does not affect the external layer loop. (Unlike in C/C ++, break terminates the entire cycle, while continue terminates this cycle)

Break label; a code block named after a label exists. This code block must contain this statement. The continue label is the same.


On February 8



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.