1. Java Language Foundation 2.1 keywords
Definition: Words that are given special meaning by the Java language
Feature: The letters in the keyword are lowercase
- Keywords to define the data type
Class,interface,byte,short,int, Long, float,double,char,boolean,void
- Keywords to define data type values
True,false,null
- Keywords to define Process Control
If,else,switch,case,default, While,do,for,break,continue,return
- Keywords used to define access rights modifiers
Private,protected,public
- Keywords for defining classes, functions, variable modifiers
Abstract,final,static,synchronized
- Keywords used to define the relationship between classes and classes
Extends,implements
- Used to define instance and reference instances, and to determine the keywords
New,this,super,instanceof
- Keywords for exception handling
Try,catch,finally,throw,throws
Package,import
Native,strictfp,transient,volatile,assert
2.2 Identifiers
L Definition: Some names defined in the program.
L Composition: 26 Letters in uppercase and lowercase, numbers: 0-9 symbols: _ $
L Legal Identifier Rules:
- Do not start with a number
- Unavailable keywords, reserved words
- Note: Java is strictly case-sensitive, so make the name as meaningful as possible
L Name Specification:
L constant Name: all letters are capitalized. For multiple words, each word is connected with an underscore.
Xxx_yyy_zzz
L variable name and function name: When multiple words are composed, the first letter is lowercase, and the second word starts with the first letter of each word capitalized.
Xxxyyyzzz
L Class name Interface name: When multiple words are composed, the first letter of all words is capitalized.
Xxxyyyzzz
L Package Name: All letters are lowercase when multiple words are composed.
Xxxyyyzzz
2.3 Notes
L Definition: text for annotation explaining the interpreter
L Role: Improve code reading
L Feature: For single-line and multiline comments, the annotated text is not interpreted by the JVM (Java Virtual machine). For a document comment, a Java-specific comment, where the comment content can be resolved by the tool Javadoc provided by the JDK, generating a set of documentation for the program as a Web page file.
L Format:
L Single-line comment:
Comment Text
L Multi-line Comment
/* Comment Text
*/
L Document Comments
/** Note Text */
2.4 Variables and constants 2.4.1 constant 2.4.1.1 classification of constants in Java
L Integer constant. All integers
L Decimal constant. All decimals
L-Boolean constant. More unique, only two values. True false.
L character Constant. A numeric letter or symbol is identified by a single quotation mark (' ').
L string constants. Identifies one or more characters in double quotation marks.
L NULL constant. There is only one value: null.
2.4.1.2 three representations of integers in Java.
• Decimal: 0-9, full 10 in 1.
• Eight binary: 0-7, 8 in 1. indicated by a 0 opening.
• 16 binary: 0-9,a-f, full 16 in 1. indicated by the beginning of the 0x.
Basic conversion of 2.4.1.3 binary
l Decimal Binary Mutual Transfer
• Decimal into binary divided by 2 to take remainder
• Binary into decimal multiplied by power of 2
L Decimal Octal Mutual transfer
l Decimal Hexadecimal Mutual transfer
L binary representation of negative numbers
• Corresponding positive binary counter plus 1
2.4.2 Variable
The concept of the L variable:
A storage area in memory that has its own name (variable name) and type (data type), and the region's data can be changed over the same type range
Why to define variables:
Used to keep constant of the same type, and can be reused
L Variable Use NOTE:
- • The scope of the variable (valid between a pair of {})
- • Initialize values
L define the format of the variable:
- • Data type variable name = initialization value;
L Type Conversion
L Automatic type conversion (also called implicit type conversion)
byte B = 3;
int x = 4;
x = x + b;//b automatically promoted to int type
l Coercion of type conversions (also called explicit type conversions)
byte B = 3;
B = B + 4;//error
b = (byte) b+4;//coercion type conversion, forcing the result of the b+4 to be converted to a byte type, and then assigning a value to B
L Data type automatic promotion
- • All byte, short, and char values will be promoted to type int.
- • If an operand is long, the result is a long type;
- • If an operand is of type float, the result is a float type;
- • If an operand is of type double, the result is a double type
2.5 operator
2.5.1 Arithmetic operators
Attention:
L if the negative number modulo, you can ignore the modulus minus, such as: 5%-2=1. But the modulus is a negative number is another matter.
L for Division Sign "/", its integers except and decimals are distinguished: when dividing between integers, only the integer part is left and the fractional part is discarded.
L "+" can also convert non-strings to strings in addition to the function of string addition
2.5.2 Assignment operator
Symbol:
= , +=, -=, *=, /=, %=
2.5.3 comparison Operators
2.5.4 logical operators
Attention:
L logical operators for connecting Boolean expressions
L The difference between "&" and "&&":
- • Single &, on the left whether true or false, on the right side of the operation;
- • Double & If the left is true, the right side participates in the operation, if the left is false, then the right side does not participate in the operation.
L "|" and "| |" The difference is the same
- Dual or time, the left is true, the right side does not participate in the operation.
L XOR (^) with or (|) The difference is: when both left and right are true, the result is false
2.5.5-bit operators
L <<
The vacancy is 0, the removed high position is discarded, and the vacant bit is 0.
L >>
The displaced binary highest bit is 0, after the right shift, the vacancy is 0, the highest is 1, the vacancy bit is 1.
L >>>
The top bit of the shifted binary is either 0 or 1, and the vacant bit is filled with 0.
L &
Bits for & operations, only 1&1 when the result is 1, otherwise 0;
l |
Bits | Operation, only 0 | 0 o'clock the result is 0, otherwise it is 1;
l ^
Any of the same bits ^ operations, the result is 0;1^1=0, 0^0=0
Not the same bits ^ operation result is 1. 1^0=1, 0^1=1
2.5.63-dollar operator
Format:
(conditional expression)? Expression 1: Expression 2;
• If the condition is true, the result of the operation is an expression of 1;
• If the condition is false, the result of the operation is an expression of 2;
2.6 Process Control 2.6.1 judgment structure
Format:
L if (conditional expression) {EXECUTE statement;}
L if (conditional expression) {EXECUTE statement;} else {EXECUTE statement;}
L if (conditional expression) {EXECUTE statement;} else if (conditional expression) {EXECUTE statement;} ... else {EXECUTE statement;}
2.6.2 selection Structure
Switch statement
Format:
switch (expression)
{
Case value 1: EXECUTE statement;
Break
Case Value 2: EXECUTE statement;
break;
Default: Execute statement;
Break
}
Characteristics:
The l switch statement selects only four types: Byte,short,int, char.
L There is no order between case and default. Executes the first case, without matching case execution default.
L Two cases of ending a switch statement: When a break is encountered, execution ends at the switch statement.
If the matching case or default does not have a corresponding break, then the program will continue execution down, running the statement that can execute until the break is encountered or the end of the switch ends
2.6.3 Cycle Structure
Delegate statements: While, do and for
Format:
L While Statement format: while (conditional expression) {EXECUTE statement;}
l Do While statement format: do {EXECUTE statement;}while (conditional expression);
L for Format: for (initialize expression; loop conditional expression; post-loop action expression) {EXECUTE statement;}
Characteristics:
The L do while is characterized by whether the condition is satisfied or not, the loop body is executed at least once.
The order in which the expressions are run in the for, the initialization expression is read only once, the loop condition is judged, the loop body is executed for the real, then the operation expression after the loop is executed, and then the loop condition continues to be judged, and a process is repeatedly found until the condition is not satisfied.
The l while and for are interchangeable, except that variables defined for the purpose of the loop are freed in memory at the end of the For loop. While the variables used by the while loop can continue to be used after the loop ends.
L simplest infinite loop format: while (true), the for (;;), the reason that an infinite loop exists is not knowing how many times the loop is, but depending on some conditions, to control the loop.
2.6.4 Other Process Control statements
Break (jump out )
Break statement: Application scope: Select structure and loop structure.
continue ( continued)
Continue statement: Applies to the loop structure.
Attention:
- These two statements leave the scope of the application, there is no point.
- This two statement is unique and cannot have a statement below because it cannot be executed.
- The continue statement is the end of this loop to continue the next loop.
- The appearance of the label allows the two statements to function in the specified range.
Java Learning Summary (ii)----Java language basics