Skip to content

Commit 09ae10d

Browse files
committed
更新Java基础面试题
1 parent dc17e51 commit 09ae10d

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

Java/Java基础面试题.md

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -190,26 +190,19 @@ int y = x; // 拆箱 调⽤了 X.intValue()
190190
下面看一道常见的面试题:
191191

192192
```java
193-
public void testAutoBox() {
194-
int a = 100;
195-
Integer b = 100;
196-
System.out.println(a == b);
197-
198-
Integer c = 100;
199-
Integer d = 100;
200-
System.out.println(c == d);
201-
202-
Integer e = 200;
203-
Integer f = 200;
204-
System.out.println(e == f);
205-
}
193+
Integer a = 100;
194+
Integer b = 100;
195+
System.out.println(a == b);
196+
197+
Integer c = 200;
198+
Integer d = 200;
199+
System.out.println(c == d);
206200
```
207201

208202
输出:
209203

210204
```java
211205
true
212-
true
213206
false
214207
```
215208

@@ -223,7 +216,7 @@ public static Integer valueOf(int i) {
223216
}
224217
```
225218

226-
`Integer e = 200;` 会调用 调⽤`Integer.valueOf(200)`。而从Integer的valueOf()源码可以看到,这里的实现并不是简单的new Integer,而是用IntegerCache做一个cache。
219+
`Integer c = 200;` 会调用 调⽤`Integer.valueOf(200)`。而从Integer的valueOf()源码可以看到,这里的实现并不是简单的new Integer,而是用IntegerCache做一个cache。
227220

228221
```java
229222
private static class IntegerCache {
@@ -252,7 +245,7 @@ private static class IntegerCache {
252245
}
253246
```
254247

255-
这是IntegerCache静态代码块中的一段,默认Integer cache 的下限是-128,上限默认127。当赋值100给Integer时,刚好在这个范围内,所以从cache中取对应的Integer并返回,所以二次返回的是同一个对象,所以==比较是相等的,当赋值200给Integer时,不在cache 的范围内,所以会new Integer并返回,当然==比较的结果是不相等的。
248+
这是IntegerCache静态代码块中的一段,默认Integer cache 的下限是-128,上限默认127。当赋值100给Integer时,刚好在这个范围内,所以从cache中取对应的Integer并返回,所以a和b返回的是同一个对象,所以==比较是相等的,当赋值200给Integer时,不在cache 的范围内,所以会new Integer并返回,当然==比较的结果是不相等的。
256249

257250
## String 为什么不可变?
258251

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616

1717
如果大家想要实时关注我更新的文章以及分享的干货的话,可以关注我的**公众号『 程序员大彬 』**,后台回复『 PDF 』可以**下载最新版本的大厂高频面试题目PDF版本**
1818

19-
<div align="center"><img src="https://gitee.com/tysondai/img/raw/master/公众号.jpg" style="zoom:90%;" />
19+
<div align="center"><img src="https://raw.githubusercontent.com/Tyson0314/img/master/公众号.jpg" style="zoom:90%;" />
2020
<p>个人公众号</p>
2121
</div>
2222
<p align="center">
2323
<br>
24-
<a href="https://gitee.com/tysondai/img/raw/master/个人微信索隆(交流群).png"><img src="https://gitee.com/tysondai/img/raw/master/微信交流群.png" alt="微信交流群"></a>
25-
<a href="https://gitee.com/tysondai/img/raw/master/公众号.jpg"><img src="https://gitee.com/tysondai/img/raw/master/公众号.png" alt="公众号"></a>
26-
<a href="https://www.zhihu.com/people/dai-shu-bin-13"><img src="https://gitee.com/tysondai/img/raw/master/知乎.png" alt="知乎"></a>
27-
<a href="https://www.nowcoder.com/profile/8683776/myDiscussPost"><img src="https://gitee.com/tysondai/img/raw/master/牛客网.png" alt="牛客网"></a>
28-
<a href="https://juejin.cn/user/201965869218574/posts"><img src="https://gitee.com/tysondai/img/raw/master/掘金.png" alt="掘金"></a>
29-
<a href="https://github.com/Tyson0314/java-books"><img src="https://gitee.com/tysondai/img/raw/master/免费计算机电子书籍.png" alt="免费PDF"></a>
24+
<a href="https://raw.githubusercontent.com/Tyson0314/img/master/个人微信索隆(交流群).png"><img src="https://raw.githubusercontent.com/Tyson0314/img/master/微信交流群.png" alt="微信交流群"></a>
25+
<a href="https://raw.githubusercontent.com/Tyson0314/img/master/公众号.jpg"><img src="https://raw.githubusercontent.com/Tyson0314/img/master/公众号.png" alt="公众号"></a>
26+
<a href="https://www.zhihu.com/people/dai-shu-bin-13"><img src="https://raw.githubusercontent.com/Tyson0314/img/master/知乎.png" alt="知乎"></a>
27+
<a href="https://www.nowcoder.com/profile/8683776/myDiscussPost"><img src="https://raw.githubusercontent.com/Tyson0314/img/master/牛客网.png" alt="牛客网"></a>
28+
<a href="https://juejin.cn/user/201965869218574/posts"><img src="https://raw.githubusercontent.com/Tyson0314/img/master/掘金.png" alt="掘金"></a>
29+
<a href="https://github.com/Tyson0314/java-books"><img src="https://raw.githubusercontent.com/Tyson0314/img/master/免费计算机电子书籍.png" alt="免费PDF"></a>
3030
</p>
3131

3232

@@ -176,7 +176,7 @@
176176

177177
如果想进**技术、面试交流群**,可以扫描下方二维码加我微信,**备注加群**,我拉你进群,群里有BAT大佬,互相学习~
178178

179-
<div align="center"><img src="https://gitee.com/tysondai/img/raw/master/个人微信索隆.jpg" style="zoom:60%;" />
179+
<div align="center"><img src="https://raw.githubusercontent.com/Tyson0314/img/master/个人微信索隆.jpg" style="zoom:60%;" />
180180
<p></p>
181181
</div>
182182

@@ -187,7 +187,7 @@
187187

188188
| 微信 | 支付宝 |
189189
| ----------------------------------------------------------- | ------------------------------------------------------------ |
190-
| ![](https://gitee.com/tysondai/img/raw/master/微信收款.png) | ![](https://gitee.com/tysondai/img/raw/master/支付宝赞赏码.png) |
190+
| ![](https://raw.githubusercontent.com/Tyson0314/img/master/微信收款.png) | ![](https://raw.githubusercontent.com/Tyson0314/img/master/支付宝赞赏码.png) |
191191

192192
每笔赞赏我会在下面记录下来,感谢你们,我会更加努力,砥砺前行~
193193

0 commit comments

Comments
 (0)