Java Self-study notes (next day)

Source: Internet
Author: User
Tags bitwise bitwise operators custom name

The Java Language Foundation consists of:

(1) Keywords: words that are given special meaning, main is not a keyword

(2) Identifier: Some of the custom name in the program, the custom name, consists of 26 letter case, the number 0-9,_$, the number can not start, can not use keywords, Java is strictly case-sensitive, in the name, in order to improve the reading, to try to make sense. Package name, all letters are lowercase. The class name and interface name, with the first letter of all words capitalized. The variable name and function name, the first letter lowercase, and the second word start with the first letter of each word capitalized. Constant name, with all letters capitalized.

(3) Note: Single line, multiple lines, document (Java-specific)

(4) Constant: constant indicates a value that cannot be changed. Three representations of Java integers, decimal, octal (0), hexadecimal (beginning with 0x), eight-bit binary number representing a byte of Byte (01101001), ASCII encoded table, decimal and binary conversion, binary negative number is positive negation +1

(5) Variables: storage of uncertain data, that is, in memory to open up a space. Note the variable name and cannot be duplicated.

(6) Data type: Basic data type: Numeric type: integer type: (byte-1 bytes, short-2 bytes, int-4 section, long-8 section)

Floating-point type: (float-4 bytes, double-8 bytes)

Character type: (char-2 bytes)

Boolean type: (boolean-2 value-true-false)

Reference data types: Classes: (Class)

Interface: (interface)

Array: []

float x = 1.0f; Float type value is followed by F.

A long y = 213123l;long type is followed by a lowercase L.

The integer type by default is an int floating-point type that defaults to double

A character type (char) can be used to perform operations.

byte x = 1;

x = x + 1; -X = (byte) (x+1);

int y = 2134;

y = y/1000*1000; The result is???.

      

(7) Operator: + Plus-minus + +-minus * multiply/divide% take remainder, ( -1%5) is how much??  (1%-5) What is the number?? + + self-reduction b=a++; the difference from b=++a

string concatenated with connection symbol (+): "AAA" + "BBB"

System.out.print (5+5); Run the result is???

System.out.print (' a ' +5+5); What is the running result???

System.out.print ("a" +5+5); What is the operation result???

System.out.print (5+5+ "a"); What is the running result???

String data and any data using the + sign are all connected and will eventually become strings

int A, B;
A=1;

B=++a;
System.out.print (A, b); The result of the operation is???

int A, B;
A=1;

B=++a;
System.out.print (A + "" +b), the operation result is???

int A, B;
A=1;

b=a++;
System.out.print (A + "" +b), the operation result is???

int A, B;
A=1;

b=a=a+1;
System.out.print (A + "" +b), the operation result is???

escape character \ : through \ To change the meaning of the following letter or symbol, example: \ n is the meaning of line break, \ r is the return, \ t tab.

System.out.print ("\" hello\ "");

System.out.print ("\\hello\\");

System.out.print ("\" hello\ "" +\t+ "\\hello\\"); error

System.out.print ("\" hello\ "" + "\ T" + "\\heloo\\");

char ch = ' \ '; Ch1= ";

System.out.print (CH+CH1); error

char ch = ' \ \ '; ch1 = ' \ ';

System.out.print (CH+CH1); Word relabeled mathematical operations

Assignment operator: = = = = *=/=%=: X+=1 is x=x+1? Is it ++x? is X + +?

Example: int a=0,b=0; B=a+=1;

b=a=a+1;

B=++a;

b=a++; b What is the difference??????

Example: short s = 5;

s = s+5; error, + and = are one addition and one assignment, data type mismatch error

(integer by default is int, decimal by default is double type)

s+=5; Yes, the + = number is an assignment operation, the left and right side of the + + assignment

Comparison operators: = =,! =, <,>,<=,>=,instanceof,

Logical operator: An expression used to concatenate a Boolean type

& (with) a false and false,

| (or) a true and true,

^ (XOR) on both sides of the same false difference is true,

! (non),

&& (double and) there is a little more efficiency than & higher for the false remainder of the part,

|| (double or) there is one for the true remainder of the calculation efficiency ratio | A little higher,

Bitwise operators:

<< (shift left): 3<<2=12---> is the 2-time 3*2

>> (right Shift): 6>>2=1---> is 6/2 2, the highest is 1 with 1, the highest bit is 0 with 0

>>> (unsigned Right Shift): 0-Padded

& (with) (when bitwise operators are used):

| (or) (when bitwise operators are used):

^ (XOR) (when bitwise operator is used): Same as false, different true, one number XOR or one number two times, result unchanged, encrypted using

~ (Anti-code): 0 ... 110=6---> (reverse)--->1...001---> (plus 1)---> 1...010=-6;

0...111=7 1...000 1...001=-7;

01111111 127
10000001-127 (129)
00000001 1
11111111-1 (255)
00000010 2
11111110-2 (254)
00000000 0
10000000 128

Using bitwise arithmetic, the hexadecimal number and binary number corresponding to the decimal number are calculated. Apply & and >>>

Ternary operator:x>1?100:200;

(8) Statement:

If Else statement: {} There is only one statement, {} can omit not to write

The difference between the ternary operator and if else: the ternary operator simplifies the if else code, but it is important to return a result when the operation symbol is finished.

Prioritize whether the data entered by the user is in the passenger calculation interval.

Switch statement: The data type that determines the condition is (Byte,short,int,char)

Switch () {

Case 1:

Case 2:

System.out.print ("AAAAA");

}

Multiple answers correspond to one execution statement

Switch cannot determine the Boolean type and is not suitable for judging intervals

Java Self-study notes (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.