In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the common misunderstandings and details of Java". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the common misunderstandings and details of Java"?
1. In Java, there is no goto statement. The Java language eliminates the use of goto because the heavy use of Goto statements reduces the readability and maintainability of the program. At the same time, in order to avoid the confusion caused by programmers' own use of goto, the Java language still defines goto as a keyword, but does not define any syntax, so it is called "reserved word".
2.true, false, and null are displayed in different colors in IDE, but they are not keywords, but "literal constants", just like abc of type String.
3. Try to avoid using $when defining names, because when compiling .java files, the compiler compiles "$" into a connector between the top-level type and the bottom type. See the following example:
When compiling (javacTest3.java) this code, the compiler reports the following error: Test.java:12: error: class repetition: com.javastack.Test.Outer.InnerclassInner {^
4Unicode escapes characters are handled very early, before the parser. For example:
These two lines of code compile an error in the program. These two Unicode codes represent "line feeds" and "carriage returns" respectively, so when the compiler compiles, the code looks like this:
The 5.Unicode code uses 16-bit character encoding and is represented by the char type in Java. Now Unicode has been expanded to a million characters, and those that exceed the 16-bit limit have become supplementary characters. All supplementary characters cannot be represented by character constants.
6. When short,byte,char participates in the operation, the result is int, not the same as the higher type. If the variable is of type byte,short,byte, the compiler can implicitly shrink when it is assigned a compile-time constant that does not exceed the range of values of the variable. This implicit indentation conversion is safe because it applies only to the assignment of variables, not to method invocation statements, that is, parameter passing during method invocation. (for details, see the small problem with default type conversion in java)
7. Note the char type, which is an unsigned type. Therefore, conversions between char and short or between char and byte must explicitly use type conversions. The conversion from byte to char is the expansion-contraction conversion, which is special, that is, the byte extension is converted to int before shrinking to char.
8. In the extended conversion between integer data, if the Operand is of char type (unsigned type), the unsigned extension is performed, and the extension bit is 0. 0. If the Operand is byte,short or int (signed type), a signed extension is performed, and the extension bit is the symbol bit of the variable.
9. The contraction conversion between integer data is simply truncated and discarded high bits without any other processing.
10.0.1% 0.2 is not equal to 0.3.System.out.println ((double) 0.1 + (double) 0.2); the output of this statement is 0.300000000000004. Because computers use binary to store data, many decimals cannot be accurately represented in binary (in fact, most decimals are approximate), just as the use of decimals cannot accurately represent fractions like 1 pound 3. Most floating-point types store their values approximately in the computer, not as accurately as integers. As another example, this is an endless cycle: for (floatfavored 10.1f (floatfavored 10.1f)
The 11.float type can retain 7 to 8 valid digits, while the double type can retain 15 to 16 significant digits, so when the value of the int type or long type is more than the valid digits of double or float, some significant bits of the value will be lost, resulting in a loss of precision. In this case, the IEEE754 nearest rounding mode will be used to extract the floating-point value closest to the integer value. Although the conversion from integer to floating point is an extended transformation, when the value is very large or small (the absolute value is very large), there will be a certain loss of precision.
How is 12.i+++j calculated? It doesn't make much sense to discuss (this issue is discussed in Crample +), because Cmax Cure + depends on the hardware structure of the implementation, and the results will vary from environment to environment. However, in Java, this result is fixed and is not affected by the hardware environment and platform on which it runs. A: according to the greedy rule, the front + + is better than the post + +, and the result is (iTunes +) + j
13.Illumination + and + + I are actually + 1 first and then assigned. + + I, there is nothing to say; the underlying implementation, for example, is "temp=i;i=i+1;j=temp;", so "15" is the result of this expression is 15. (because the assignment is performed again after adding one, from 16 to 15.)
14. Symbol bits are different from-0 in floating-point type variable storage. Different results can be produced when-0 and + 0 participate in floating-point type correlation operations, such as division and congruence operations.
15. Floating-point division and remainder operation is different from integer division and remainder operation. When the divisor is 0, floating-point operation will not produce ArithmeticException exception.
The 16.String class is immutable, and once its objects are created, they cannot be destroyed. The methods of the String class that seem to modify the character sequence actually return the newly created String object rather than modify its own object.
17. Because String objects are immutable, they are thread-safe and can be shared freely.
18. Within the String class, a character array (char []) is used to maintain the character sequence. The * length of String is the * length of the character array. In theory, the * length is the * value of int type, that is, 2147483647. In practice, the value that can be obtained is generally less than the theoretical value.
The 19.main () method is basically the same as other methods in terms of behavior. It can be overloaded, called by other methods, inherited, hidden, or thrown with type parameters. We can also call the main method (or other methods) through reflection in a program.
20. When two or more methods have the same name but different parameter lists, these methods constitute overloading. The overloaded method can be distinguished according to the type of the parameter list and the number of parameters, but the name of the parameter, the return type of the method, the exception list of the method and the type parameter cannot be used as the condition to distinguish the overloaded method.
21. The order of which method call is chosen is as follows:
In the * * phase, automatic boxing (unboxing) and variable parameters are not considered, and the corresponding parameter type can match the actual parameter type and the number of formal parameters is the same as the number of parameters.
If there is no qualified method in step 1, automatic packing and unpacking will be performed in the second stage.
If there is no qualified method in step 2, in the third stage, the variable parameter method will be considered.
If no qualified method is found in all three phases, a compilation error will be generated. If there is more than one method of how to condition, the most specific method will be chosen. The clearest method is defined as: if the formal parameter list type of method A corresponds to the formal parameter list type of method B, then method An is more explicit than method B. If the clearest method cannot be selected, a compilation error will occur.
twenty-two。 The essential difference between rewriting and hiding is that overrides are dynamically bound and the members of the calling class are determined based on the actual type of the object that the runtime reference points to. Hiding is statically bound, and the relevant members of the call are determined according to the static type referenced at compile time. In other words, if the subclass overrides the method of the parent class, when the reference of the parent class points to the subclass object, the subclass method is called through the reference of the parent class. If the subclass hides the method of the parent class (member variable), the method of the parent class (member variable) is still called through the reference of the parent class.
23. The constructor is called recursively, and the constructor of the subclass invokes the constructor of the parent class until the constructor of the Object class is called.
24. The constructor does not create an object; it is called by the system when the object is created using new to initialize instance members of the class. Sequentially, the object is created and then the constructor is called. (the constructor does not produce a new object)
25. The default constructor, which is not empty, invokes the parent class's parameterless constructor and may perform initialization of instance member variables. Therefore, the default constructor at least invokes the constructor of the parent class, and it may do more, including instance variable declaration initialization and instance initialization blocks, which are performed in the constructor.
twenty-six。 When the type of the two operands of the = = or! = operator is a primitive data type and the other is a wrapper class reference type, the reference type is unboxed to a primitive data type, and then the values of the two primitive data types are compared to see if they are equal.
twenty-seven。 In Java, an array is also a class, and the reference variable declared by the array points to an object of the array type. All arrays inherit the Object class and implement the java.lang.Cloneable and java.io.Serializable interfaces. The members of the array include the variable length (implicitly present) and members inherited from the Object class. Cloneable and Serializable are two tagged interfaces in which no member is explicitly declared.
twenty-eight。 Interfaces are completely abstract designs and cannot be instantiated. The excuse type that A creates in new actually creates an anonymous class that implements the interface type.
twenty-nine。 If two interfaces declare the same variable x, a compilation error occurs when an interface inherits both interfaces, or when a class implements both interfaces at the same time.
thirty。 If a method m with the same name is declared in two interfaces and the two methods are not overloaded, there must be a method signature when an interface can inherit both interfaces, or when a class can inherit both interfaces, so that the signature is a subsignature of both m methods, and there must be a type on the return type of the method. So that the type returns the replaceable type of the type for both m methods.
Thank you for your reading, the above is the content of "what are the common misunderstandings and details of Java". After the study of this article, I believe you have a deeper understanding of the common misunderstandings and details of Java, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.