JAVA Study Notes - summarized articles (a)
A, Java Overview
- JVM (Java Virtual Machine): Java Virtual Machine. Java programs run directly in the JVM, so to ensure the cross-platform features of Java. JVM Java programs and act as a bridge platform.
- JRE (Java Runtime Environment): Java runtime environment, including the JVM + Java core class libraries.
- JDK (Java Development Kit): Java development tools, including jre + development tools. Developers using the JDK to compile, debug, and execute Java programs.
Two, Java data types
java data types can be divided into two categories: basic data types and the reference data type.
Types of | Keyword | Occupation and byte-digit | Value range |
---|---|---|---|
Byte | byte | Occupies 1 byte (i.e. 8 bits) | -128 to 127 (i.e.: -2 . 7 ~ 2 . 7 - 1) |
Short integer | short | 2 bytes (i.e., 16) | -32 768 to 32 767 (i.e.: -2 15 to 2 15 - 1) |
Integer | int | Occupies 4 bytes (32-bit) | ~ -2147483648 2147483647 (i.e.: -2 31 is ~ 2 31 is - 1) |
Long integer | long | It occupies 8 bytes (i.e., 64) | -9223372036854775808 ~ 9223372036854775807 (i.e.: -2 63 is ~ 2 63 is - 1) |
Single-precision floating-point number | float | Occupies 4 bytes (32-bit) | Absolute value: 1.4e-45 ~ 3.4e + 38 |
Double-precision floating-point number | double | It occupies 8 bytes (i.e., 64) | Absolute value: 4.9e-324 ~ 1.8e + 308 |
Character | char | 2 bytes (i.e., 16) | 0 to 65,535 (i.e., 0 to 2 16 -1) |
Boolean | boolean | Occupies 1 byte (i.e. 8 bits) | true and false |
Third, the basic concept
-
Keywords : also known as reserved words, for example: byte, char, break, for , this, super, final, class, extends , and so on.
-
Identifier : Java package name, class name, an interface name, method name, object name, constant names, variable names, etc. are collectively referred to as an identifier.
-
Operators :
arithmetic operators: +, - , /,%
increment decrement operators: +, - -
relational operators:>,> =, <=, ==,! =
Logical operators:! , &&, ||
bitwise operators: ~, &, |, ^
shift operator: <<, >>, >>>
assignment operator: =, + =, - =, =, / =,% = | = ,! =, << =, >> =
conditional operator: ?:, Ternary operator.
(Ps: note operator precedence) -
Java program structure, there are three basic types : sequential structure, selection structure, cyclic structure.
Order structure: that is, the program statements written order from top to bottom, executed one by one.
Select structure: also known as branch structure, such as if statements, switch statements.
Looping structures: For "statement is executed repeatedly" loop can be used to write. For example, for statement, while statement, do ... while statement. -
Array : is a reference type (i.e. type Object), an ordered set of data by a number composed of the same type, each of which is called a data element.
Array initialization: at the same time declare the array, the array elements and then allocate space assigned. E.g:
int a[] = {1 , 2 , 3};//直接给每个元素(成员)赋值
int b[] = new int [3];//创建了长度为3的数组对象,每个元素取默认值,例如int类型为0
b[0] = 1;b[1] = 2;b[2] = 3;//给b数组的每个元素赋值
- An array of objects : an object is an array of array elements.
E.g:
public class Teacher{
public static void main(String[] args) {
Student[] student = new Student[2];//实例化对象
student[0] = new Student(1,"张三");//给数组元素赋值
student[1] = new Student(2,"李四");
//遍历数组访问元素
for(int i = 0;i < student.length;i++){
System.out.println(student[i].id+" "+student[i].name);
}
}
}
class Student{
int id;
String name;
//有参构造方法
public Student(int id,String name){
this.id = id;
this.name = name;
}
}