試題如下:
參考答案:
導入java.io.io.filenotfoundException; import java.io.ioexception; import java.util.arraylist; import java.util.concurrent.concurrent.executorservice; import java.util.util.util.concurrent.executors; executors;/**由ysc在7/26/16/16/16/16/26/16/ysc上創建。 */公共類採訪{private static void One(){字符串str1 =“ Hello”;字符串str2 =“ he”+new String(“ llo”); system.err.println(str1 == str2); system.out.println(“1。false”); } private static void二(){int i = integer.max_value; system.err.println(((i+1)<i); system.out.println(“ 2。存在一個i,使得(i+1)<i”); } private static void三(){system.err.println(“ GC不是Java線程,它是本機線程”); thread.getAllStackTraces()。keyset()。foreach(thread-> system.out.println(thread.getName()+“ - >” - >“ - >”+thread.isdaemon()+“”+thread.getPriority()); system.out.println(“3。Gc線程是守護程序線程”); }私有靜態揮發性int count = 0; private static void四(){executorService executorService = executors.newcachedthreadpool(); for(int j = 0; j <10; j ++){executorService.Submit(() - > {for(int i = 0; i <1000000; i ++){count ++;}}); } system.out.println(“計數應為:“ +10000000+”,實際be:“+count); system.out.println(“ 4。揮發性不能保證線程安全”); } private static void fix(){arrayList <integer> list = new ArrayList <>(20); list.add(1); system.out.println(“調試代碼,而不是執行grow方法”); system.out.println(“ 5。列表增長0次”); } private static void六(){system.out.println(“ BufferedReader的構造函數僅接受讀取器實例”); system.out.println(“6。 NewBufferedReader)(new FileInputStream(/“ a.dat/”));是錯誤的); } private static void七(){try {if(true){thur new ioexception(); }} catch(filenotfoundException e){system.out.print(“ filenotfoundexception!”); } catch(ioexception e){system.out.print(“ ioexception!”); } catch(異常E){system.out.print(“ exception!”); } system.out.println(“/n7。ioexception!”); } private static void八(){system.out.println(“字符串s; system.out.println(s);錯誤:變量s可能沒有用-xlint初始化/nrecompile,以-xlint:未經檢查以獲取詳細信息。”); system.out.println(“ 8。 } private static void nine(){system.out.println(“ 5” +2); system.out.println(“9。52”); }私有靜態void ten(){int i = 2; int結果= 0;開關(i){情況1:結果=結果 + i;案例2:結果=結果 + i * 2;案例3:結果=結果 + i * 3; } system.out.println(“結果=”+結果); System.out.println(“10。10”); }私有靜態類NULL {public static void Hello(){System.out.println(“ Hello”); } public static void main(string [] args){(((null)null).hello(); null _null =(null)null; _null.hello(); }}私有靜態類StringExample1 {字符串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 =“歡迎”; } public static void main(string [] args){string str =“ 1234”;更改(str); system.out.println(str); }} private static類forloop {static boolean foo(char c){system.out.print(c);返回true; } public static void main(string [] args){int i = 0; for(foo('a'); foo('b')&&(i <2); foo('c')){i ++;食物'); } system.out.println(); }} private static類helloa {public helloa(){system.out.println(“ helloa”); } {system.out.println(“我是class”); } static {system.out.println(“ static a”); }} private static類Hellob擴展了Helloa {public HellOb(){System.out.println(“ HellOb”); } {system.out.println(“我是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){一();二();三();四();五();六();七();八();九();十(); null.main(null); StringExample1.main(null); StringExample2.2.main(null); forloop.main(null); hellob.main(null); }}}以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。 ,也希望大家多多支持武林網。