试题如下 :
参考答案 :
Importieren Sie java.io.filenotfoundException; import Java.io.ioxception; import Java.util.ArrayList; importieren java.util.concurrent */public class Interview {private static void One () {String str1 = "Hallo"; String str2 = "er"+new String ("llo"); System.err.println (str1 == str2); System.out.println ("1. false"); } private static void zwei () {int i = integer.max_value; System.err.println ((i+1) <i); System.out.println ("2. 存在一个 i, 使得 (i+1) <i"); } private static void drei () {System.err.println ("GC ist kein Java -Thread, es ist ein nationaler Thread"); Thread.getallStacktraces (). Keyset (). Foreach (thread -> system.out.println (thread.getName ()+" ->"+thread.isdaemon ()+""+thread.getPriority ())); System.out.println ("3. GC 线程是 Daemon 线程"); } private statische volatile int count = 0; private static void four () {ExecutorService ExecutorService = Executors.NewcachedThreadpool (); für (int j = 0; j <10; j ++) {ExecutorService.submit (()-> {für (int i = 0; i <1000000; i ++) {count ++;}}); } System.out.println ("count sollte:" +10000000+ ", tatsächlich be:"+count); System.out.println ("4. Volatile 不能保证线程安全"); } private static void five () {ArrayList <GanzEger> list = new ArrayList <> (20); list.add (1); System.out.println ("Debug -Code, nicht ausführende Grow -Methode"); System.out.println ("5. List wachsen 0 -mal"); } private static void sechs () {System.out.println ("BufferedReader's Constructor akzeptiert nur eine Leserinstanz"); System.out.println ("6. New BufferedReader (neuer FileInputStream (/" a.dat/"); ist falsch"); } private static void sieben () {try {if (true) {thrower New ioException (); }} catch (FilenotFoundException e) {System.out.print ("FilenotFoundException!"); } catch (ioException e) {System.out.print ("ioException!"); } catch (Ausnahme e) {System.out.print ("Ausnahme!"); } System.out.println ("/n7. IoException!"); } private static void acht () {System.out.println ("String S; System.out.println (s); Fehler: Variable S wurde möglicherweise nicht mit -xLint: Unkontrolliert für Details initialisiert."); System.out.println ("8. 由于 String S 没有初始化, 代码不能编译通过"); } private static void neun () {System.out.println ("5" +2); System.out.println ("9. 52"); } private statische void Ten () {int i = 2; int result = 0; Switch (i) {Fall 1: Ergebnis = Ergebnis + i; Fall 2: Ergebnis = Ergebnis + I * 2; Fall 3: Ergebnis = Ergebnis + I * 3; } System.out.println ("result ="+result); System.out.println ("10. 10"); } private statische Klasse null {public static void hello () {System.out.println ("Hallo"); } public static void main (String [] args) {((null) null) .hello (); Null _null = (null) null; _null.hello (); }} private statische Klasse 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+"und"); System.out.print (ex.ch); System.out.println (); }} private statische Klasse StringExample2 {public static void Change (String str) {str = "willkommen"; } public static void main (String [] args) {String str = "1234"; Veränderung (str); System.out.println (str); }} private statische Klasse Forloop {statische boolean foo (char c) {System.out.print (c); zurückkehren; } public static void main (String [] args) {int i = 0; für (foo ('a'); foo ('b') && (i <2); foo ('c')) {i ++; Essen'); } System.out.println (); }} private statische Klasse Halloa {public helloa () {System.out.println ("Helloa"); } {System.out.println ("Ich bin eine Klasse"); } static {System.out.println ("static a"); }} private statische Klasse Hellob erweitert Helloa {public hellob () {System.out.println ("hellob"); } {System.out.println ("Ich bin B -Klasse"); } static {System.out.println ("static b"); } public static void main (String [] args) {System.out.println ("Hauptstart"); neuer Hellob (); neuer Hellob (); System.out.println ("Hauptende"); }} public static void main (String [] args) {One (); zwei(); drei(); vier (); fünf(); sechs(); Sieben(); acht(); neun(); zehn(); Null.main (null); StringExample1.Main (null); StringExample2.main (null); Forloop.main (null); Hellob.main (null); }}以上就是本文的全部内容 , 希望对大家的学习有所帮助 , 也希望大家多多支持武林网。 也希望大家多多支持武林网。