Java Core Technology Volume Ⅰ Basics (1)

Source: Internet
Author: User
Tags square root

Chapter three basic program design structure of Java
  • Java is case sensitive
  • Name specification for camel nomenclature, cannot use reserved word
  • The main method must be declared public
  • If the main method exits normally, the Java application's exit code is 0, indicating that the program was successfully run. If you want to return additional code when you terminate the program, you need to call the System.exit method.
  • The Java general syntax is object.method (parameter), which is equivalent to a function call
  • System.out.print Output No Line break
  • Three ways to annotate/////*/(Cannot nest), third can be used to automatically generate documents
  • Java is a strongly typed language, eight basic types, four integers, two floating-point types, a character type used to represent Unicode encoded character cells char, and a type of boolen that is used to represent truth values.
  • Byte and short are primarily used for specific applications, such as underlying file processing or large arrays that require control over the amount of storage space consumed.
  • Data type is fixed, so no integer overflow occurs
  • Starting with Java7, you can also underline the literal, such as using 1_000_000 to represent 1 million, and the compiler will remove the underscore
  • In Java, the number of bytes occupied by all numeric types is platform independent, without any unsigned type (unsigned)
  • Double is twice times the numerical precision of float
  • In fact, there are very few cases where you can try float type, for example, you need to process single-precision data quickly, or you need to store large amounts of data
  • A value of type float has a suffix f and no default is double
  • In JDK5.0, you can use hexadecimal to represent floating-point values. For example, 0.125 can be represented as 0x1.0p-3
  • Three special floating-point values that indicate overflow and error: positive infinity, negative infinity, NaN (not a number). For example, a positive integer divided by 0 results in positive infinity. Calculates the square root result of a 0/0 or negative number as Nan
  • All non-numeric values are considered to be different and cannot be equal to Double.NaN with a specific value, and you can use the Double.isnan method
  • Floating-point values are not used to prohibit rounding errors in financial calculations. For example, System.out.println (2.0-1.1) will print 0.899999999, mainly because the floating-point value is in binary notation and cannot accurately represent a fraction of 1/10, just as the decimal does not accurately represent 1/3
  • We strongly recommend that you do not try the char type in your program unless you do need to manipulate the UTF-16 code unit. It is best to represent a string that needs to be processed with an abstract data type.
  • In Java, if (x=0) cannot be compiled, 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, declaring a variable example
  • To know which Unicode characters belong to the "letters" in Java, you can use the Isjavaidentifierstart and Isjavaidentifierpart methods of the character class to detect
  • $ is a valid Java character, but do not use this character in your own code, it is used only in names generated by the Java compiler or other tools.
  • After declaring a variable, the variable must be displayed with an assignment statement to initialize
  • In Java, Declaration and definition are not distinguished
  • In practice, the constant name uses all caps
  • In Java, you often want a constant to be used in multiple methods within a class, often referred to as class constants, and you can set a class constant using the keyword static final. If a constant is declared public, then the methods of the other classes use the constant
  • Const is a keyword reserved by Java, but is not currently used
  • An integer is 0 in addition to an exception, and the floating-point number is 0 in addition to the infinity or Nan result
  • If you mark a class as STRICTFP, all methods in this class use strict floating-point calculations
  • Self-increment and self-decrement operators
  • It is not recommended to use + + inside other expressions
  • && | | is evaluated in a "short-circuit" manner, if the first operand is already able to determine the value of the expression, the second operand does not have to be evaluated. If the x=0,1/x is not counted, there will be no error divided by 0.
  • X<y?x:y
  • int fourthbitfromright= (n&0b1000)/0b1000; if n is an integer variable, and n is represented by the binary in the right number, the 4th bit is 1, 1 is returned, otherwise 0
  • int fourthbitfromright= (N&1<<3) >>3; It is convenient to use these two operators when it is necessary to establish a bit pattern to mask a bit
  • The >>> operator fills the high position with the sign bit with the 0 fill high;>> operator; no <<< operator
  • Math.sqrt Math.PI MATH.E The top of the source file plus import static java.lang.math.*; You do not have to prefix the math method name and the constant name with "math."
  • If you want a fully predictable result that is more important than the running speed, then you should use the Strictmath class
  • 3 virtual arrows for conversions that may have a loss of precision
  • Strongly typed conversions
  • The round method returns a long type
  • If a strongly-typed conversion exceeds the target type representation range, the result is truncated to an entirely different value, (byte) 300 The actual value is 44
  • Conceptually, a Java string is a sequence of Unicode characters.
  • The string class does not have a way to modify the strings, if you really want to change them
  • The following expressions are legal
  • The = = operator detects whether two strings are placed in the same position
  • In fact, only string constants are shared, and the results of operations such as + or substring are not shared
  • Issupplementarycodepoint (int codepoint) is a Boolean method of the character class that determines whether the specified character (Unicode code point) is within the supplementary character range. In layman's words, the supplemental character set is the new character that is created after the upgrade of the standard old version of the basic data type. Supplementary characters make the Char happy greetings complex but more powerful. In particular, the business needs of the Southeast Asian market. If you use the Unicode2.0 version, China's GB18030 belong to its supplementary character set. The i+=2 means that it accounts for 2 bytes.
  • Read input

  • First, you need to construct a scanner object and associate it with the standard input stream system.in

  • Don't forget
  • Now that you have seen the basic program structure of the Java language, the next section introduces object-oriented programming in Java.


Java Core Technology Volume Ⅰ Basics (1)

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.