一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務器之家 - 編程語言 - JAVA教程 - 15道非常經典的Java面試題 附詳細答案

15道非常經典的Java面試題 附詳細答案

2020-06-26 15:38楊尚川 JAVA教程

這篇文章主要為大家推薦了15道非常經典的Java面試題,附詳細答案,具有一定的參考價值,感興趣的小伙伴們可以參考一下

試題如下:

15道非常經典的Java面試題 附詳細答案

15道非常經典的Java面試題 附詳細答案

15道非常經典的Java面試題 附詳細答案

15道非常經典的Java面試題 附詳細答案

15道非常經典的Java面試題 附詳細答案

參考答案:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
 
/**
 * Created by ysc on 7/26/16.
 */
public class Interview {
 private static void one(){
 String str1 = "hello";
 String str2 = "he"+new String("llo");
 System.err.println(str1==str2);
 System.out.println("1. false");
 }
 private static void two(){
 int i = Integer.MAX_VALUE;
 System.err.println((i+1)<i);
 System.out.println("2. 存在一個i, 使得(i+1)<i");
 }
 private static void three(){
 System.err.println("gc is not a Java Thread, it is a native thread");
 Thread.getAllStackTraces().keySet().forEach(thread -> System.out.println(thread.getName()+"->"+thread.isDaemon()+" "+thread.getPriority()));
 System.out.println("3. gc線程是daemon線程");
 }
 private static volatile int count = 0;
 private static void four(){
 ExecutorService executorService = Executors.newCachedThreadPool();
 for(int j=0; j<10; j++){
  executorService.submit(()->{
  for(int i=0; i<1000000; i++){
   count++;
  }
  });
 }
 System.out.println("count should be: "+10000000+", actual be: "+count);
 System.out.println("4. volatile不能保證線程安全");
 }
 private static void five(){
 ArrayList<Integer> list = new ArrayList<>(20);
 list.add(1);
 System.out.println("debug code, not execute grow method");
 System.out.println("5. list grow 0 times");
 }
 private static void six() {
 System.out.println("BufferedReader's constructor only accepts a Reader instance");
 System.out.println("6. new BufferedReader(new FileInputStream(\"a.dat\")); is wrong");
 }
 private static void seven() {
 try{
  if(true){
  throw new IOException();
  }
 }catch (FileNotFoundException e){
  System.out.print("FileNotFoundException!");
 }catch (IOException e){
  System.out.print("IOException!");
 }catch (Exception e){
  System.out.print("Exception!");
 }
 System.out.println("\n7. IOException!");
 }
 private static void eight() {
 System.out.println("String s;System.out.println(s); error: variable s might not have been initialized\nRecompile with -Xlint:unchecked for details.");
 System.out.println("8. 由于String s沒有初始化, 代碼不能編譯通過");
 }
 private static void nine() {
 System.out.println("5"+2);
 System.out.println("9. 52");
 }
 private static void ten() {
 int i = 2;
 int result = 0;
 switch(i){
  case 1:
  result = result + i;
  case 2:
  result = result + i * 2;
  case 3:
  result = result + i * 3;
 }
 System.out.println("result="+result);
 System.out.println("10. 10");
 }
 private static class Null{
 public static void hello(){
  System.out.println("hello");
 }
 public static void main(String[] args) {
  ((Null)null).hello();
  Null _null = (Null)null;
  _null.hello();
 }
 }
 private static class StringExample1{
 String str = new String("good");
 char[] ch = {'a', 'b', 'c'};
 public void change(String str, char[] ch){
  str = "test ok";
  ch[0] = 'g';
 }
 
 public static void main(String[] args) {
  StringExample1 ex = new StringExample1();
  ex.change(ex.str, ex.ch);
  System.out.print(ex.str+" and ");
  System.out.print(ex.ch);
  System.out.println();
 }
 }
 private static class StringExample2{
 public static void change(String str){
  str = "welcome";
 }
 
 public static void main(String[] args) {
  String str = "1234";
  change(str);
  System.out.println(str);
 }
 }
 private static class ForLoop{
 static boolean foo(char c){
  System.out.print(c);
  return true;
 }
 
 public static void main(String[] args) {
  int i=0;
  for(foo('A');foo('B')&&(i<2);foo('C')){
  i++;
  foo('D');
  }
  System.out.println();
 }
 }
 private static class HelloA{
 public HelloA(){
  System.out.println("HelloA");
 }
 
 { System.out.println("I'm A class"); }
 
 static {
  System.out.println("static A");
 }
 }
 private static class HelloB extends HelloA{
 public HelloB(){
  System.out.println("HelloB");
 }
 
 { System.out.println("I'm B class"); }
 
 static {
  System.out.println("static B");
 }
 
 public static void main(String[] args) {
  System.out.println("main start");
  new HelloB();
  new HelloB();
  System.out.println("main end");
 }
 }
 public static void main(String[] args) {
 one();
 two();
 three();
 four();
 five();
 six();
 seven();
 eight();
 nine();
 ten();
 Null.main(null);
 StringExample1.main(null);
 StringExample2.main(null);
 ForLoop.main(null);
 HelloB.main(null);
 }
}

 

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 高h折磨调教古代 | 国内精品久久久久影院网站 | 美女脱了内裤让男桶爽 | 513热点| 国产成人精品三级在线 | 日本三级在丈面前被耍了 | 国产码一区二区三区 | hd最新国产人妖ts视频 | 日韩国产欧美精品综合二区 | 俄罗斯毛片免费大全 | 波多野结中文字幕在线69视频 | 高h孕交| 亚洲AV永久无码精品老司机蜜桃 | 亚洲夜色夜色综合网站 | 无人视频在线观看完整版高清 | 狠狠色婷婷日日综合五月 | 免费在线看| 四虎影视紧急入口地址大全 | 国内自拍2019 | 亚洲国产精品久久久久久网站 | 久久青青草视频在线观 | 天天综合天天色 | 91国产在线视频 | 攻插受| 性做久久久久免费观看 | 日本大乳护士的引诱图片 | 私人影院免费观看 | 青青视频国产依人在线 | 午夜精品国产自在现线拍 | 999热在线精品观看全部 | 亚洲国产在 | 7788理论片在线观看 | xxx86日本人 xxnx日本免费护士 | 日麻逼 | 国产精品久久久久久久久免费hd | 亚洲日韩男人网在线 | 91精品导航在线观看 | 91亚洲精品第一综合不卡播放 | 国士李风起全文在线阅读 | 边摸边吃奶又黄激烈视频韩国 | 日本久久影视 |