Skip to content

Commit 2712f3a

Browse files
authored
Merge pull request #13 from CyC2018/master
merge
2 parents 9b25ef4 + 3c6be1a commit 2712f3a

14 files changed

+406
-162
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
<a href="other/Group.md"> <img src="https://img.shields.io/badge/>-group-4ab8a1.svg"></a> <a href="https://legacy.gitbook.com/book/cyc2018/interview-notebook/details"> <img src="https://img.shields.io/badge/_-gitbook-4ab8a1.svg"></a>
1010
</div>
1111

12-
<!-- [![](https://img.shields.io/badge/>-gitter-blue.svg)](https://gitter.im/CyC2018-Interview-Notebook/Lobby?utm_source=share-link&utm_medium=link&utm_campaign=share-link) [![](https://img.shields.io/badge/_-gitbook-4ab8a1.svg)](https://legacy.gitbook.com/book/cyc2018/interview-notebook/details) -->
13-
1412
### :pencil2: 算法
1513

1614
- [剑指 Offer 题解](https://github.com/CyC2018/InnterviewNotes/blob/master/notes/剑指%20offer%20题解.md)

notes/HTTP.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
* [实体首部字段](#实体首部字段)
2626
* [五、具体应用](#五具体应用)
2727
* [Cookie](#cookie)
28-
* [6. Secure](#6-secure)
2928
* [缓存](#缓存)
3029
* [连接管理](#连接管理)
3130
* [内容协商](#内容协商)
@@ -40,7 +39,6 @@
4039
* [认证](#认证)
4140
* [完整性保护](#完整性保护)
4241
* [HTTPs 的缺点](#https-的缺点)
43-
* [配置 HTTPs](#配置-https)
4442
* [七、HTTP/2.0](#七http20)
4543
* [HTTP/1.x 缺陷](#http1x-缺陷)
4644
* [二进制分帧层](#二进制分帧层)
@@ -369,19 +367,19 @@ document.cookie = "tasty_cookie=strawberry";
369367
console.log(document.cookie);
370368
```
371369

372-
### 6. HttpOnly
370+
### 6. HttpOnly
373371

374372
标记为 HttpOnly 的 Cookie 不能被 JavaScript 脚本调用。跨站脚本攻击 (XSS) 常常使用 JavaScript 的 `Document.cookie` API 窃取用户的 Cookie 信息,因此使用 HttpOnly 标记可以在一定程度上避免 XSS 攻击。
375373

376374
```html
377375
Set-Cookie: id=a3fWa; Expires=Wed, 21 Oct 2015 07:28:00 GMT; Secure; HttpOnly
378376
```
379377

380-
## 6. Secure
378+
### 7. Secure
381379

382380
标记为 Secure 的 Cookie 只能通过被 HTTPS 协议加密过的请求发送给服务端。但即便设置了 Secure 标记,敏感信息也不应该通过 Cookie 传输,因为 Cookie 有其固有的不安全性,Secure 标记也无法提供确实的安全保障。
383381

384-
### 7. Session
382+
### 8. Session
385383

386384
除了可以将用户信息通过 Cookie 存储在用户浏览器中,也可以利用 Session 存储在服务器端,存储在服务器端的信息更加安全。
387385

@@ -396,11 +394,11 @@ Session 可以存储在服务器上的文件、数据库或者内存中。也可
396394

397395
应该注意 Session ID 的安全性问题,不能让它被恶意攻击者轻易获取,那么就不能产生一个容易被猜到的 Session ID 值。此外,还需要经常重新生成 Session ID。在对安全性要求极高的场景下,例如转账等操作,除了使用 Session 管理用户状态之外,还需要对用户进行重新验证,比如重新输入密码,或者使用短信验证码等方式。
398396

399-
### 8. 浏览器禁用 Cookie
397+
### 9. 浏览器禁用 Cookie
400398

401399
此时无法使用 Cookie 来保存用户信息,只能使用 Session。除此之外,不能再将 Session ID 存放到 Cookie 中,而是使用 URL 重写技术,将 Session ID 作为 URL 的参数进行传递。
402400

403-
### 9. Cookie 与 Session 选择
401+
### 10. Cookie 与 Session 选择
404402

405403
- Cookie 只能存储 ASCII 码字符串,而 Session 则可以存取任何类型的数据,因此在考虑数据复杂性时首选 Session;
406404
- Cookie 存储在浏览器中,容易被恶意查看。如果非要将一些隐私数据存在 Cookie 中,可以将 Cookie 值进行加密,然后在服务器进行解密;
@@ -720,11 +718,6 @@ HTTPs 的报文摘要功能之所以安全,是因为它结合了加密和认
720718

721719
- 因为需要进行加密解密等过程,因此速度会更慢;
722720
- 需要支付证书授权的高额费用。
723-
724-
## 配置 HTTPs
725-
726-
[Nginx 配置 HTTPS 服务器](https://aotu.io/notes/2016/08/16/nginx-https/index.html)
727-
728721
# 七、HTTP/2.0
729722

730723
## HTTP/1.x 缺陷
@@ -849,7 +842,7 @@ DELETE /idX/delete HTTP/1.1 -> Returns 404
849842

850843
# 九、HTTP/1.0 与 HTTP/1.1 的区别
851844

852-
> 详细内容请见上文
845+
详细内容请见上文
853846

854847
- HTTP/1.1 默认是长连接
855848

notes/Java IO.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,17 @@ public static void listAllFiles(File dir) {
6969

7070
```java
7171
public static void copyFile(String src, String dist) throws IOException {
72-
7372
FileInputStream in = new FileInputStream(src);
7473
FileOutputStream out = new FileOutputStream(dist);
74+
7575
byte[] buffer = new byte[20 * 1024];
76+
int cnt;
7677

7778
// read() 最多读取 buffer.length 个字节
7879
// 返回的是实际读取的个数
7980
// 返回 -1 的时候表示读到 eof,即文件尾
80-
while (in.read(buffer, 0, buffer.length) != -1) {
81-
out.write(buffer);
81+
while ((cnt = in.read(buffer, 0, buffer.length)) != -1) {
82+
out.write(buffer, 0, cnt);
8283
}
8384

8485
in.close();
@@ -182,8 +183,10 @@ public static void readFileContent(String filePath) throws IOException {
182183

183184
```java
184185
public static void main(String[] args) throws IOException, ClassNotFoundException {
186+
185187
A a1 = new A(123, "abc");
186188
String objectFile = "file/a1";
189+
187190
ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(objectFile));
188191
objectOutputStream.writeObject(a1);
189192
objectOutputStream.close();
@@ -195,6 +198,7 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio
195198
}
196199

197200
private static class A implements Serializable {
201+
198202
private int x;
199203
private String y;
200204

notes/Java 基础.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ String 不可变性天生具备线程安全,可以在多个线程中安全地
196196

197197
## String Pool
198198

199-
字符串常量池(String Poll)保存着所有字符串字面量(literal strings),这些字面量在编译时期就确定。不仅如此,还可以使用 Stringintern() 方法在运行过程中将字符串添加到 String Poll 中。
199+
字符串常量池(String Pool)保存着所有字符串字面量(literal strings),这些字面量在编译时期就确定。不仅如此,还可以使用 Stringintern() 方法在运行过程中将字符串添加到 String Pool 中。
200200

201-
当一个字符串调用 intern() 方法时,如果 String Poll 中已经存在一个字符串和该字符串值相等(使用 equals() 方法进行确定),那么就会返回 String Poll 中字符串的引用;否则,就会在 String Poll 中添加一个新的字符串,并返回这个新字符串的引用。
201+
当一个字符串调用 intern() 方法时,如果 String Pool 中已经存在一个字符串和该字符串值相等(使用 equals() 方法进行确定),那么就会返回 String Pool 中字符串的引用;否则,就会在 String Pool 中添加一个新的字符串,并返回这个新字符串的引用。
202202

203203
下面示例中,s1 和 s2 采用 new String() 的方式新建了两个不同字符串,而 s3 和 s4 是通过 s1.intern() 方法取得一个字符串引用。intern() 首先把 s1 引用的字符串放到 String Pool 中,然后返回这个字符串引用。因此 s3 和 s4 引用的是同一个字符串。
204204

@@ -219,7 +219,7 @@ String s6 = "bbb";
219219
System.out.println(s4 == s5); // true
220220
```
221221

222-
Java 7 之前,String Poll 被放在运行时常量池中,它属于永久代。而在 Java 7String Poll 被移到堆中。这是因为永久代的空间有限,在大量使用字符串的场景下会导致 OutOfMemoryError 错误。
222+
Java 7 之前,String Pool 被放在运行时常量池中,它属于永久代。而在 Java 7String Pool 被移到堆中。这是因为永久代的空间有限,在大量使用字符串的场景下会导致 OutOfMemoryError 错误。
223223

224224
- [StackOverflow : What is String interning?](https://stackoverflow.com/questions/10578984/what-is-string-interning)
225225
- [深入解析 String#intern](https://tech.meituan.com/in_depth_understanding_string_intern.html)
@@ -685,34 +685,34 @@ protected void finalize() throws Throwable {}
685685

686686
**1. 等价关系**
687687

688-
(一)自反性
688+
自反性
689689

690690
```java
691691
x.equals(x); // true
692692
```
693693

694-
(二)对称性
694+
对称性
695695

696696
```java
697697
x.equals(y) == y.equals(x); // true
698698
```
699699

700-
(三)传递性
700+
传递性
701701

702702
```java
703703
if (x.equals(y) && y.equals(z))
704704
x.equals(z); // true;
705705
```
706706

707-
(四)一致性
707+
一致性
708708

709709
多次调用 equals() 方法结果不变
710710

711711
```java
712712
x.equals(y) == x.equals(y); // true
713713
```
714714

715-
(五)null 的比较
715+
null 的比较
716716

717717
对任何不是 null 的对象 x 调用 x.equals(null) 结果都为 false
718718

@@ -741,6 +741,7 @@ System.out.println(x == y); // false
741741

742742
```java
743743
public class EqualExample {
744+
744745
private int x;
745746
private int y;
746747
private int z;

notes/Java 容器.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* [HashMap](#hashmap)
1414
* [ConcurrentHashMap](#concurrenthashmap)
1515
* [LinkedHashMap](#linkedhashmap)
16-
* [WeekHashMap](#weekhashmap)
16+
* [WeakHashMap](#weakhashmap)
1717
* [附录](#附录)
1818
* [参考资料](#参考资料)
1919
<!-- GFM-TOC -->
@@ -974,7 +974,7 @@ void afterNodeAccess(Node<K,V> e) { // move node to last
974974

975975
### afterNodeInsertion()
976976

977-
在 put 等操作之后执行,当 removeEldestEntry() 方法返回 ture 时会移除最晚的节点,也就是链表首部节点 first。
977+
在 put 等操作之后执行,当 removeEldestEntry() 方法返回 true 时会移除最晚的节点,也就是链表首部节点 first。
978978

979979
evict 只有在构建 Map 的时候才为 false,在这里为 true。
980980

@@ -1034,7 +1034,7 @@ public static void main(String[] args) {
10341034
[3, 1, 4]
10351035
```
10361036

1037-
## WeekHashMap
1037+
## WeakHashMap
10381038

10391039
### 存储结构
10401040

0 commit comments

Comments
 (0)