Java core technology volume I Basic knowledge (1), java Core Technology

Source: Internet
Author: User

Java core technology volume I Basic knowledge (1), java Core Technology
Chapter 3 basic program design structure of Java

  • Java is case sensitive.
  • The naming rule is the camel naming method. Reserved Words cannot be used.
  • The main method must be declared as public.
  • If the main method Exits normally, the exit code of the java application is 0, indicating that the program runs successfully. If you want to return other code when terminating the program, you need to call the System. exit method.
  • The common Java syntax is object. method (parameter), which is equivalent to function call.
  • System. out. print Output does not wrap
  • Three annotation Methods: //,/**/(cannot be nested), and the third method can be used to automatically generate documents.
  • Java is a strongly typed language, eight basic types, four integer types, two floating point types, A character type used to represent the character units of Unicode encoding and a boolen type used to represent the true value
  • Byte and short are mainly used in specific application scenarios, such as underlying file processing or large arrays that need to be controlled to occupy storage space.
  • The data type value is fixed, so no integer overflow occurs.
  • From Java 7, you can also underline the literal. For example, the compiler will remove the underline when "000_000" is used to represent 1 million.
  • In java, the number of bytes occupied by all numeric types is not related to the platform, and there is no unsigned type)
  • The numeric precision of double is twice that of float.
  • In fact, only a few cases are suitable for the float type. For example, you need to quickly process single-precision data or store a large amount of data.
  • The float type value has a suffix F. No default value is double.
  • In JDK5.0, you can use hexadecimal notation to represent floating point values. For example, 0.125 can be expressed as 0x1. 0p-3
  • Three special floating point values indicating overflow and error: positive infinity, negative infinity, and NaN (not a number ). For example, the result of dividing a positive integer by 0 is positive infinity. The square root of 0/0 or negative number is NaN.
  • All "non-numeric" values are considered to be different. A specific value cannot be equal to Double. NaN. The Double. isNaN method can be used.
  • The floating point value is not used in financial calculation to prohibit rounding errors. For example, System. out. println (2.0-1.1) will print out 0.899999999, mainly because the floating point value is represented in binary and cannot accurately represent the score of 1/10, just as it cannot accurately represent 1/3 in decimal.
  •  
  • We strongly recommend that you do not try the char type in your program unless you do need to operate on the UTF-16 code unit. It is best to represent the string to be processed with the abstract data type.
  • In java, if (x = 0) cannot be compiled, and x = 0 cannot be converted to a Boolean value (integer and boolean values cannot be converted to each other)
  • In java, each variable belongs to a type, and an example of declaring a variable
  • To know which Unicode characters belong to the "letters" in Java, you can use the Character-class isJavaIdentifierStart and isJavaIdentifierPart methods for detection.
  • $ Is a valid Java character, but do not use it in your own code. It is only used in the name generated by the Java compiler or other tools.
  • After declaring a variable, you must use the value assignment statement to display and initialize the variable.
  • Java does not distinguish between declarations and definitions.
  • Traditionally, constant names are all capitalized.
  • In Java, it is often expected that a constant can be used in multiple methods of A Class. These constants are usually called class constants and can be set with the keyword static final. If a constant is declared as public, the method of other classes also uses this constant.
  • Const is a reserved keyword in Java, but it is not currently used
  • If an integer is divided by 0, an exception occurs. If a floating point is divided by 0, an infinite number or NaN result is obtained.
  • If you mark a class as strictfp, all methods in this class must use strict floating point calculation.
  • Auto-increment and auto-increment Operators
  • We recommend that you do not use ++ in other expressions.
  • & | Calculates the value based on the "Short Circuit" method. If the first operand can determine the value of the expression, the second operand does not have to be calculated. If x = 0, 1/x is not calculated, no error is returned if x is divided by 0.
  • X <y? X: y
  • Int fourthBitFromRight = (n & 0b1000)/0b1000; if n is an integer variable and n represented in binary is 1 from the right number of 4th bits, 1 is returned; otherwise, 0 is returned.
  • Int fourthBitFromRight = (n & 1 <3)> 3. It is very convenient to use these two operators when you need to create a bit mode to block a specific user.
  • >>> The operator is filled with 0 to a high position. >>> the operator is filled with a sign bit to a high position. No <Operator
  • Add import static java. lang. Math. * at the top of the Math. sqrt Math. PI Math. E source file. You do not need to add the prefix "Math." Before the mathematical method name and constant name ."
  • If you want to get a completely predictable result that is more important than the Running Speed, you should use the StrictMath class.
  • Three virtual arrows indicate conversion with potential loss of Precision
  • Forced type conversion
  • The round method returns the long type.
  • If the strong type conversion exceeds the range indicated by the target type, the result will be truncated into a completely different value, (byte) 300 actual value is 44
  •  

  • Technically, Java strings are Unicode character sequences.
  •  
  • The String class does not have a method to modify the String. If you really want to modify it
  • The following expressions are valid:
  • = Operator checks whether two strings are placed in the same position
  • In fact, only string constants are shared, and the results produced by operations such as + or substring are not shared.
  •  
  • IsSupplementaryCodePoint (int codePoint) is a boolean method of the Character class, used to determine whether the specified Character (Unicode code point) is within the range of supplementary characters. In layman's terms, the Supplementary Character Set is a new character generated after the upgrade based on the standard old version of the basic data type. The supplementary character makes the char more complex but more powerful. Especially for the Southeast Asian market. If you use Unicode2.0, GB18030 in China belongs to its supplementary character set. I + = 2 means 2 bytes.
  •  
  • Read Input

  • First, you need to construct a callback object and associate it with "standard input stream" System. in.

  •  
  • Don't forget
  • Now we have seen the BASIC program structure of the Java language. The next chapter will introduce the object-oriented programming in Java.


 

Related Article

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.