Java knowledge point summary

Source: Internet
Author: User
Tags bitwise operators

1. Java is a compilation and Interpretation Language.

2. Java's garbage collection mechanism:
Java garbage collection will be automatically executed during the program running, without the need for programmers to recycle useless memory.

3. Java environment variable Configuration:
Add the C:/program files/Java/jdk1.6.0/bin path to the path in my computer> Properties> advanced> environment variable (Note: put it at the top of all paths ).

4. Java program entry method:
Public static void main (string [] ARGs ){
}

5. The public class name must be the same as the Java file, and only one public class can be included in a Java file.

6. Java notes:
// Single line comment
/**/Multi-line comments (not nested)
// **/Notes

7. Valid identifier:
It can start with a letter, underscore "_" and "$", and consist of letters, underscores "_", and "$" or numbers. It cannot be the same as a keyword in Java.

8. Keywords
Some words in Java that give specific meanings and are used for special purposes are called keywords. All are in lower case.

9. Java data types are classified into simple and reference types.
Simple Type: Numeric (integer and floating point), numeric, and Boolean.
Reference types include class, interface, array, and enumeration.

Valid range of data types (BITs)
Boolean 1
Byte 8
Int 32
Float 32
Char 16
Short 16
Long 64
Double 64

10. boolean type boolean B = true; Boolean B = false;

11. Branch Statement (if Statement)
Format:
If (true ){

} Else {

}
Or
If (Boolean B ){
 
} Else if (Boolean B ){
 
} Else {
 
}

12. Integer type
Number of tables in which the data type occupies the storage space
Byte 1 byte-128 ~ 127
Short 2 byte-32768 ~ 32767
Int, 4 bytes-2147483648 ~ 2147483647 (-2 ^ 31 ~ 2 ^ 31-1)
Long 8 bytes-2 ^ 63 ~ 2 ^ 63-1

13. bytes (2 bytes), using Unicode encoding.
Format: Char c = 'a'; char c = 98; char c = '中 ';
Note: use single quotes. A Chinese character can be represented by a char. Add "/" before special characters "/".

14. Floating Point Type
Number of tables in which the data type occupies the storage space
Float 4 bytes-3.403e38 ~ 3.403e38
Double 8 bytes-1.798e308 ~ 1.798e308

Format: Double D = 12; float F = 12.5f;

15. Conversion of various Integer Data Types
In addition to the boolean type, other data types can be automatically converted to other data types.
However, the following principles must be followed:
Byte --> short --> int --> long ---> float --> double
Char --> int
Int ------------> float
Long -------------> double

16. Operators
Note the priority. use parentheses.
Int x = 4/5*5;
X = 0 instead of 4;

17. Relational and boolean operators
Relational operators: = (equal ),! = (Not equal to),> (greater than), <(less than),> = (greater than or equal to), <= (less than or equal)
Logical OPERATOR :! (Logical not), & (logical and), | (logical or), ^ (logical exclusive or), & (short and), | (short or)

18. Three-object conditional Operators
Syntax format: X? Y: Z
Calculate the value of X first. If it is true, the result is Y. Otherwise, the result is Z.

19. bitwise operators
~ (Reverse)
& (Bitwise AND)
| (By bit or)
^ (By bit or)

~ 01001111 = 10110000
11001011 & 01101101 = 01001001
11001011 | 01101101 = 11101111
11001011 ^ 01101101 = 10100110

20. Shift Operator
>>: Shifts the left operand to the right. The number of shifts is determined by the right operand (Shifts one digit to the right equals to divide 2 ).
<: Left-shift operator, which moves the left operand to the left. The number of shifts is determined by the right operand (the value of one left operand is equivalent to the value of 2 ).
>>>: Unsigned right shift operator.

4 = 0100; 4> 1 = 0010;
4> 1 = 2; 12> 2 = 3; 5> 1 = 2;-4> 1 =-2;
4 <1 = 8; 4 <2 = 16;-3 <1 =-6;
8 >>> 1 = 4;-4 >>> 1 = 2147473646;

21. Value assignment operator
The most common assignment operator: "="
Extended value assignment operator: "+ =,-=, * =,/=, % =, ^ =, & =, | =, >>=, <=, >>="

Int I = 5;
I + = 5; that is, I = I + 5;
I-= 2; I = I-2;
(Others)

Double d1 = 5.0;
Float F1 = (float) d1;
Byte b1 = (byte) 350; Result: b1 = 94;
(From big to small, forced transformation is required. Data may be lost during forced transformation)

22. String connector "+"
When "+" is used in an expression, if one of the operands is of the string type, Java automatically converts the other operand to the string type and then concatenates it into a new string.
Int b1 = 2;
Int b2 = 3;
String S1 = "S" + B1 + B2;
S1 = S23; instead of S5; if you want S5, you can use "S" + (b1 + b2)
String S2 = b1 + B2 + "S ";
S2 = 5S; if you want to get 23 S, you can add an empty string in front of "+ B1 + B2 +" S"

23. Expression
Expressions are the combination of operators and operands (a variable and a number are also expressions ).

-Concatenation of operators in expressions
In Java, most operations are performed from left to right, except for single object, assignment, and conditional operators.

-Priority of operators in expressions
(Maximum) separator:. [] (),;
(2nd) single object operators: +,-, and ,-,~ ,! , ++ ,--
(3rd) Create or type conversion: New (type) expr
(4) multiplication and division: *,/, %
(5) addition and subtraction: + ,-
(6) shift: <, >>,>
(7) Relationship: <, <=, >=,>
(8) equivalent: = ,! =
(9) bitwise AND :&
(10) bitwise OR: ^
(11) bitwise OR: |
(12) conditions and :&&
(13) condition or: |
(14) condition :? :
(15) Value assignment: =
Note: In normal times, the priority level cannot be relied on, and all operations must be enclosed in brackets.

24. Branch statement
If-else statement
Switch statement

Switch statement format:
Switch (expr1 ){
Case constant1:
Statements;
Break;
Case constant2:
Statements;
Break;
......
Default:
Statements;
Break;
}

Note: In switch (expr1), expr1 and case constatnt1: constatnt1 can only be int type or can be converted to int type. For example, char short byte

25. Cyclic statements
-
-Do/while
-While

While statement format:
Int I = 0
While (I <10 ){
System. Out. println ("I =" + I );
I ++;
}

Note: B in while (B) must be of the boolean type, that is, true or false.

For statement format:
For (INT I = 0; I <10; I ++ ){
System. Out. println ("For Loop ~ I = "+ I );
}
Note: the lifecycle of I is in the for loop.

Do/while statement format:
Int I = 0
Do {
System. Out. println ("I =" + I );
I ++;
} While (I <10 );
Note: The difference between the while statement and the do/while statement is to determine whether to do it first. When the first condition is not met, the DO/while statement will execute the code in the loop body, but the while statement will not.

-Break/continue statement
The break statement completely jumps out of the loop.
When there is a break in a loop, only the cycle closest to it exists.
For (INT I = 1; I <100; I ++ ){
If (I = 50 ){
Break;
}
}
In the above loop, when I = 50, the loop ends.

The continue statement is used to skip the remaining statements in the loop and start the next loop.
Int sum = 0;
For (INT I = 1; I <100; I ++ ){
If (I % 2) = 0 ){
Continue;
}
Sum + = I;
}
The above loop jumps out of this loop when I is an even number. That is, sum + = I is not executed, and the next loop is directly carried out.

26. static method call

Public class teststaticmethod {

Public static void main (string [] ARGs ){

System. Out. println ("======== ");

Hello (); // call directly

Teststaticmethod. Hello (); // call it using the class name + vertex + method name
System. Out. println ("======== ");

Int x = 5;

Teststaticmethod. printhello (x); // call a method with parameters. A value of the same type as the parameter must be provided during the call.

Int z = 10;

Int result = teststaticmethod. multy (z); // call a method with a parameter and a return value. To obtain the return value, you must define a variable of the same type to receive the return value of the method.

System. Out. println (result );

}
 
// No return value, no Parameter Method
Public static void Hello (){

System. Out. println ("Hello ....");
}
 
// Method with no return value and Parameters
Public static void printhello (int n ){

For (INT I = 0; I <n; I ++ ){

System. Out. println ("Hello..." + I );
}

}
 
// Methods with return values and parameters. Return a value of the same type.
Public static int multy (INT y ){

Int r = y * 2;
Return R;

}

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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.