This article includes a variety of tedious Java written/interview questions, some of which are easy to forget and occasionally updated. I also hope that you can leave a message below to post all kinds of tedious test and interview questions you have encountered or seen.
J2EE Basics
1. What is the result of the following code about the operator priority? (Written test)
Package test; public class test {public static void main (string [] ARGs) {int K = 0; int ret = ++ K + k ++ K + K; // The value of RET is system. err. println (RET );}}
2. What is output by the following code for operator problems? (Written test)
package test;public class Test {public static void main(String[] args) {int i1 = 10, i2 = 10;System.err.println("i1 + i2 = " + i1 + i2);System.err.println("i1 - i2 = " + i1 - i2);System.err.println("i1 * i2 = " + i1 * i2);System.err.println("i1 / i2 = " + i1 / i2);}}
3. What is the result of the following code? Or throw an exception? (Written test)
package test;public class Test {public void myMethod(String str) {System.err.println("string");}public void myMethod(Object obj) {System.err.println("object");}public static void main(String[] args) {Test t = new Test();t.myMethod(null);}}
4. Suppose Today is July 22, September 8. What is the output of the following code? (Written test)
package test;import java.util.Date;public class Test {public static void main(String[] args) {Date date = new Date();System.err.println(date.getMonth() + " " + date.getDate());}}
5. What is the output result of the following code?
package test;public class Test {public static void main(String[] args) {double val = 11.5;System.err.println(Math.round(val));System.err.println(Math.floor(val));System.err.println(Math.ceil(val));}}
6. Program to output the names of all directories and files under a directory, and use tabs between directories. (Written test)
package test;import java.io.File;public class Test {public static void main(String[] args) {new Test().read("D:/test", "");}public void read(String path, String tab) {File file = new File(path);File[] childFiles = file.listFiles();for (int i = 0; childFiles != null && i < childFiles.length; i++) {System.err.println(tab + childFiles[i].getName());if (childFiles[i].isDirectory()) {read(childFiles[i].getPath(), tab + "\t");}}}}
Do not think it is very simple. at least remember that the method for returning all the files in the current folder is listfiles (). Do not misspell isdirectory.
7. read 10 integers from the keyboard, and then output the data from large to small. (Written test)
Package test; import Java. util. arrays; import Java. util. comparator; import Java. util. role; public class test {public static void main (string [] ARGs) {role in = new role (system. in); // note that the array here is not an integer of int [] arr = new integer [10]; for (INT I = 0; I <10; I ++) {arr [I] = in. nextint ();} arrays. sort (ARR, new comparator <integer> () {@ overridepublic int compare (integer O1, integer O2) {If (O1> O2) Return-1; if (O1 <O2) return 1; return 0 ;}}); system. err. println (arrays. tostring (ARR ));}}
You can ignore this question when writing the Sorting Algorithm by yourself. If it is arrays. Sort (), pay attention to the difference between the comparator and comparable interfaces.
8. What is the result of the following code?
package test;public class Test extends Base {public static void main(String[] args) {Base b = new Test();b.method();Test t = new Test();t.method();}@Overridepublic void method() {System.err.println("test");}}class Base {public void method() throws InterruptedException {System.err.println("base");}}
9. What is the result of the following code?
package test;public class Test extends Base {public static void main(String[] args) {new Test().method();}public void method() {System.err.println(super.getClass().getName());System.err.println(this.getClass().getSuperclass().getName());}}class Base {}
10, true or false?
package test;public class Test {public static void main(String[] args) {String str1 = new String("abc");String str2 = new String("abc");System.err.println(str1.equals(str2));StringBuffer sb1 = new StringBuffer("abc");StringBuffer sb2 = new StringBuffer("abc");System.err.println(sb1.equals(sb2));}}
11. What are the output results?
package test;public class Test {public static void main(String[] args) {System.err.println(new Test().method1());System.err.println(new Test().method2());}public int method1() {int x = 1;try {return x;} finally {++x;}}public int method2() {int x = 1;try {return x;} finally {return ++x;}}}
So what? Output
package test;public class Test {public static void main(String[] args) {System.err.println(method());}public static boolean method() { try { return true; } finally { return false; } }}
12. Are there any differences between Methods m1 and m2? What is the difference?
package test;public class Test {public static void main(String[] args) {}public synchronized void m1() {}public static synchronized void m2() {}}
13. True or false? Reason
package test;public class Test {public static void main(String[] args) {Integer i1 = 127;Integer i2 = 127;System.err.println(i1 == i2);i1 = 128;i2 = 128;System.err.println(i1 == i2);}}
14. True or false? Reason
package test;public class Test {public static void main(String[] args) {String str1 = "a";String str2 = "a";String str3 = new String("a");System.err.println(str1 == str2);System.err.println(str1 == str3);str3 = str3.intern();System.err.println(str1 == str3);}}
15. True or false? Reason
package test;public class Test {public static void main(String[] args) {System.err.println(12 - 11.9 == 0.1);}}
16. What is the output of the following code?
package test;import java.math.BigInteger;public class Test {public static void main(String[] args) {BigInteger one = new BigInteger("1");BigInteger two = new BigInteger("2");BigInteger three = new BigInteger("3");BigInteger sum = new BigInteger("0");sum.add(one);sum.add(two);sum.add(three);System.out.println(sum.toString());}}
17. What is the output result? 12345? Sort by words? Or?
package test;import java.util.HashSet;import java.util.Iterator;import java.util.Set;public class Test {public static void main(String[] args) {Set<String> set = new HashSet<String>();set.add("one");set.add("two");set.add("three");set.add("four");set.add("five");for (Iterator<String> it = set.iterator(); it.hasNext();) {System.err.println(it.next());}}}
18. How to iterate the map container? What's next?
19. The output result of the following code (Examination choice)
public class Test {public static void main(String[] args) {System.err.println(args.length);}}/*A. nullB. 0C. TestD. Exception in thread "main" java.lang.NullPointerException*/
20. The following is the implementation code of a singleton. Please point out several errors or unreasonable points in the Code and correct them.
public class Test {public Test instance = null;public static Test getInstance() {if (instance == null) {instance = new Test();return instance;}}}
If you write so much data first, it will be updated all the time.
Remember this article address: http://blog.csdn.net/smcwwh/article/details/7315041