-------Android Training, Java training, look forward to communicating with you! ----------
02.01 Overview and use of keywords
Keywords Overview: Words that are given a specific meaning by the Java language
Keywords feature: The letters that make up the keywords are all lowercase
Keyword considerations: Goto and Const exist as reserved words, not currently used, advanced Notepad like notepad++, with special color tags for keywords, very intuitive
Reserved words: May be promoted to keywords in new versions of JDK
02.02 Overview and composition rules for identifiers
Identifier Overview: A sequence of characters to use when naming classes, interfaces, methods, variables, etc.
Composition rules: English uppercase and lowercase letters, numeric characters, $ and _
Precautions:
1. Cannot start with a number
2. Cannot be a keyword in Java
3. Strictly case-sensitive
02.03 common naming conventions in identifiers
Common naming rules requirements: see Names and meanings
Package: All lowercase, multi-level package when used. Separate
Class or interface: The first letter of a word is capitalized, and the first letter of each word is capitalized when multiple words
Methods and variables: The first letter of a word is lowercase, and multiple words start with a second word with each first letter capitalized
Constants: All uppercase, multiple words separated by _
02.04 Overview of annotations and their classifications
Comment Overview: Text used to interpret the description program
Comment Classification format in Java
Single-line Comment: Format://Comment text
Multiline Comment: Format:/* Comment Text */
Document comments: Format:/** Note text */
1. For single-line and multiline comments, the annotated text is not interpreted by the JVM (Java Virtual machine).
2. 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.
02.05 HelloWorld Case Add Comment version
Cases:
1/* 2 Requirements: Write a program in console output HelloWorld 3 analysis: 4 1. Write a Java program that defines the class first. 5 2. The main method must be defined for the program to be able to be called by the JVM. 6 3. If the program wants to have output results, it must use the output statement. 7 8 Implementation: 9 1. The class keyword is used to define classes, followed by the class name 2.main method basic format: public static void Main (string[] args) 3. Output Statement basic format: System.out.println ("HelloWorld"), */14//helloworld case, class Demo16 { //main method, public static void Main (string[] args) + //Output statement System.out.println ("HelloWorld"); }23}
02.06 function of the annotations
1. Explain procedures to improve the reading of the program
2. Can help us to debug the program
02.07 Overview and use of constants
Constants Overview: Their values cannot be changed during program execution
Constants in Java categories: Literal constants and custom constants
Literal constants:
1. String constants: Examples of contents enclosed in double quotation marks: "HelloWorld"
2. Integer constants: All integers example: 12,23
3. Decimal constants: All decimal Examples: 12.34,56.78
4. Character constants: Examples of content enclosed in single quotes: ' A ', ' a ', ' 0 '
5. Boolean constants: Only True and false two values
6. NULL constant: null
02.08 binary Overview and binary, octal, hex
Java provides 4 representations of integer constants: binary, octal, decimal, hexadecimal
Introduction: The system is a carry system, is a kind of carry method.
For any kind of binary--x, it means that the number operation at a certain position is every x in a bit.
Binary is every two in one, eight into the system is every eight into a, decimal is every ten into one, Hex is 16 into one.
Conversion:
1byte (bytes) = 8 bit (bits)
1 k = 1024byte
Law, the larger the system, the shorter the form of expression.
02.09 representations of the different binary data
Binary: 0, 1, full 2 in 1, beginning with 0b
Octal: 0~7, full 8 in 1, with 0 beginning to indicate
Decimal: 0~9, full 10 in 1, integer by default is decimal
Hex: 0~9, A~f, full 16 in 1, starting with 0x
Any data exists in the computer as a binary form
02.10 conversion of any binary to decimal
Binary: 110 to decimal: 1*22 + 1*21 + 1*20 = 6
Octal: 110 to decimal: 1*82 + 1*81 + 1*80 = 72
Hex: 110 to decimal: 1*162 + 1*161 + 1*160 = 272
02.11 any decimal-based exercise
0b10101 to decimal: 1*24 + 0*23 + 1*22 + 0*21 + 1*20 = 21
0123 decimal: 1*82 + 2*81 + 3*80 = 83
0x3C to decimal: 3*161 + 12*160 = 60
02.12 decimal to any binary conversion
Decimal: 56 is converted into binary:
56/2 = 28...0
28/2 = 14...0
14/2 = 7 ... 0
7/2 = 3 ... 1
3/2 = 1 ... 1
1/2 = 0 ... 1
Combine the remainder from bottom to top, i.e. 0b 111000
Decimal: 56 into octal:
56/8 = 7...0
7/8 = 0...7
Combine the remainder from bottom to top, i.e. 0 70
Decimal: 56 to Hex:
56/16 = 3...8
3/16 = 0...3
Combine the remainder from bottom to top, i.e. 0x 38
02.13 decimal to arbitrary binary exercises
Convert decimal 52 to binary, octal, hexadecimal, respectively
Decimal: 52 into binary: 0b 110100
52/2 = 26...0
26/2 = 13...0
13/2 = 6 ... 1
6/2 = 3 ... 0
3/2 = 1 ... 1
1/2 = 0 ... 1
Decimal: 52 to octal: 0 64
52/8 = 6...4
6/8 = 0...6
Decimal: 52 to Hex: 0x 34
52/16 = 3...4
3/16 = 0...3
02.14 Fast Conversion method of the binary
Fast conversion of decimal and binary binary
8421 yards:
1 1 1 1 1 1 1 1
128 64 32 16 8 4 2 1
Cases:
100 turn into binary: 0b 01100100
101101 turn into decimal: 32+8+4+1 = 45
Binary and octal, 16 binary conversion
1. Use decimal as a bridge
2. Binary to octal: binary to octet from low to high for each three-bit group, insufficient high 0
Example: 100100 = (100) (100) =0 44
3. Binary to 16 binary: binary to hexadecimal from low to high every four bits of a group, insufficient high 0
Example: 100100= (0010) (0100) =0x 24
02.15 Original code anti-code complement
Symbolic data representation: In a computer, there are 3 notation numbers: The original code, the inverse code, and the complement.
All data is performed in the complement.
The original code: is the binary fixed-point notation, that is, the highest bit is the sign bit, "0" is positive, "1" is negative, the remaining bits represent the size of the value.
Anti-code: The inverse code of positive number is the same as its original code, and the inverse code of negative number is the inverse of its original code, except the sign bit.
Complement: The complement of a positive number is the same as its original code; the complement of a negative number is the minus 1 of its inverse code.
Cases:
7 The original code: 0 0000111
7 Anti-code: 0 0000111
Complement of 7:0 0000111
-7 of the original code: 1 0000111
-7 of the inverse code: 1 1111000 (on the basis of the original code in addition to the symbol bit by bit reversed)
-7 Complement: 1 1111001 (reverse code and 1)
02.16 Original code Anti-code complement practice
It is known that a number of the original code is 10110100, to seek its complement and anti-code
Original code: 1 0110100
Anti-code: 1 1001011
Complement: 1 1001100
The complement of a certain number is known to be 11101110, to seek its original code
Complement: 1 1101110
Anti-code: 1 1101101 (complement minus 1)
Original code: 1 0010010 (bitwise reversed)
02.17 Overview and format of variables
Variable Overview: The amount of value that can change within a range during program execution
Variable definition Format: Data type variable name = initialization value;
02.18 Overview and classification of data types
The Java language is a strongly typed language that defines specific data types for each data and allocates different sizes of memory space in memory
02.19 defining variables for different data types
Cases:
1//define a byte variable 2 byte b = 10; 3 4//define a short integer variable 5 shorter s = 7; 6 8//define an integer variable 9 int i = n; 10 100000000//define a long integer variable with a suffix plus l or l mark one-time 0000L;12 13//define a floating-point variable with a single-precision floating-point number suffix plus f or f mark float F = 12.34f;15
02.20 Considerations for using variables
Considerations for Using Variables:
Scope: The variable is defined in the curly braces, which range is the scope of the variable. Two variables of the same name cannot be defined in the same scope.
Initialization value: No initialization value can be used directly
It is recommended that you define only one variable on a line, but you can define multiple, but do not recommend
02.21 default conversion of data type conversions
The Boolean type cannot be converted to another data type
Default conversion: Byte,short,char→int→long→float→double
Byte,short,char do not convert to each other, they participate in the operation first converted to int type
02.22 different data type variables participate in operation interpretation
Cases:
1 byte a = 3;2 int b = 4;3 byte c = a + b;//error 4 int d = a + B; That's right
Explanation: The data-participation operation of byte type is promoted by default to int, the result of a + B is int, and cannot be assigned to a byte type C
02.23 Casting of data type conversions
Forced conversions
Target type variable name = (target type) (data to be converted);
Cases:
1 byte a = 3;2 int b = 4;3 byte c = (byte) (A + B);
The preceding statement discards the first three bytes of the result int of a + B, leaving the last byte assigned to C
02.24 study questions of the cast
1. The following assignment has no problem
Double d = 12.345;
float F = d;
A: There is a problem, you cannot assign a double type D to the float type F.
Required cast: float F = (float) D;
2. Are there any differences between the definitions below?
Float F1 = (float) 12.345;
float F2 = 12.345F;
A: There are differences, F1 is strong by double type to float type. The F2 itself is a type of float.
02.25 the distinguishing questions of the addition of variables and the addition of constants
BYTE B1 = 3,b2 = 4,b;
B = B1 + b2;//compilation failed, variable, type promoted first, b1+b2 result int type
b = 3 + 4; Correct, constant, calculate the result first, see if it is within the byte range, do not error
02.26 result calculation after casting data overflow
byte B = 130; Is there a problem? What do you do if you want to assign the correct value? How much is the result?
A: There is a problem, 130 is out of byte range, you can use cast byte B = (byte) 130;
Results:
int type 130 Original code: 00000000 00000000 00000000 10000010
int type 130 complement: 00000000 00000000 00000000 10000010
Cast drop high three-bit result is: 10000010
Complement: 1 0000010
Anti-code: 1 0000001
Original code: 1 1111110→ result is decimal-126
02.27 character data participation operations
System.out.println (' a '); A
System.out.println (' a ' + 1); 98, the character a participates in the operation using the corresponding 97 in the ASCII code table
02.28 String Participation Operations
System.out.println (' A ' +1+ "Hello"); 98hello
System.out.println ("Hello" + ' a ' + 1); Helloa1
System.out.println ("5+5=" +5+5); 5+5=55
System.out.println (5+5+ "=5+5"); 10=5+5
Dark Horse programmer-java Basic-java Basic Syntax 1