Java Basic Finishing (1)

Source: Internet
Author: User
Tags arithmetic operators bitwise operators

1. The file name of the source code must match the class name of the public class, and there can be at most one common class (public) in a source code file 2. NOTES: 3 kinds
    • Line comment with double slash//start
    • Paragraph comment/* Comment content */
    • Document Comments/** Comments */
3.8 Basic types of data type
    • Integer 4 types: Byte (1byte), short (2 bytes), int (4 bytes), Long (8 bytes) are signed (signed)
    • Floating-point 2 kinds: Float (4 bytes), double (8 bytes) The former effective bit 6~7 bit, the latter 15-bit
    • Char type: char (2 bytes)
    • Boolean (1 byte) has only true and false two values and cannot be converted to an integral type
* * The integer data of the default in the Java compiler is type int, so a forced type conversion is required to assign a value to byte, short type **long (Long integer) value has a suffix l, hex prefix 0x, octal prefix 0, binary prefix 0b * * float suffix f,double suffix d (F, D case can be) **positive_infinity, negtive_infinity, nan denote positive infinity, negative infinity, and not a number 4. Logical operators
    • && according to "short-circuit" method evaluation, Eg:expression1 && expression2, if expression1 is false, do not calculate expression2
    • || Evaluated according to "short circuit" mode, Eg:expression1 | | Expression2, if expression1 is true, no calculation is necessary expression2
    • ! Represents the logical "non"
Bitwise operators
    • & |  ^ ~ with, or, XOR, non-**& | Do not calculate by short-circuit method
    • >> << Right Shift left
    • >>> is also the meaning of the right shift, and the difference between >> is that >> is filled with a sign bit high, and >>> is filled with 0 high
No <<< operator 5. Enum type custom enum type with enum Eg:enum Size {SMALL, MEDIUM, LARGE, extra_large}; Size size = Size.small; Indicates that size can only be one of the 4 sizes above 6. String Java does not have a built-in string type, but instead provides a predefined class in the standard class library, the string class is an immutable string
    • The difference between an empty string and a null string
The empty string "" is a string of length 0, is a Java object, has its own length (0) and the content (NULL) NULL string: Indicates that no object is currently associated with the variable
    • JDK5.0 introduced the StringBuilder class, formerly known as StringBuffer, which is slightly less efficient, but allows the use of multithreading to add and remove character operations.
7. Reading data from the console
    • Scanner class Scanner sc = new Scanner (system.in);
String S1 = Sc.nextline ();          Reads a row of string s2 = Sc.next ();               Read in a word, separated by a space int i = Sc.nextint (); Read into an int type integer
    • The console class is used to read passwords, because scanner is not suitable for reading passwords, so it uses the console class specifically
Console c = new Console (system.in);                    String ss = C.readline ();   Read in line char[] passwd = C.readpassword (); Read-in Password from console output (3 formats)
    • System.out.print ("");
    • System.out.println ("");
    • System.out.printf ("%d,%s", age,name);
8. Control process
    • You cannot declare a variable of the same name in a nested two block of statements, but you can declare a variable of the same name in two parallel (equal) statement blocks
    • Select statement Switch...case, If...else
    • Loop statement while, Do...while, for
    • Interrupt Control Flow statement: Label label, then break label, can jump out of loop to label position
9, Large value: if the basic integers and floating-point numbers do not meet the required precision, then you can use two useful classes in the Java.math package: BigInteger and BigDecimal. These two classes can handle numeric values that contain a sequence of arbitrary lengths.     BigInteger realizes the integer operation of arbitrary precision, and BigDecimal realizes the floating-point arithmetic with arbitrary precision. * * Unfortunately it is not possible to use our familiar arithmetic operators (+ 、-、/, *,%, etc.), but need to use BigInteger, BigDecimal Add, multiply, subtract, divide, mod (BigDecimal     No this method) operation.  Eg:biginteger A = biginteger.valueof (1000);  BigInteger B = biginteger.valueof (34567);  BigInteger C = A.add (b); BigInteger d = a.multiply (c); 10. Array * * Array length is 0 and null is different
    • Declaration Method 2 kinds of int[] A; int a[];
    • String[] s = new STRING[10];  Creates an array with 10 strings, all of which are null. * * Once you create an array, you cannot change its size, but you can change the contents of individual elements.
    • Anonymous array new int[] {2,14,35,47,57};
    • Numeric arrays can be sorted with arrays static method sort () (optimized fast sorting algorithm)

Java Basic Finishing (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.