timerring

07 Classes and Interfaces

January 9, 2024 · 3 min read
Tutorial
Java

7.1 Classes and Objects #

A class defines an entirely new data type containing a group of variables and functions; an object is an instance of that class.

Defining Student as a class represents the abstract concept of a “student.” Each student is then an object (instance) of the Student class.

...


06 Functions

January 8, 2024 · 5 min read
Tutorial
Java

Function Basics #

A typical function definition includes the following parts: modifiers, return type, function name, a list of zero or more parameters, and the function body.

...


05 Strings

January 7, 2024 · 3 min read
Tutorial
Java

1. Characters and Integers — ASCII Codes #

Each commonly used character corresponds to a number in -128 ~ 127, and the two can be converted to each other. Note: currently, negative numbers have no corresponding characters.

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        char c = 'a';
        System.out.println((int)c);

        int a = 66;
        System.out.println((char)a);
    }
}

Common ASCII values: 'A'- 'Z' are 65 ~ 90, 'a' - 'z' are 97 - 122, and 0 - 9 are 48 - 57.

In Java, character literals must be enclosed in single quotes and string literals in double quotes. They are distinct. (Python and JS do not make this distinction.)

Characters can participate in arithmetic; they are treated as integers during operations:

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        int a = 'B' - 'A';
        int b = 'A' * 'B';
        char c = 'A' + 2;

        System.out.println(a); // 1
        System.out.println(b);
        System.out.println(c);
    }
}
...


04 Arrays

January 6, 2024 · 4 min read
Tutorial
Java

One-Dimensional Arrays #

Defining Arrays #

Array definitions are similar to variable definitions.

public class Main {
    public static void main(String[] args) {
	    int[] a;// Definition: define an array a
		a = new int[10]; // Initialization: initialize a as an array of length 10, meaning a contains 10 int variables; equivalent to =>int[] a = new int[10]// Define and initialize at the same time
        int[] a = new int[10], b;
        float[] f = new float[33];
        double[] d = new double[123];
        char[] c = new char[21];
        // Arrays can be defined for more than just primitive data types; String arrays can also be defined
        String[] strs = new String[10];// This array contains 10 String variables
    }
}
...


03 Loops

January 5, 2024 · 1 min read
Tutorial
Java

Use == to compare primitive data types for equality; for other types (such as strings and functions), use equals to compare them.

...


02 Conditional Statements

January 4, 2024 · 2 min read
Tutorial
Java

If Statements #

if-else statements can also contain other if-else statements.

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();

        if (a > b) {
            if (a > c)
                System.out.println(a);
            else
                System.out.println(c);
        } else {
            if (b > c)
                System.out.println(b);
            else
                System.out.println(c);
        }
    }
}

Chained if-else statements

Enter a score between 0 and 100.
If it is at least 85, output A;
if it is at least 70 but less than 85, output B;
if it is at least 60 but less than 70, output C;
if it is less than 60, output D.

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();

        if (s >= 85) {
            System.out.println("A");
        } else if (s >= 70) {
            System.out.println("B");
        } else if (s >= 60) {
            System.out.println("C");
        } else {
            System.out.println("D");
        }
    }
}
...


01 Variables, Operators, Expressions, Input and Output

January 3, 2024 · 3 min read
Tutorial
Java

Syntax Basics #

Variables #

  1. In Java, outputting a variable without assigning it a value causes an error.
  2. Built-in data types
TypeBytesExampleAdditional notes
byte1123
short212345$2^{16}=65536$
int4123456789$2^{32}=2147483648≈2.1*10^9$
long81234567891011L$2^{64}≈10^{18}$
float41.2FAbout 6 or 7 significant decimal digits; subsequent digits are imprecise approximations. To explicitly denote a float, append f or F.
double81.2, 1.2DAbout 15 or 16 significant decimal digits; subsequent digits are imprecise approximations. To explicitly denote a double, append d or D.
boolean1true, false
char2‘A’ASCII code correspondences: a-97 A-65 0-48
...


Density Plotting

August 31, 2023 · 13 min read
Tutorial
Python

Seaborn’s kdeplot() function is one way to draw density plots in Python. At present, Matplotlib does not have a specific function for drawing density plots, and plotting is generally performed in combination with the result of the gaussian_kde() function in the Scipy library.

The neighbors.KernelDensity () module in Python’s scikit-learn library provides six kernel functions—Gaussian, Tophat, Epanechnikov, Exponential, Linear, and Cosine—for kernel density estimation calculations. Python’s KDEpy library provides as many as nine kernel functions, including Gaussian, Exponential, Box, Tri, Epa, Biweight, Triweight, Tricube, Cosine.

A schematic diagram of the nine kernel functions in the KDEpy library is shown below:

...


Types of Univariate Plots for Continuous Variables

August 29, 2023 · 8 min read
Tutorial
Python

A univariate plot (chart for one variable) refers to drawing a corresponding plot using one variable from a dataset. To visualize this variable, a plot must be drawn according to the different data variable types. Data variables are divided into continuous variables and discrete variables.

...


Message Queues and Kafka Basics

August 27, 2023 · 7 min read
Tutorial
Message Queue | Kafka

走进消息队列 #

面对存储行为服务崩溃的时候,可以采用解耦的方式,将记录加入消息队列中,然后作为生产者,此时存储服务作为一个消费者来消耗。

面对多个请求同时进行时,可以采用削峰的方式解决,将订单也加入消息队列中,然后每次只处理 10 个请求。

把发起订单的请求放入消息队列中,这时就可以通知客户下单成功了,然后将下面的三个请求异步地执行即可。

将日志放入消息队列中,然后通过日志的相关组件例如 ES 引擎等等,Kibana 展示平台进行分析。

...