X Tutup
Skip to content

Commit 4a903f0

Browse files
committed
更新SpringSecurity源码学习文章
1 parent 13d614a commit 4a903f0

File tree

4 files changed

+197
-5
lines changed

4 files changed

+197
-5
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.learnjava.concurrent;
2+
3+
import org.junit.Test;
4+
5+
import java.util.concurrent.atomic.AtomicInteger;
6+
7+
/**
8+
* @author LuoHaiYang
9+
*/
10+
public class AtomicTest {
11+
12+
@Test
13+
public void testAtomicInteger() {
14+
AtomicInteger atomicInteger = new AtomicInteger(1);
15+
System.out.println(atomicInteger.get());
16+
17+
boolean compareAndSet = atomicInteger.compareAndSet(1, 2);
18+
System.out.println(compareAndSet);
19+
20+
System.out.println(atomicInteger.incrementAndGet());
21+
22+
System.out.println(atomicInteger.get());
23+
24+
}
25+
}

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ Tip:
2222

2323
- 超大超全Spring源码知识脑图
2424

25-
![image](https://github.com/coderbruis/JavaSourceLearning/blob/master/note/images/Spring.png)
26-
2725
- [在IDEA中构建Spring源码](https://blog.csdn.net/CoderBruis/article/details/85840438)
2826
- [深入SpringIOC容器一](https://blog.csdn.net/CoderBruis/article/details/85940756)
2927
- [深入SpringIOC容器二](https://blog.csdn.net/CoderBruis/article/details/86505582)
@@ -40,8 +38,6 @@ Tip:
4038

4139
- 超大超全Spring源码知识脑图
4240

43-
![image](https://github.com/coderbruis/JavaSourceLearning/blob/master/note/images/SpringBoot.png)
44-
4541
- [深入SpringBoot源码学习之——SpringFactoriesLoader](https://blog.csdn.net/CoderBruis/article/details/106559304)
4642
- [深入SpringBoot源码学习之——系统初始化器](https://blog.csdn.net/CoderBruis/article/details/106610007)
4743
- [深入SpringBoot源码学习之——SpringBoot的事件和监听器](https://blog.csdn.net/CoderBruis/article/details/106896656)
@@ -50,4 +46,7 @@ Tip:
5046
- Netty源码学习
5147
- [二进制运算以及源码、反码以及补码学习](https://github.com/coderbruis/JavaSourceLearning/blob/master/note/Netty/%E4%BA%8C%E8%BF%9B%E5%88%B6.md)
5248
- [Netty源码包结构](https://github.com/coderbruis/JavaSourceLearning/blob/master/note/Netty/Netty%E6%BA%90%E7%A0%81%E5%8C%85%E7%BB%93%E6%9E%84.md)
53-
- [Netty中的EventLoopGroup](https://github.com/coderbruis/JavaSourceLearning/blob/master/note/Netty/Netty%E4%B8%AD%E7%9A%84EventLoopGroup%E6%98%AF%E4%BB%80%E4%B9%88.md)
49+
- [Netty中的EventLoopGroup](https://github.com/coderbruis/JavaSourceLearning/blob/master/note/Netty/Netty%E4%B8%AD%E7%9A%84EventLoopGroup%E6%98%AF%E4%BB%80%E4%B9%88.md)
50+
51+
- SpringSecurity&OAuth2源码学习
52+
- [从零开始系统学习SpringSecurity和OAuth2(一)—— 初识SpringSecurity](https://blog.csdn.net/CoderBruis/article/details/107297547)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.bruis.learnnetty.binary;
2+
3+
/**
4+
* @author LuoHaiYang
5+
*/
6+
public class BinaryTest {
7+
public static void main(String[] args) {
8+
9+
int a = -16;
10+
11+
/**
12+
* 由于二进制运算都是用补码来进行的,因为换算为补码后可以让最高位来参与运算。
13+
*/
14+
System.out.println(Integer.toBinaryString(a));
15+
System.out.println(Integer.toUnsignedString(a));
16+
System.out.println(a << 2);
17+
}
18+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
package com.bruis.learnnetty.binary;
2+
3+
import org.junit.Test;
4+
5+
/**
6+
* @author LuoHaiYang
7+
*/
8+
public class BinaryTest {
9+
10+
/**
11+
* 对负数的源码、补码和反码进行验证
12+
*/
13+
@Test
14+
public void testSingedNumber() {
15+
16+
/**
17+
* 1 的二进制:源码 0000 0000 0000 0000 0000 0000 0000 0001
18+
* 补码 0000 0000 0000 0000 0000 0000 0000 0001
19+
* 正数的源码和补码相同, 正数没有反码一说,反码是用于计算负数补码的。
20+
*
21+
* -1 的二进制:源码 1000 0000 0000 0000 0000 0000 0000 0001
22+
* 补码 1111 1111 1111 1111 1111 1111 1111 1111
23+
* 反码 1111 1111 1111 1111 1111 1111 1111 1110
24+
*
25+
* 照网上介绍的,二进制的运算都是通过补码来进行的,
26+
* 那么 1 & -1则为:
27+
* 0000 0000 0000 0000 0000 0000 0000 0001
28+
* 由于最高位为0,即为正数,所以该数即为正数。所以补码、源码、反码都一样,所以源码为:
29+
* 0000 0000 0000 0000 0000 0000 0000 0001 换算为10进制为1。
30+
* 那么 1 ^ -1则为:
31+
* 1111 1111 1111 1111 1111 1111 1111 1110
32+
* 由于上述异运算结果为补码,所以得换回源码之后再计算得十进制结果。
33+
* 补码:1111 1111 1111 1111 1111 1111 1111 1110
34+
* 反码计算源码步骤:反码 - 1 ,然后再计算反码
35+
* 补码 - 1 , 得到的反码为:
36+
* 1111 1111 1111 1111 1111 1111 1111 1101
37+
* 用上述反码计算源码得:
38+
* 1000 0000 0000 0000 0000 0000 0000 0010
39+
*
40+
* 由于最高位为1,即为负数,所以结果为2。
41+
*
42+
* 则 1 | -1 可以计算结果为:
43+
* 1111 1111 1111 1111 1111 1111 1111 1111
44+
* 反码:
45+
* 1111 1111 1111 1111 1111 1111 1111 1110
46+
* 源码:
47+
* 1000 0000 0000 0000 0000 0000 0000 0001
48+
*
49+
*/
50+
int a = 1, b = -1;
51+
52+
// 1
53+
System.out.println(a & b);
54+
// -2
55+
System.out.println(a ^ b);
56+
// -1
57+
System.out.println(a | b);
58+
59+
}
60+
61+
@Test
62+
public void testSingedNumber2() {
63+
64+
/**
65+
* 分析:
66+
* 10
67+
* 源码:0000 0000 0000 0000 0000 0000 0000 1010
68+
* 补码:0000 0000 0000 0000 0000 0000 0000 1010
69+
*
70+
* -10
71+
* 源码:0000 0000 0000 0000 0000 0000 0000 1010
72+
* 反码:1111 1111 1111 1111 1111 1111 1111 0101
73+
* 补码:1111 1111 1111 1111 1111 1111 1111 0110
74+
*
75+
* a & b
76+
* 补码:0000 0000 0000 0000 0000 0000 0000 0010
77+
* 反码:0000 0000 0000 0000 0000 0000 0000 0010
78+
* 源码:0000 0000 0000 0000 0000 0000 0000 0010
79+
*
80+
* a ^ b
81+
* 补码:0000 0000 0000 0000 0000 0000 0000 0010
82+
* 反码:0000 0000 0000 0000 0000 0000 0000 0010
83+
* 源码:0000 0000 0000 0000 0000 0000 0000 0010
84+
*
85+
*/
86+
int a = 10, b = -10;
87+
88+
89+
System.out.println(a & b);
90+
System.out.println(a ^ b);
91+
System.out.println(a | b);
92+
}
93+
94+
/**
95+
* 测试移位运算
96+
*/
97+
@Test
98+
public void testMove() {
99+
100+
int a = 16, b = -16;
101+
102+
/**
103+
* a = 16, 其二进制源码为:
104+
* 0000 0000 0000 0000 0000 0000 0001 0000
105+
* 其反码和补码和源码都相同。
106+
*
107+
* b = -16, 其二进制源码为:
108+
* 1000 0000 0000 0000 0000 0000 0001 0000
109+
* 反码:
110+
* 1111 1111 1111 1111 1111 1111 1110 1111
111+
* 补码:
112+
* 1111 1111 1111 1111 1111 1111 1111 0000
113+
*
114+
* -16 << 2 , 对补码进行向左移2位, 低位补0
115+
* 1111 1111 1111 1111 1111 1111 1100 0000
116+
* 由于移位后最高位仍然为1,表示负数,所以需要借助反码来运算
117+
*
118+
* 反码为补码 - 1,则结果为:
119+
* 1111 1111 1111 1111 1111 1111 1011 1111
120+
*
121+
* 源码为反码取反,则结果为:
122+
* 1000 0000 0000 0000 0000 0000 0100 0000
123+
* -1 * (2 * 2 ^ 6) = -64
124+
*
125+
* -16 >> 2
126+
* -16
127+
* 源码:1000 0000 0000 0000 0000 0000 0001 0000
128+
* 补码:1111 1111 1111 1111 1111 1111 1111 0000
129+
*
130+
* 对补码进行向右有符号移2位后,结果(补码)为:
131+
* 111 1111 1111 1111 1111 1111 1111 1100
132+
*
133+
* 反码为补码 - 1, 则对移位后的结果进行运算,得:
134+
* 1111 1111 1111 1111 1111 1111 1111 1011
135+
* 源码得:
136+
* 1000 0000 0000 0000 0000 0000 0000 0100
137+
*
138+
* 结果为-4。
139+
*
140+
*/
141+
System.out.println(a << 2);
142+
System.out.println(b << 2);
143+
144+
System.out.println(a >> 2);
145+
System.out.println(b >> 2);
146+
147+
System.out.println(a >>> 2);
148+
System.out.println(b >>> 2);
149+
}
150+
}

0 commit comments

Comments
 (0)
X Tutup