1. In Java, there is no goto statement. Because the large number of use of goto statements will reduce the readability and maintainability of the program, the Java language cancels the use of goto. At the same time, in order to avoid the confusion caused by programmers using goto on their own, the Java language still defines goto as a keyword, but does not define any syntax, so it is called "reserved words".
2 Although true, false and null are displayed in different colors in the IDE, they are not keywords, but "literal constants", just like abc of String type.
3 Try to avoid using $ when defining a name, because when the compiler compiles the .java file, it will compile "$" into a connector of the top-level type and the bottom-level type. See the following example:
When compiling (javac Test3.java) this code, the compiler will report the following error: Test.java:12: Error: Class duplication: com.javastack.Test.Outer.Inner class Inner{ ^
4 Unicode escape characters are processed very early, before parsing the program. For example:
These two lines of code compilation errors occur in the program. These two Unicode codes represent "line wrap" and "carriage return" respectively, so when the compiler compiles, the code looks like this:
5 Unicode code is encoded using 16-bit character and is represented by the char type in Java. Unicode has now expanded to one million characters, and those that exceed the 16-bit limit become complementary characters. All complementary characters cannot be represented by character constants.
6 When short, byte, char participates in the operation, the result is int type, not the same as the higher type. If the variable is of type byte, short, and byte, when it is assigned a constant from the compile time, and the constant does not exceed the value range of the variable, the compiler can perform implicit shrinking conversion. This implicit shrink conversion is safe because the shrink conversion only applies to the assignment of variables, not to method calling statements, i.e. not to parameter passing during method calling. (See the small problem with default type conversion in java for details)
7 Note the char type, which is an unsigned type. Therefore, the conversion between char and short or char and byte must be displayed using type conversion. The conversion from byte to char to extended shrink conversion is quite special, that is, the conversion is expanded to byte to int first, and then shrink to char.
8 In the extended conversion between integer data, if the operand is of char type (unsigned type), unsigned expansion is performed, with the expansion bit being 0. If the operand is of byte, short or int (signed type), signed expansion is performed, with the expansion bit being the sign bit of the variable.
9 The shrinking conversion between integer data is simply to truncate and discard the high bits without doing any other processing.
10 0.1+0.2 does not equal 0.3.System.out.println((double)0.1+(double)0.2); The output result of this statement is 0.30000000000000000000004. Because computers use binary to store data, and many decimals cannot be represented accurately in binary (in fact, most decimals are approximate), just like using decimal decimals cannot accurately represent 1/3. Most floating point types only store their values approximately in computers, rather than accurately as integer types. Another example is a dead loop: for(float f = 10.1f;f != 11;f+=0.1f){}
11 The float type can retain 7 to 8 significant numbers, while the double type can retain 15 to 16 significant numbers. Therefore, when the value of the int type or long type is more than the valid number of double or float, some of the lowest significant bits of the value will be lost, resulting in the loss of accuracy. At this time, the IEEE754 recent rounding mode will be used to extract the floating point value closest to the integer value. Although the conversion from integer to floating point type is an extended conversion, when the value is large or small (the absolute value is large), a certain accuracy loss will occur.
12 How to calculate i++j? (This question is not very meaningful to discuss in C/C++), because C/C++ depends on the implementation of hardware structure, and the results will be different in different environments. However, in Java, this result is fixed and not affected by the hardware environment and platform it runs on). Answer: According to the greed rules, front + + + is better than back + +, and the result is (i++) + j
13 i++ and ++i are actually +1 first and then assigned. ++i, there is nothing to say; i++, taking j=i++; as an example, the implementation at the underlying level is: temp = i;i = i + 1; j = temp; So, i=15;i=i++; The result of this expression is 15. (Because after adding one, another assignment is performed, changing from 16 to 15)
14 +0 and -0 In floating-point type variable storage, the sign bits are different. When -0 and +0 participate in related operations of floating point types (such as division and remnant operations), different results can be produced.
15 The phase division and balance calculation of floating point are different from the phase division and balance calculation of integers. When the divisor is 0, the floating point operation will not generate an ArithmeticException exception.
16 The String class is a non-mutable class, and once its objects are created, they cannot be destroyed. The methods that seem to modify the character sequence in the String class actually return the newly created String object instead of modifying its own object.
17 Since String objects are immutable, they are thread-safe and can be freely implemented for sharing.
18 Inside the String class, a character array (char[]) is used to maintain the character sequence. The maximum length of a String is the maximum length of the character array. In theory, the maximum length is the maximum value of type int, that is, 2147483647. In practice, the maximum value that can be obtained is generally less than the theoretical maximum value.
19 The main() method is basically the same as other methods in terms of performance behavior. It can be overloaded, called, inherited, hidden by other methods, or thrown exceptions with type parameters. We can also call the main method (or other method) through reflection in a program.
20 When the names of two or more methods are the same and the parameter list is different, these methods constitute overloading. The overloaded method can be distinguished based on the type corresponding to the parameter list and the number of parameters. However, the name of the parameter, the return type of the method, the exception list and the type parameter of the method cannot be used as conditions to distinguish the overloaded method.
21 Which method to choose to call, the order is as follows:
22 The essential difference between rewriting and hidden is that rewriting is dynamically bound, and the members of the relevant class are determined based on the actual type of the object pointed to by the runtime reference. Hiding is statically bound, and the relevant members of the call are determined based on the static type referenced at compile time. In other words, if the subclass overrides the parent class's method, when the reference of the parent class points to the child class object, the subclass method is called through the reference of the parent class. If the child class hides the parent class's method (member variable), the parent class's method (member variable) is still called through the reference to the parent class.
23 The constructor is called recursively. The constructor of the subclass will call the constructor of the parent class until the constructor of the Object class is called.
24 The constructor does not create an object. The constructor is called by the system when creating an object using new and is used to initialize the instance members of the class. In order, the object is created first, and then the constructor is called. (The constructor does not generate new objects)
25 The default constructor is not empty. This constructor will call the parent class's parameterless constructor and may perform initialization of instance member variables. Therefore, the default constructor calls at least the constructor of the parent class, and it may do more work, including instance variable declaration initialization and instance initialization blocks, both executed in the constructor.
26 When the types of the two operands of the == or != operator are one of the basic data types and the other are the wrapper class reference types, unboxing the reference type into the basic data type, and then comparing whether the values of the two basic data types are equal.
27 In Java, arrays are also classes, and reference variables declared by arrays point to objects of array type. All arrays inherit the Object class and implement the java.lang.Cloneable and java.io.Serializable interfaces. Members of an array include the variable length (implicitly exists) and members inherited from the Object class. Cloneable and Serializable are two marked interfaces, and no members are explicitly declared in these interfaces.
28 The interface is a completely abstract design and cannot be instantiated. The excuse type created by A in new way is actually to create an anonymous class that implements the interface type.
29 If two interfaces declare the same variable x, a compilation error will occur when an interface inherits the two interfaces at the same time, or a certain class implements the two interfaces at the same time.
30 If the method m of the same name is declared in both interfaces, and the two methods do not constitute overload, when an interface can inherit the two interfaces at the same time, or a certain class can inherit the two interfaces at the same time, there must be a method signature so that the signature is a sub-signature of the two m method signatures at the same time, and in the return type of the method, there must be a type such that the type is an alternative type of the return type of the two m method.