coding笔记(Computer works)
—————————————
安装arch linux
确定国家
确保有网络连接(无线或者网线)
dmesg | grep iwlwifi
开启wifi
ip link set interface(or wlan0) up
连接wifi
iwctl(打开iwctl : The wireless client)
device list(寻找硬件)
station wlan0 get-networks(寻找网络)
station wlan0 connect (网络名)
输入密码
确定是否连接上网络
ping -c 3 google.com (ping 谷歌)
station wlan0 show (再次确认)
enable Network Time Protocols (NTP)
timedatectl set-ntp true
check the NTP service status
timedatectl status
寻找安装硬件
fdisk -l
格式化硬件
cfdisk /dev/sd?
需要以下3个分区(gpt):efi, linux swap, linux filesystem
大小:300mb, 1gb, 随意
pacman安装所有需要的命令
gdisk /dev/sd? (format disk)
需要以下3个分区:efi(ef00), bios boots(ef02), linux
250M, 10M, 随意
格式化efi: mkfs.fat -F32 /dev/sd?
加密 linux filesystem (可选项)
cryptsetup (加密算法)/dev/sd?
有用的链接:https://phoenixnap.com/kb/arch-linux-install
https://wiki.archlinux.org/title/Network_configuration/Wireless
https://www.linuxandubuntu.com/home/how-to-setup-a-wifi-in-arch-linux-using-terminal
https://www.howtoforge.com/tutorial/linux-grep-command/
https://www.debugpoint.com/2020/11/connect-wifi-terminal-linux/
https://www.tecmint.com/arch-linux-installation-and-configuration-guide/
https://ostechnix.com/retrieve-latest-mirror-list-using-reflector-arch-linux/
https://stackoverflow.com/questions/26130427/arch-linux-sudo-command-not-found
https://wiki.archlinux.org/title/locale
https://unix.stackexchange.com/questions/659713/dhcpcd-service-does-not-exist
https://unix.stackexchange.com/questions/405472/cannot-find-efi-directory-issue-with-grub-install
https://linuxhint.com/arch_linux_network_manager/
—————————————
如何在复制directory 下的所有文件?
rsync -av ~/directly ~/directly
—————————————
如何找到.ext 的文件中包含"abc"的内容并删除该文件
—————————————
grep -rw '路径(或者.)' -e 'abc'| cut -d ":" -f 1 > 文件名.txt
rm -f $(cat 文件名.txt)
—————————————
如何找到.ext 的文件并把它复制到某个文件夹
—————————————
find . -name "*.ext" > list.txt
cat list.txt | awk 'BEGIN {a="'"'"'"}{print "cp "a$0a" Directory"}' > script.sh
sh script.sh
—————————————
how to install specific dependency that is needed and it's hard to find online (as .jar file is needed)
choose to use mvn and use the pom.xml to install such dependency.
add following statements in the pom.xml file (use mysql connector as e.g.)
project
.....
"dependencies"
!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --
dependency
groupIdmysql/groupId
artifactIdmysql-connector-java/artifactId
version8.0.26/version
/dependency
/dependencies
.....
/project
—————————————
coding笔记(coding knowledges)
—————————————
Serializable
—————————————
The ability an object being transfer into another form and back.
what if I don't want to make it serialized? use the keyword "transient"
usually given as "null" or "0" if it's an primitive type
compile time (checked) / runtime (unchecked) exceptions
—————————————
About sql
—————————————
rename a column in sql: use "as" keyword.
left join: everything on the left table but right table.
right join: everything on the right table but left table.
inner join: everything that those 2 table have common
natrual join: same as join but remove the repeating part of matching elements
—————————————
union and union all and full outer join
—————————————
union: eliminate duplicate
union all: does not elimaniate duplicate
full outer join: does not elimaniate duplicate
—————————————
except: first statement minus values in second statement
—————————————
symbols behind like:
%: same as *(wild card)
_: use as placeholder
—————————————
(Subquery?)outter query iterate over the result of inner query.
—————————————
"in" statement: same as multiple where statements (e.g.SELECT * FROM Customers
WHERE Country IN ('Germany', 'France', 'UK'))
"exist" statement: return true as it find one or many condition to be true (then it usually being used with select. so it's going to return any row that has "exist" return true on it.)
we can use () to represent an way we group another table.
—————————————
aggregate functions: can be used without group by
Cannot it be used with having but not group by
self-join: unary relationship
—————————————
Cross join return table that is a cross product from two tables. where it's different from other joins as the table is a product of the 2 tables, it's row number is the multiplication of the rows of those 2 tables. we might need to use it when we want to populate a new table. e.g. when we want to combine 2 different elements of clothes, color and style, we could cross join the table. And we can also use it when we want to create a new hairstyle by combining different ways of cutting at the front and back.
—————————————
sub-query: query that is nested inside a SELECT , INSERT , UPDATE , or DELETE statement.
different types of subqueries:
Single Row Subquery:
return 1 row or none.
Multiple Row Subquery:
Returns one or more rows
Multiple Column Subqueries:
Returns one or more columns
Correlated Subqueries:
Returns one or more columns according to the outer query
Nested Subqueries:
Queries within queries
—————————————
views: a result set sotred in data (virtual table)
different from table: table is prelimary storage, it's virtual table. (contents defined by query)
modify data on view &will update the data on table
—————————————
indexes: special lookup tables that database search engine can use to speed up data retrieval. (pointer of to the data) (needed to sort and optimized data)
we don't want to create as much as possible, we only create indexes as we need to sort data. We also need more time to maintain those indexes, more index doesn't mean it's going to make it perform better. insert the data.
—————————————
no clustered index: only the references are stored in tree (as many as you want)
clustered index: a dynamic(balanced) tree is created when we create a clustered index. data is moved to the tree. primary key as tree leafs.(only have 1)
—————————————
jdbc
—————————————
CallableStatement: calling an stored procedure and function in database. (define countries name and find out how many city within in that country.)
—————————————
transaction: single unit of work
Transaction Management: ACID
A: (Atomicity) either successful or none
C: (Consistency) make database from 1 consistent state to another consistent state.
I: (Isolation) ensures all transactions are isolated from other transactions.
D: (Durability) once transactions are committed. it will remain in events of errors etc.
—————————————
JDBC DriverManager: software component that enables java application to interact with the database.
—————————————
execute, executeQuery, executeUpdate
execute: execute queries and return true if execute is successful.
executeQuery: execute queries that return single result set object.
executeUpdate: execute DDL and DML statements like insert, update, delete and create.
—————————————
JDBC statements: send to database and prepared for execution, only the values need to be sent.
—————————————
JDBC API: |Driver manager: control JDBC driver|
JDBC-ODBC Bridge: provide JDBC access through ODBC driver
Vendor Specific JDBC Driver: 2 groups driver connect a client directly to DBMS.
Vendor specific ODBC Driver: mediating layer between jdbc driver and vendor client libraries.
—————————————
connect to db:
import the JDBC driver
create connection with connection object
create statements
execute queries with the prepared statements
Iterate throught the result and close the connection
—————————————
data modeling
—————————————
data modeling: visual representation of the relationship between datas. need it before the construction of the database
—————————————
entity: objects or concept that is described in the database
attribute: property of the entity
domain: a set of atomic values (atomic: value is indivisible to each other
—————————————
Superkey: an attribute or attributes that uniquely identify each entity in a table.
candidate key: a primary key to identify an tuple or a row in database, not necessary that it's a superkey as superkey can be made of many candidate keys.
—————————————
Primary Key: an identifier compose of one or emore atributes that uniquely identify a row.
Primary key: made of many unique Key
—————————————
relationships in data modeling:
1:1|1:M|M:N
—————————————
Cardinality: a property assigned to an attributes that connect to another entity in database
—————————————
composite attributes: attached to an entity that is in 1:m relationship, 1 entity can have many attributes likes that. (An attributes that is composed of more than 1 attributes.)
—————————————
multi-valued attributes: an attribute that can have many value (e.g. color or the car, 1 car can have many color)
—————————————
Drived attribute: an attribute whose value is calculated from other attributes
—————————————
Normalization: process for evaluating and correcting table structures to minimize data redundancies and reduce data anomalilies (data anomalilies: inconsistent changes have made in database [e.g. address changles not shown in all files in database]). You will need to normalize when there is m:n relationship.
—————————————
Data redundancy: data is being stored repeatedly in different location in the database. (Data redundancy could be caused by e.g. student name being stored in the class table which student table has their own list of students id and names.)
Duplication: a data existed in other row of the table but stored repreatly in the other related table. which it's not necessary.
—————————————
partial dependency: exist when there is functional dependence where determinant is only part of the primary key. (e.g. (A, B) → (C, D), B → C, which primary key is (A, B) then functional dependence is B → C as B is part of the primary key that is needed to determine the value of C)
transitive dependency: exist when there is a determinant is working as part of the transitive function from one table to another table. (e.g.B → C, A → B, which A is primary key. then transitive dependency is: A → C )
complete dependency:
—————————————
normal form: result of Normalization, a process of process for evaluating and correcting table structures to minimize data redundancies.
3 normal form
1NF: no repeating groups, and PK identified
2NF:1NF and no partial dependencies
3NF:2NF and no transitive dependencies
—————————————
Database integrity is rules that require the database to have all primary key to be unique, all rows haveunique identity and foreight key can properly reference primary values. (Includes (Entity Integrity, Referential Integrity, Domain Integrity))
—————————————
User-defined integrity refer to user's ability to define each row with specific type of value e.g. it can't be null or something like those.
—————————————
relational database: database that stores and provides access to api that are related.
non-relational: database that does not use a storage model optimized for specific requirements of typeof data being stored.
—————————————
DDL: data definition language, used in DBA and by database designer to define both schemas.
Major DDL: Create, Alter, Drop.
—————————————
DML: data manipulation language, provides a set of operation for retrieval, insertion, deletion, and modifucation.
Major DML: Insert, Update, Delete, Merge.
—————————————
insert values into a table if you don't know the order of columns:
We can insert the values with Where condition for where condition is true to insert the value.
specify column name of the order.
—————————————
Truncate delete all rows or tuples from table. Delete is used to delete specific row. Truncate cannot be rolled backed.
—————————————
SQL: is not case sensitive
—————————————
Constrants: restriction placed on data. We need them to protect the date integrity. no, it's
not mandatory to have.
—————————————
use UNIQUE statements in the value that we do not want to have duplicate in it
—————————————
add constrains to a table:
—————————————
3 major way:
Create table then alter to add constrain, you don't have to alter any data after.
Add constraint as we specify the column in table, we need to check on the data and make sure all the data is comply with the rule that we set.
Add constraint in the same create statement after specified in the table.
—————————————
oop concepts
Encapsulation: the way the data is being hided in side the object and only accessable through the getter and setter (set it to private [only visible within the class.])
—————————————
conceptual things
—————————————
operator priority: (from high to low)
—————————————
postfix: exp++, exp--
unary: ++exp, --exp
multiplicative: * / %
additive: + -
shift: << or >> or >>>
relational: < or > or <= or >= or instanceof
equality: == !=
bitwise AND: &
bitwise exclusive OR: ^
bitwise inclusive OR: |
logical AND: &&
ternary: ? :
assignment: = += -= *= /= %= &= ^= |= <<= >>= >>>=
—————————————
java data types: (widening casting[automatically] small-> large)
byte -> short -> char -> int -> long -> float -> double
1 -> 2 -> 1 -> 4 -> 4 -> 4 -> 16
Primitive type: build in type in java: e.g. int, char
abstraction: a method that is required in inheritance that its sub class must implement
abstract class: a class with abstract method.
inheritance: a subclass which they inherite all the methods and property of the superclass
override: overwrite the methods in the parents class
polymorphism: ability to implements one method in many forms.
multiple inheritance: a sub_class extends 2 different classes. (which it's not possible in java [ambiguity or "diamond problems"])
a class extends object class by default in java
static keyword: (compile time [executed when loading a class][and only executed once])
static block executed "before" the constructor [can't access non static variable in static method/class]
static variable: variable that are not specific to object (the variable is shared with all the instance in the class --- class level only) [instance variable is stored in the heap] (belong to class and does not need reference [can be called without creating objects])
static methods: belong to a class [can be called without creating objects] (why we need it? to access/manipulate static variables/methods that don't depends on objects)
—————————————
Inner class within an class: how to call constructor:
use refferences from outer class. e.g. c1.c2 = c1(ref).new c2()
assume c2 is inner class of c1
—————————————
Strings
String is an OBJECT
String: charAt(_) _ accept range from 0 to String.length-1 [same as arrays]
String: Indexof(_) _ takes a char and find its location in Strings
what is restful api?
rest: representational state transfer
restful api: conforms to the constraints of REST architectural style and allows for interaction with RESTful web services
string vs string builder vs string buffer
—————————————
1) String is immutable (when content is fixed)(not thread safe)
—————————————
String buffer (synchronized)
1) String buffer is mutable (when content changes)
2) Thread safe
—————————————
String builder
1) String builder is mutable (when content changes)(more efficient)
2) Not thread safe
list vs set vs map
—————————————
list: allow duplicate
arraylist: used dynamic array, slow because it internally uses an array
linklist: used doubly linked list, no bit shifting is required in memory (no array), act as a list and queue
vector: similar to array list but it's synchronized (thread safe)
—————————————
set: not allow duplicate
hashset: not maintain insertion order
linkedhashset: maintain the insertion order
treeset:sort the elements by comparactor(assending order by default)
—————————————
map:
where key: (unique) value: may have duplicate
hashmap: key, value. allow 1 null key, multiple null value. (not thread safe)
hashtable: (thread safe) no null keys
—————————————
Queue(using linklist) vs Priority Queue
—————————————
Queue with linkedlist will keep its order
Queue with priorityqueue will have assending order
—————————————
comparable vs comparactor
comparable:(@override compareto) compare only 1 subject with calling subject by natural ordering
comparactor:(@override compare) compare 2 different subject in different class (can have multiple comparactor)
code suggestions for strings
substring: return substring of original string
indexof: can be inputed with "string"
SOLID principles
S: Single-responsibility (A class should only have a single responsibility)
O: Open-closed (Open for extension, but closed for modification)
L: Liskov substitution (replaceable with instances of their subtypes without altering the correctness of that program) (extend from same parent class)
I: Interface segregation (each class should take what they need from parent class and not have to use all of the methods in parent class)
D: Dependency inversion (depend upon abstractions, [not] concretions) (only depend on abstract methods)
trees trevasal
In_order[DFS](bottom left, middle, bottom right): D→B→E→A→C→F
Pre_order[DFS](middle, bottom left, bottom right): A→B→D→E→C→F
Post_order[DFS](bottom left, right, middle): D→E→B→F→C→A