Computer Science Learn Notes

website·Indexed 29 days ago

https://zhiyu1998.github.io/Computer-Science-Learn-Notes/

A comprehensive collection of study notes covering computer science fundamentals, including data structures, design patterns, and extensive JVM internals (memory areas, class loading, and garbage collection). It also features guides on Java frameworks like Spring, Spring Boot, Spring Cloud, and Spring Security, as well as notes on Golang, Kotlin, Node.js, and Vue 2/3.

Tokens
226.6K
Snippets
664
Records
1.3K
Agent score
70%

What's inside Computer Science Learn Notes

  1. Overview of G1 Garbage Collection cycles

    G1 follows a cyclical recovery process: Young GC $\rightarrow$ Concurrent Marking $\rightarrow$ Mixed GC.

    • Young GC: Occurs when Eden is full. STW, parallel collection of Young regions.
    • Concurrent Marking: Triggered when heap usage hits a threshold (default 45%). Identifies live objects in the Old generation.
    • Mixed GC: Follows concurrent marking. Collects Young regions and a subset of Old regions (based on the efficiency calculated during marking). Unlike other collectors, G1 does not need to collect the entire Old generation at once.
    • Full GC: A single-threaded, exclusive, high-intensity fallback mechanism used when G1's evaluation fails or when contiguous Humongous regions cannot be found.
  2. Overview of Behavioral Design Patterns

    Behavioral patterns are concerned with algorithms and the assignment of responsibilities between objects.

    • Template Method: Defines the skeleton of an algorithm in a base class, deferring specific steps to subclasses.
    • Iterator: Provides a way to access elements of a collection sequentially without exposing the underlying representation.
    • Chain of Responsibility: Passes a request along a chain of handlers. Each handler decides either to process the request or to pass it to the next handler in the chain.
    • Strategy: Defines a family of algorithms, encapsulates each one, and makes them interchangeable at runtime to adapt to different scenarios.
  3. Introduction to Java Virtual Threads (Java 19+)

    Introduced in Java 19, Virtual Threads (also known as fibers) are lightweight threads managed by the Java runtime rather than the operating system. They significantly reduce the overhead of thread creation and context switching, allowing developers to create a massive number of threads to improve concurrency without exhausting system resources.
    import java.util.concurrent.*;
    
    public class FiberExample {
        public static void main(String[] args) throws Exception {
            // Example of using a single thread executor to run a task
            // Note: In Java 19+, specific Virtual Thread APIs like Executors.newVirtualThreadPerTaskExecutor() are typically used
            ExecutorService executor = Executors.newSingleThreadExecutor();
            executor.submit(() -> {
                System.out.println("Hello from fiber!");
            }).get();
            executor.shutdown();
            executor.awaitTermination(1, TimeUnit.SECONDS);
        }
    }
  4. Overview of common Java Collection containers

    Java provides several container implementations categorized by the List, Set, and Map interfaces:

    List (Ordered, allows duplicates)

    • ArrayList: Dynamic array. Fast random access, slow insertion/deletion.
    • LinkedList: Doubly-linked list. Fast insertion/deletion, slow random access.
    • Vector/Stack: Legacy thread-safe implementations.

    Set (Unique elements, generally unordered)

    • HashSet: Backed by HashMap. No guaranteed order, not thread-safe.
    • LinkedHashSet: Maintains insertion order using a doubly-linked list.
    • TreeSet: Backed by TreeMap. Elements are sorted according to a comparator.

    Map (Key-Value pairs, unique keys)

    • HashMap: Array + Linked List (JDK 1.8+ converts lists to Red-Black Trees when length > 8). Not thread-safe.
    • LinkedHashMap: Extends HashMap; maintains insertion or access order.
    • TreeMap: Red-Black Tree implementation; keys are sorted.
    • ConcurrentHashMap: Thread-safe implementation using CAS and synchronized blocks (JDK 1.8+).
  5. Overview of G1 (Garbage-First) Collector

    G1 is a server-side garbage collector designed for multi-core CPUs and large memory capacities. It is the default collector from JDK 9 onwards, replacing CMS and Parallel combinations. Unlike traditional collectors, G1 divides the heap into independent, non-contiguous Regions. It tracks the 'value' (amount of garbage vs. time to reclaim) of each region and prioritizes collecting regions with the most garbage first to maximize efficiency within a specified pause time target.
  6. Overview of Structural Design Patterns

    Structural patterns explain how to assemble objects and classes into larger structures.

    • Facade: Provides a unified, high-level interface to a set of interfaces in a subsystem, making a complex subsystem easier to use.
    • Composite: Allows clients to treat individual objects and compositions of objects uniformly, typically used for tree-like structures.
    • Decorator: Dynamically adds extra functionality to an object at runtime by wrapping it, providing a flexible alternative to static inheritance.
    • Adapter: Acts as a converter between two incompatible interfaces, allowing them to work together.
    • Flyweight: Reduces memory usage by sharing a common object (the flyweight) among many contexts that share the same internal state.
    • Proxy: Provides a surrogate or placeholder for another object to control access to it.
    • Bridge: Decouples an abstraction from its implementation so that the two can vary independently.
  7. Overview of the OS Network Protocol Stack

    The network protocol stack handles data transmission through a layered delegation model where upper layers delegate tasks to lower layers:

    • Application Layer: Applications (like browsers) use Socket libraries to delegate work to the transport layer.
    • Transport Layer: TCP and UDP handle the sending and receiving of data.
    • Network Layer (IP): Responsible for splitting data into network packets and routing them. It includes:
      • ICMP: Reports errors and control information during packet transmission.
      • ARP: Resolves IP addresses to Ethernet MAC addresses.
    • Network Interface Layer: Consists of the network card driver and the physical network card hardware that handles actual electrical/optical signals.
  8. Overview of the JVM Execution Engine

    The Execution Engine is a core component of the JVM responsible for translating Java bytecode into native machine instructions that the host operating system can execute. It consists of three primary components: the Interpreter, the JIT (Just-In-Time) Compiler, and the Garbage Collector. Unlike a physical machine's execution engine, which is built on hardware (CPU, cache, instruction sets), the JVM execution engine is software-implemented, allowing it to define its own instruction set independent of the underlying hardware.
  9. Overview of Spring Data JPA

    Spring Data JPA is part of the Spring Data family and provides enhanced support for JPA-based data access layers. Its primary goal is to simplify the implementation of repositories, allowing developers to perform CRUD operations and pagination by defining interfaces rather than writing boilerplate implementation code. Key features include support for Querydsl type-safe queries, transparent domain class auditing, dynamic query execution, and JavaConfig-based repository configuration via @EnableJpaRepositories.
  10. Overview of Modern Java Garbage Collectors

    Java GC has evolved to support various application needs, from serverless environments to large-heap, low-latency services:

    • G1 GC: The current default collector. Recent versions (JDK 10+) have improved Full GC performance by making it parallel, often outperforming Parallel GC's Full GC implementation.
    • Serial GC: While old, its low overhead makes it suitable for new application scenarios like Serverless.
    • CMS GC: Deprecated in JDK 9 and removed in JDK 14 due to theoretical algorithmic flaws.
    • Epsilon: A 'No-Op' garbage collector that handles memory allocation but does not reclaim it.
    • ZGC & Shenandoah: Modern collectors designed specifically for ultra-low pause times regardless of heap size.
  11. Overview of Apache Dubbo RPC Framework

    Apache Dubbo is a high-performance, lightweight open-source Java RPC framework. It provides six core capabilities: high-performance RPC calls via interface proxies, intelligent fault tolerance and load balancing, automatic service registration and discovery, high extensibility, runtime traffic scheduling, and visual service governance and operations.
  12. Overview of Creational Design Patterns

    Creational patterns focus on object creation mechanisms.

    • Abstract Factory: An abstraction of factories that provides a top-level specification for creating families of related products, preventing a proliferation of individual factory classes.
    • Builder: Used for constructing complex objects step-by-step. It separates the construction process from the representation, allowing the same construction process to create different representations.