1.JAVA Basics-Grammar-related

Source: Internet
Author: User
Tags bitwise bitwise operators control characters

1.1 of 8 basic data types

    • Numeric type
    1. Integer type: Byte (1 bytes), short (2 bytes), int (4 bytes), Long (8 bytes)
    2. Floating-point type: Float (4 bytes), double (8 bytes)
    • Non-numeric
    1. Character type: char (2 bytes)
    2. Boolean Type: Boolean

① about Byte (byte) and bit (bit): Data is stored in bytes (byte), which is mostly in bits (bit), in binary, a "bit" represents a 0 or 1, and each 8 bit constitutes a byte,bit is the smallest level of information unit.

② about the complement: Calculator storage binary values are expressed in complementary form. Positive, complement is consistent with the original code. Negative, complement the original code to reverse, and then add one.

③ about ASCII: The United States Standard Information Interchange code, an ASCII code of 1 bytes (byte), that is, 8 bit, where the highest level is used as the parity bit, the remainder of a 7-bit binary code, can represent 27 (128) states, each of which corresponds to a decimal sequence number 0~ 127, that is, a ASICC code can represent 128 kinds of characters. among them, 0~32 and 127 (a total of 34) are control characters or communication-specific characters, 33~126 (a total of 94) is a character, 48~57 is 0 to 9 a total of 10 Arabic numerals, 65~90 is 26 English capital letters, 97~122 is 26 English lowercase letters, The rest is some punctuation, arithmetic symbols, and so on.

④ is an integer type for byte:byte and can be written like this:

byte b = ' C ';

If you want to get the character C, you can turn the byte strong into char, as follows:

 Public Static void Main (string[] args) {    byte b = ' C ';    System.out.println ((char) b);}

The returned result is: C.

⑤ Char as an unsigned 16-bit primitive type integer for the Char:java language. That is, as a char of 2 bytes long, its value range is 0~65535, and the same as 2 bytes of short, its value range is -32768~32767.

⑥ the default type for Java: In Java, Integer data defaults to int, and floating-point data defaults to double. Therefore, the declaration of the float and long type data should be preceded by the tree value with L, L, or F, f.

1.2 Binary conversions

    • All kinds of decimal: from right to left for this number starting from 0 a one-digit label, the number of bits above multiplied by the exponent of this binary number of the power to sum.
      • (123.456) 10=1*102+2*101+3*100+4*10+5*10-1+6*10-2=123.456
      • (101.010) 2=1*22+0*21+1*20+0*2-1+1*2-2+0*2-3=5.25
      • (765.012) 8=7*82+6*81+5*80+0*8-1+1*8-2+2*8-3=501.01953125
      • (12A. C) 16=1*162+2*161+10*160+12*16-1=298.75
    • Decimal to a variety of binary: integer part divided by this binary number to take the remainder of the sort, the fractional part of the rounding is sorted.
      • For example (123.456) 10 turn binary: 123 except 2, the remainder is 1, 1, 0, 1, 1, 1, 0,0.456 by 2, the integers are 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1 ..., the remainder is sorted, the integers are sorted, and the result is (123.456) 10 = ( 111011.01110100101) 2

1.3 java keyword

Java has 50 reserved keywords, where the goto and const keywords are not defined for use as reserved words in the Java language.

1.4 operator

:&& in logical operations (logic and) and | | (logical OR) has a short-circuit function, that is, in &&, the previous false is the end of the comparison, directly return False, in | | , the previous one is true and the comparison ends and returns true directly.

Bitwise operators: Operations are performed on every binary in the two operands. Includes four types of operators: ~ (bitwise Inverse), & (Bitwise VS), | (bitwise OR), ^ (bitwise XOR)

//convert two of data without defining a new variable 1voidChangeint (intAintb) {System.out.println (The original A is: "+a+" \ n the original B is: "+b); A= A +b; b= A-b; A= A-b; System.out.println (Later A is: "+a+" \ n is: "+b);}//convert two of data without defining a new variable 2voidChangeint (intAintb) {System.out.println (The original A is: "+a+" \ n the original B is: "+b); A= a ^b; b= a ^b; A= a ^b; System.out.println (Later A is: "+a+" \ n is: "+b);}

Displacement operators: Divided into left (<<), signed Right (>>), unsigned Right shift (>>>).

    • Shift Left (<<): A<<b indicates that a binary form of a is shifted by a bit to the left B bit, and the lowest bit vacated by the B-bit 0.
    • Signed right Shift (>>): A>>b indicates that a binary form of a is shifted by a bit to the right of the B bit and the highest bit to the original symbol bit.
    • Signed right Shift (>>>): A>>>b indicates that the binary form of a is shifted by bit to the right B bit, and the highest bit is 0.
    • Note:a<<b is equivalent to multiplying a by 2b,a>>b equivalent to dividing a by 2b. because of the fast speed of the displacement operation, the multiplication operation which satisfies the power of 2 can be carried out by means of displacement.

1.5switch Selection Statement

About the type of the return value of the switch expression: Before jdk1.6, only one of the types in int, Byte, char, short four, and a new support for string types in jdk1.7.

1.6break and Continue

Break is used to jump out of the current loop and execute the statement following the loop (only one layer out); Continue is used to jump out of the remaining statement in the current loop body (one level out) and perform the Next loop.

Note: Break and continue only jump out of a loop, and if you want to jump out of a multi-layer loop, you can match the label. The code is as follows:

 Public Static voidMain (string[] args) {outer: for(inti = 0; I < 4; i++) {                 for(intj = 0; J < 5; J + +) {System.out.println ("I=" +i+ "j=" +j); if(i = = 3 && J = = 3) {                     Breakouter; }                if(J = = 2) {                     Break; }            }        }}

When j = = 3, the internal loop will stop, the external loop continues, I = = 3 and J = 3, the entire cycle will stop.

1.JAVA Basics-Grammar-related

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.