1. The relationship between JDK,JRE,JVM
JVM
Is the Java
virtual machine, is the Java
important guarantee of cross-platform, JVM
realize the Java
premise of cross-platform, can be different for different operating system JVM
.
Languages can be said to Java
be cross-platform, but JVM
not.
JRE
Is the Java
run-time environment that contains the JVM
+ core class library.
JDK
is a Java
development kit that contains development tools + JRE
.
2. Java classification-javase, Java EE, javame
JavaSE
For the Standard Edition, JavaEE
for the Enterprise Edition, JavaME
for the mini version
3. Key reserved words in Java
Java
There are two keywords currently not used, for goto
and const
, in Java
, all of the keywords are lowercase.
4. Identifiers
Identifier rules: 可以使用字母,数字,_ ,以及美元符号 $
in the Java
Chinese name can be used, but it is not recommended to use, you can not use the keyword, or the beginning of the array, attention to the case-sensitive, to see the name of the understanding
5. Hump Naming method
- Class name and interface name, if there are multiple words, the first letter of each word should be capitalized, as
HelloWorld
- Variable name and method name, if there are more than one word, then the first letter should be lowercase and the first letter of the other words should be capitalized, as
helloWorld
- Constant name, no matter how many words are composed, all letters are uppercase, emphasizing that each word must be separated by _, as
HELLO_WORLD
- The package name, no matter how many words are composed, all the letters are lowercase, emphasizing a little is used between each word. Separated, as
cn.dashucoding.com
6. Annotations
The Java
annotations in are used to explain what the code does and what it does, and as a qualified programmer, you must know how to annotate the code.
Single-line Comment
// 注释文字
Multi-line comments
/*注释文字*/
Document comments
/**注释文字*/
The text in a document's comments can be extracted to form a document.
7. Literal
Literal: Refers to a value that is immutable in the computer
1. integer constants (all integers)
2. Decimal Constants (all decimals)
3. Character Constants (a letter, a number, a symbol, and a "logo")
4. string Constants (identify one or more characters with "")
5. Boolean Constants (True and False)
6. NULL constant (NULL)
8. Binary
Binary : start with 0b/0b (0~1, full 2 in 1)
octal: starts with 0 (0~7, 8 in 1)
decimal: No special identification (0~9, 10 in 1)
16 binary: start with 0x/0x (0~9,a~f, full 16 in 1)
Conversion between the binary systems
decimal to binary: constantly dividing by 2, then taking the remainder
Binary to decimal: multiply from the lowest bit by 2 to the power of precedence, then sum
Similarly:
Decimal to other binary: divide by the corresponding binary number, and then take the remainder
Other decimal: Start with the lowest bit, multiply by the order of precedence, and then sum
Binary to octal, but also from the low start, every three bits of binary for a group, the generation of an octal number, the highest bit less than three, on 0, together three bits can be.
Formula: three Change one
Octal binary system, each octet number will produce three-bit binary digits, less than three 0 can be.
Formula: one change three
Similarly
Binary to 16-bit: The formula for four change one
16-bit binary to binary: formula for one change four
9. Variables
Format:
数据类型 变量名 = 数据;int i = 2;// 变量的声明int i;// 变量的赋值i = 2;// 存储bit为最小单位,8位为1字节(byte,简写为B)
Data type
Data type: base data type and reference data type
Basic data types
Byte-1 short-2 int-4 long-8
Float-4 double-8 Char-2 Boolean
Long---l FLOAT---f
Reference data type
Reference data types: arrays, classes, interfaces
10. Conversion of data types
Conversion of data types:
- Automatic type conversion/implicit conversion
- Forcing type conversions/explicit conversions
Automatic type conversions: small types can be automatically converted to large types
char
Can be converted to, int
long
can be converted to float
, other forward conversions, may produce a loss of precision
// short char // ok 可行 字面量如果在范围内允许转化short a = ‘b’;char c = 97;// not 不可行 可能超过范围,所以不允许转化char c = ‘a’;short b = c;
coercion Type conversions: large types are forced into small types, which can result in data loss accuracy
// 强制类型转换double d = 3.14int i = (int)d;
11. Operators
+ - * / % ++ --
+ +/-self-increment/auto-subtract
int j = i++; // j = i ; i++int j = ++i; // ++i ; j = ++i
Assignment operators
= += -= *= /= %= &= |= ^= <<= >>= >>>=
Relational operators
> < >= <= == !=
logical operators
& 与Or 或Not 非^ 亦或&& 短路与|| 短路或短路 表示如果前面的表达式正确,后面的就不再运行&&:前边的表达式结果为false,后面的就不再运行||:前面为true,后面就不再运行
Bit arithmetic
& | ^ << 左移 >> 右移 >>> 无符号右移 ~ 取反
&, 1 is considered true, and 0 is considered false,0& any number of 0,1& odd numbers is 1,1& even 0.
| , with 1 being 1.
Ternary operators
Format:
Logical value? Expression 1: Expression 2
Precedence of Operators
() ~ ++ -- ! * / % + - << >> >>> 关系 逻辑 & | ^ 三元 赋值
Unary operations > Two-ary Operations > Ternary Operations > Assignment
12. Process Control
If,if-else, If-else if
Branching structure
if(逻辑值){代码块;}
if(逻辑值){代码块;} else {代码块;}
switch(逻辑值){case 值:代码块;break;case 值:代码块;break;...}
switch
Supportbyte/short/char/int/String
while(逻辑值){代码块;}
do{代码块;} while(逻辑值);
while, do-while
for(定义循环变量; 控制条件; 改变循环变量){ 代码块;}
Break and Continue
break:
Represents terminating the current layer of a loop structure
continue:
Represents skipping the current loop to continue the next loop
14. Arrays
Format:
data type [] Array name = new data type [length];
data type [] Array name = new data type []{element 1, Element 2, Element 3 ...};
int[] arr = new int[]{2,3,4,5,6};
Int[] arr = {2,5,7,8,9};
Application of arrays
- Array name [subscript]
- Array name. length
- Iterating through an array
- Gets the maximum value in the array
- Sorting of arrays
- Invert an array
- Searching for array elements
for(int i = 0; i < arr.length; i++){System.out.println(arr[i]);}
for(int i : arr){System.out.println(i);}
// 冒泡排序for(int i = 1; i < arr.length; i++){for(int j = 1; j <= arr.length - i; j++){ if(arr[j - 1] > arr[j]){ int temp = arr[j - 1]; arr[j - 1] = arr[j]; arr[j] = temp; } }}
// 选择排序for(int i = 1; i < arr.length ; i++){ for(int j = i; j < arr.length; j++){ if(arr[i - 1] > arr[j]){ int temp = arr[i - 1]; arr[i - 1] = arr[j]; arr[j] = temp; } }}
Array:,,, Arrays.sort
Arrays.toString
System.arraycopy
Arrays.copyOf
15. Memory
Java
Memory:
Stack memory, heap memory, method area, local method stack, PC counter (register)
Stack memory is used to store variables
Heap memory is used to store objects
16. Methods
Format:
修饰符 返回值类型 方法名(参数列表){方法体;return 返回值;}
Overloading of methods
Method name is the same but parameter list is different
The value of the method
The pass-through value of the method, the actual value of the base type , the address of the reference type
17. Shortcut keys
Ctrl + x 剪切Alt + / 快捷提示键Ctrl + Shift + o 导包Ctrl + Shift + f 调整格式Ctrl + F 搜索Ctrl + D 删除一行
18. member variables and local variables
- member variables in a class, local variables in methods
- Member variables function throughout a class, local variables can only be in its methods, or in statements
- Member variables are stored in heap memory and are automatically assigned default values;
- Local variables are stored in stack memory and are not automatically assigned default values
The constructor method, with the same name as the class name, has no return value, and the constructor can overload
this
Keyword that represents a reference to an object in this class
Can be this
constructed by invoking the corresponding form in the original
Object-oriented features for encapsulation, inheritance, polymorphism
Conclusion
- Below I will continue to
Java
the Android
other knowledge, in-depth explanation, interested can continue to follow
- A little gift to walk or like.
Java Interview Collection (iv)