Beginners To learn Java, is javase, every day I learn from the day and notes, I hope you can criticize and advice, and promote common progress! The next day!

Source: Internet
Author: User
Tags logical operators

Day02
    1. Each writing a small program, first write a note to identify the role and purpose of the program. Important or critical statements are also written in comments. (A very useful habit later)
    2. Bytes, which is the smallest unit in the computer, and each byte consists of eight binary data. The data stored in the computer or on the hard disk are all saved in binary form.
    3. Data is generally available, binary, octal, hexadecimal. In binary, three bits represent one octal, and four bits represent a hexadecimal.
    4. In a computer, the binary representation of a negative number is the binary negation of this positive number plus 1 (so the highest bit of the binary with negative numbers is 1).
    5. Variable: is the storage of uncertain data, that is, the need to open up a space in memory.

Byte:1 bytes ( -128~+127); short:2 bytes; int:4 bytes;

Long:8 bytes; float:4 bytes; double:8 bytes;

When defining a float type variable, you need to add an F to the following. Because a decimal is defaulted by default to double type (for example, float f = 4.2f).

    1. byte B = 3; b = (byte) b + 2; The procedure for this line of code is to define a variable B of type Byte, assign a value of 3, and then perform the plus 2 operation. At this point, the computer automatically promotes the B type upward to int (automatic type promotion). The result is a value of type int, at which time the value is coerced to type byte and finally to B.
    2. In the computer, each character has its corresponding ASCII value (for example, the character A is 97, the character B means 98,a is 65, ' 1 ' is 49).
    3. String data and any data using the connection character "+" are all connected and will eventually become strings.
    4. Escape character: By "\" To change the meaning of the following letter or symbol, as follows:

\ n: Line break

\b: Backspace (equivalent to BACKSPACE)

\ r: Press ENTER

\ t: Tab (equivalent to Tab key)

System.out.println ("\" Hello "\") This line statement is a "hello" that takes advantage of the escape character output

    1. X+=4 is equivalent to adding the two to the left, i.e. x = x +4. But there is a difference between the two, when short x = 4 o'clock, there is no doubt that the latter is wrong, but the former is correct. Because the former only makes an assignment operation, it does an automatic type conversion. And the latter is to do an addition operation, first do an automatic type conversion, so that the result has become an int type, the last assignment resulted in a compilation error.
    2. Logical operators: Expressions for connecting a Boolean type ' & ' with a symbol of ' and ', ' | ' The symbol is "or" and the "^" symbol is "XOR". and the "&&" double and the rule is that once the left is false, the right side will not be the operation. "| |" Double or, when the left is true, the right side is not calculated. The operation efficiency of the two is higher than &,|.
    3. Shift character: 3<<2, meaning to move 3 to the left two bits, that is, 3 into binary data, and then move to the left two bits, the result is equivalent to 3 times 2 of the left shift power. Conversely, if it is 3>>2, move 3 to the right by two bits, then divide by 2 by the right shift power. (bit operation, the most efficient algorithm)
    4. Do not use third-party variables to achieve the exchange of two variable values, int a = 3 int b = 8;

The code is as follows: a = a + B;  b = a A; A = A–b;

The exchange is implemented. However, this method has the limitation that when the value of a and B is very large, the sum of the two is more easily than the maximum range of the int type variable.

The second method: a = a ^ b; b = a ^ b; (= a ^ b ^ b = a) A = a ^ b; (= a ^ a ^ b = b) (^ for, xor) this way, which does not involve numerical range operations, this is a tricky way.

    1. In a computer, if you want to convert a decimal number to a hexadecimal or octal number, the average computer is 16 minus 1 of the maximum value in hexadecimal (&) with the target number. Thus taking the first group to the lowest four bits. The target number is then shifted to the right by four bits (example: a >>4), and then with 15 (&). (And so, the octal conversion is done with 7 "with arithmetic", get the lowest three bits, then move right three bits)
    2. Ternary operator: basic format, (conditional expression)? (Expression 1): (expression 2). The meaning is that if the conditional expression is true, the expression 1 is executed, and the expression 2 is executed. In the previous note 16 binary gets the lowest four bits, if greater than 10. You need to convert to the corresponding letter, the code is as follows

N1 > 9? (char) (n1–10 + ' A '): N1;

Note: If the target number is negative, when using the shift character >>, the high-constant 1 is removed, resulting in a minimum of four-bit acquisition, which will not be completed at all. Therefore, the use of >>>, indicating whether positive or negative, both complement 0.

    1. In the program flow control statement switch, it features:
      1. The switch statement chooses only four types: Byte,short,int,char.
      2. There is no order between case and default, first case is executed and no matching case executes default.
      3. Two scenarios for ending a switch statement: When a break is encountered, execution ends at the switch statement.
      4. If the matching case or default does not have a corresponding break, then the program continues execution down, running statements that can be executed until the break is encountered or the end of the switch ends.
    2. The difference between a++ and ++a is that the former performs an expression and then a self-increment. The latter is the first self-increment, then executes the expression. For example, when B = a++, the step is to assign the value of a to B, and then A to self-increment. When B = ++a, it is the first self-increment of a, and then the self-increment of a is assigned to B.

Beginners To learn Java, is javase, every day I learn from the day and notes, I hope you can criticize and advice, and promote common progress! The next day!

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.