Java study and review. This article mainly references Java Core Technologies Volume as the object of study.
Chapter 1: Java Overview
Java White Paper
Simplicity, Object-oriented, Distributed, Robust, Secure, Architecture-neutral, Portable, Interpreted, High performance, Multithreading, Dynamism
- Java applet
A Java program that runs in a web page: applet
- JavaScript and Java
Apart from the name, the two are not related. Java is strongly typed and catches errors more effectively than JavaScript
Chapter 2: Java Environment
- Java Terminology
| Term | Abbreviation | Explanation |
|---|---|---|
| Java Development Kit (JDK) | JDK | Software used by programmers to write Java programs |
| Java Runtime Environment (JRE) | JRE | Software used by users to run Java programs |
| Server JRE (Server Runtime) | Software for running Java programs on a server | |
| Standard Edition (SE) | SE | Java platform for desktop or simple server applications |
| Enterprise Edition (EE) | EE | Java platform for complex server applications |
| Micro Edition (ME) | ME | Java platform for small devices |
| Java FX | An alternative toolkit for graphical user interfaces, provided in some Java SE releases prior to Java 11 | |
| OpenJDK | A free open-source implementation of Java SE | |
| Java2 | J2 | An obsolete term used to describe Java versions between 1998 and 2006 |
| Software Development Kit (SDK) | SDK | An obsolete term used to describe the JDK between 1998 and 2006 |
| Update | u | Oracle’s term, indicating bug-fix releases prior to Java 8 |
| NetBeans | Oracle’s integrated development environment |
- Java Installation & Compilation
# 配置环境变量javac --version # 查看java版本
# 命令行编译javac welcome.javajava welcome- Integrated Development Environments
Eclipse | IntelliJ IDEA | NetBeans
- JShell
JShell: Java’s interactive shell
Chapter 3: Java Basic Programs
- CamelCase Naming
myClass
- Comments
//注释/*注释*//** *自动生成文档 *注释 */1 Data Types
- Integers
| int | 4 bytes | -2^32 ~ 2^32 - 1 |
|---|---|---|
| short | 2 bytes | -2^16 ~ 2^16 - 1 |
| long | 8 bytes | -2^64 ~ 2^64 - 1 |
| byte | 1 byte | -2^8 ~ 2^8 - 1 |
1L/1l Long integer
0x Hexadecimal 0 Octal 0b/0B Binary
- Floating-point
| float | 4 bytes | Approximately ±3.40282347E+38F 6~7 digits |
|---|---|---|
| double | 8 bytes | Approximately ±1.79769313486231570E+308 15 digits |
float 1f/1F
double 1D/1d
NaN <= 0/0 || sqrt(-n)

- char type
\\b 退格 \\t 制表 \\n 换行 \\r 回车 \\" 双引号 \\' 单引号 \\\\ 反斜杠- Unicode
16-bit: early era
Code point U+ 16-bit
Planes 2–17 (including supplementary characters U+10000 ~ U+10FFF)
- boolean type
Boolean type false || true Logical evaluation
2 Variables
- Initialization
After defining, you must explicitly initialize before you can use it
final constants enum types
3 Operators
+ - * / %
- Math
sqrt pow floorMod
Trigonometric functions sin cos tan atan atan2
Logarithms exp log log10
Pi and e approximations Math.PI Math.E
You can import static java.lang.Math.* to use them directly
- Type conversion
Low precision -> high precision is lossless
High precision -> low precision incurs loss - explicit casting (int) | …
+= *= %= ...k++ ++k== != > < >= <=&& ||x?a:b //(true:false)& | ^ ~ >> <<Operator precedence

4 Strings
"...".substring(l,r) //[l,r)"a"+"b""a".repeat(3) //ans = "aaa"Strings are immutable
equalsand==
== checks whether strings are in the same location, and can only reliably compare shared literals; for non-shared concatenations or substring there can be errors
Use a.equals(b) or a.compareTo(b) for comparing strings
- Empty strings and null strings
"" null
- Code points and code units
int index = a.offsetByCodePoints(0,i); //position of ith code pointint cp = a.codePointAt(index); //get the ith code point//UTF-16 surrogate pairs require two code units; cannot use charAt(pos)- Building strings
StringBuilder builder = new StringBuilder(); //String builderbuilder.append('a');builder.append(b);String res = builder.toString(); //generate string5 Input/Output
- Input
Scanner in = new Scanner(System.in);in.nextLine(); //read a linein.next(); //read with space delimiterin.nextInt(); //read intin.nextDouble(); //read Doublein.hasNext(); //check if there is more input- Output
System.out.println();System.out.printf(“%8.2f",x); //similar to printf in C// d decimal x hexadecimal o octal f fixed-point e exponential// s string c character b boolean h hash code- File Input/Output
Scanner in = new Scanner(Path.of(""),StandardCharsets.UTF_8);PrintWriter out = new PrintWriter("",StandardCharsets.UTF_8);6 Control Flow
// 块作用域{}
// 条件语句if(){
}else if(){
}else {}
// 循环while(...){} // Evaluate condition first, then executedo ... while(...); // Execute first, then evaluate
for(int i = ..;i <= .. ; i++) {}
switch (...){ case ...://Label can be char byte short int enum constants string literals ... break; ... default: ... break;//Will stop only when break is encountered}
//break continue goto//break tag; Similar to goto jumping to tag:- Large numbers
BigInteger BigDecimal
Use valueOf(x) to convert x
7 Arrays
//数组定义int[] a = new int[len];int[] b = {1,2,3,4};new Type[0] || new Type[] {} //Length-0 arrays, different from null
//for each loopfor(int i:a) ... //process array or other element collections
//- Array copyinga = b;a = Array.copyOf(b,copyLen);
//Array sortingArrays.sort(a); //Quicksort Math.random() -> [0,1)
//Multidimensional arraysint[][] a = new int[lenA][lenB];a = { {...}, {...}};for(int[] i:a) for(int j:i) ...
//Jagged arraysint[][] a = new int[N][]; //Array of N referencesa = {...};If this article helped you, please share it with others!
Some information may be outdated





