JVM in short

What is the JVM? Java programs need the JVM to run. Like .NET Framework. Stands for Java Virtual Machine. Java can run on multiple platforms because JVMs are implemented for different systems. So, Java programs can run on any platform that has a JVM (Though JVM may be different). It executes bytecode, which is translated from Java code. Oh, and Kotlin code can also be compiled into bytecode. What are JRE, JDK, and JAR? JRE (Java Runtime Environment) – It’s what Java needs to run, includes the JVM. JDK (Java Development Kit) – The toolkit for Java developers (You need it to do developing things), and it includes the JRE. It also contains the javac compiler, which turns your code into bytecode. JAR (Java ARchive) – A zip file specifically for Java programs. If everything’s set up correctly, you can run it directly. What is the JVM made of? Class Loader Subsystem – Finds your classes. Runtime Data Area – Contains the native method stack, Java method stack, method area, PC Registers, and heap. Native Method Stack – For calling code in other languages (mainly C++). Java Method Stack – For storing Java function call stacks. PC Registers – Tells the interpreter where to go next. Fact: It’s the only area that won’t throw an OutOfMemoryError. Method Area – Holds class-related info. It’s shared between threads. Heap – Just the heap, shared between threads. Anything not explicitly mentioned is thread-private. Execution Engine – Interpreter, JIT (Just-In-Time compiler), and GC (Garbage Collector). Native Method Library. Class Loader Subsystem? MyClass.java -> Loading (find the class) -> Linking -> Verify, Prepare, Resolve -> Initialization. Verify – Did you write your class correctly? Prepare – Allocates memory for static variables and sets them to default. Resolve – Turns symbolic references (names) into direct references (addresses). Loading: Class Loaders Everything’s an object in Java, even the classes themselves are loaded by class loader objects. ...

2026-09-10

Simple Tree Traversal

🖋️ Leaf-Similar Trees (Leetcode 872) In short, we are gonna to compare the leaves between two tree. First, we should get the elements from the leaves. # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def dfs(self, root, list_para): temp = [] curr = root while curr is not None or len(temp) > 0: while curr: temp.append(curr) curr = curr.left // Save all elements on the left side, but // we only want the leaf element, so... curr = temp.pop() if curr.left is None and curr.right is None: list_para.append(curr.val) curr = curr.right // Attention here, we 'move' our 'pointer' to the right side // After we have done all the things we should do on the left side def leafSimilar(self, root1: Optional[TreeNode], root2: Optional[TreeNode]) -> bool: l1 = [] l2 = [] self.dfs(root1, l1) self.dfs(root2, l2) return l1 == l2 Recursion Method class Solution: def dfs(self, root, list_para): if root is None: return if root.left is None and root.right is None: list_para.append(root.val) // **Move** to the left, do it again, **until 'root is None'** self.dfs(root.left, list_para) // Left side finished // **Move** to the right, do it again, **until 'root is None'** self.dfs(root.right, list_para) // Right side finished, all required data is saved in the list_para def leafSimilar(self, root1: Optional[TreeNode], root2: Optional[TreeNode]) -> bool: l1 = [] l2 = [] self.dfs(root1, l1) self.dfs(root2, l2) return l1 == l2

2026-09-10

Two Ways to Reverse a Singly Linked List

0. Structure of a Singly Linked List class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next // 1 -> 2 -> 3 -> 4 -> 5 -> NULL 1. Move pointers def reverseList(head: ListNode) -> ListNode: prev = None curr = head while curr: temp = curr.next # Save next node curr.next = prev # Reverse the pointer prev = curr # Move prev forward curr = temp # Move curr forward return prev # New head of the reversed list 0: 1 -> None 2 -> 3 -> 4 -> 5 -> NULL 1: 2 -> 1 -> None 3 -> 4 -> 5 -> NULL ...

2026-09-10

Rust Notes 4

Range Rather than using C style loop, in Rust, we use ..= to indicate a range: for i in 1..=5 { println!("{}",i); } Output: 1 2 3 4 5 Sequences are only allowed for numeric or character types because they can be consecutive. for i in 'a'..='z' { println!("{}",i); } Char Use '' . "" is for the string fn main() { let c = 'z'; let z = 'ℤ'; let cat= '😻'; } Accept Unicode, occupy 4 bytes. ...

2026-09-10

Lagrange Interpolation Method

🖋️ Starting from known points Given the task of constructing a function f(x) f(x) f(x)that passes through the points P1(x1,y1),P2(x2,y2),⋯ ,Pn(xn,yn) P_1(x_1, y_1), P_2(x_2, y_2), \cdots, P_n(x_n, y_n) P1​(x1​,y1​),P2​(x2​,y2​),⋯,Pn​(xn​,yn​), first let the projection of the i th point onto the x axis be ...

2026-09-10

Leetcode reflection (1)

1732. Find the Highest Altitude There is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes. The biker starts his trip on point 0 with altitude equal 0. You are given an integer array gain of length n where gain[i] is the net gain in altitude between points i and i + 1 for all (0 <= i < n). Return the highest altitude of a point. ...

2026-09-10

Rust Notes 3

🔔 Prelude: In the end, all data types in Rust come from these primitive types. Basic types Every value in Rust has a specific data type In general, these can be divided into two categories: scalar types and compound types Scalar types include: Numbers: Signed integers (i8, i16, i32, i64, isize), unsigned integers (u8, u16, u32, u64, usize), floating-point numbers (f32, f64) The isize and usize types depend on the architecture of the computer the program is running on: if the CPU is 32-bit, these types are 32-bit; similarly, if the CPU is 64-bit, they are Rust’s default integer type is i32 Can overflow, and Rust does not check for this by default. If you encounter incorrect values, make sure to check the type of your numbers. Strings: String literals and string slices Booleans: true and false Characters: Representing a single Unicode character, stored as 4 bytes Unit type: Represented by (), with its only value also being () Be Careful with floats See this example: ...

2026-09-10

Rust Notes 2

Syntax of Rust Don’t worry, this will be very easy at the beginning. (Really?) Function goes first Similar to C and C++, there must be a main function as the entry point of the program. Use fn to declare a function, so concise. Use () for receiving parameters, and {} for the actual logic inside the function. Remember to use ; to end a statement. As I said, it’s similar to C and C++. Example: fn main() -> { println!("Hello, world!"); // "ln" means print with a new line after the content // What is "!"? Well, it means this function is actually a macro // For now, let's just use it as is // You don't need to learn everything to start using Rust. Heart. } A complete structure of function head in Rust should be: ...

2026-09-10

Rust Notes 1

About these notes These Rust notes are just a collection of my learning records. Since I’m a beginner in Rust, these notes are more like quick references or supplements, rather than a comprehensive Rust tutorial. No matter what, I hope you can still find parts that are useful to you. Why rust? Rust’s advantages include memory safety, high performance, and high productivity. To me, Rust appears to be one of the best implementations of C++. If you don’t get into deeper topics and only use prepared libraries, Rust’s syntax is simple and clear. Its built-in compiler cautions are also quite informative, which significantly decreases the amount of thinking required on developers. ...

2026-09-10

Window Functions in SQL

🔔 Prelude: Boss: “I need the average sales for 7 days.” Me: “Sure! Which 7 days?” Boss: “All the 7 days!” Me: “Su…Sure…?” 🖋️ Window Functions Window functions are generally applied after aggregate functions like MAX(), MIN(), AVG() to perform calculations across a set of table rows(days before, days after) that are related to the current row(current day). Example Table 1: employees employee_id department_id salary 1 101 5000 2 101 6000 3 101 5500 4 102 7000 5 102 7200 6 102 6800 Example 1: OVER() Without Partitioning Calculate the average salary for all employees: ...

2026-09-10