J2EE部分
1、运算符优先级问题,下面代码的结果是多少?(笔试) package test;
public class Test {
public static void main(String[] args) { int k = 0;
int ret = ++k + k++ + ++k + k; // ret的值为多少
System.err.println(ret); } }
2、运算符问题,下面代码分别输出什么?(笔试) 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、下面代码的结果是什么?还是抛出异常?(笔试) 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、假设今天是9月8日,下面代码输出什么?(笔试) 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、下面代码的输出结果是什么? 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、下面代码的结果是什么? 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(); }
@Override
public void method() {
System.err.println(\"test\"); } }
class Base {
public void method() throws InterruptedException { System.err.println(\"base\"); } }
文案大全
实用标准文档
7、以下代码的结果是什么? 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 { }
8、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)); } }
9、输出的结果是什么? 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; }
这样呢?输出什么 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; } } }
10、方法m1和m2有区别吗?什么区别 package test;
public class Test {
public static void main(String[] args) { }
public synchronized void m1() { }
public static synchronized void m2() { } }
11、true or false?理由
文案大全
实用标准文档
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); } }
12、true or false?理由 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); } }
13、true or false?理由 package test;
public class Test {
public static void main(String[] args) { System.err.println(12 - 11.9 == 0.1); } }
14、以下代码输出是什么?
文案大全
实用标准文档
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()); } }
15、输出的结果是什么?12345?根据单词排序?还是? package test;
import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class Test {
public static void main(String[] args) { Set for (Iterator 16、以下代码输出的结果(笔试选择题) 文案大全 实用标准文档 public class Test { public static void main(String[] args) { System.err.println(args.length); } } A. null B. 0 C. Test D. Exception in thread \"main\" java.lang.NullPointerException 17、下面为一个单例的实现代码,请指出代码中有几个错误或不合理之处,并改正。 public class Test { public Test instance = null; public static Test getInstance() { if (instance == null) { instance = new Test(); return instance; } } } 18、编程输出一个目录下的所有目录及文件名称,目录之间用tab。(笔试) 19、从键盘读入10个整数,然后从大到小输出。(笔试) 20、如何迭代Map容器,手写个试试? 答案: 文案大全 实用标准文档 1、 8 2、 i1 + i2 = 1010 语法错误 i1 * i2 = 100 i1 / i2 = 1 4、 5 19 6、 test test 8、 true false 10、 A: synchronized static是某个类的范围,synchronized static cSync{}防止多个线程同时访问这个类中的synchronized static 方法。它可以对类的所有对象实例起作用。 B: synchronized 是某实例的范围,synchronized isSync(){}防止多个线程同时访问这个实例中的synchronized 方法。 12、 true false true 14、 0 16、 B 3、 string 5、 12 11.0 12.0 7、 test.Test test.Base 9、 1 2 false 11、 true false 13、 false 15、 two five one three four 17、 getInstance 无默认返回值 instance 必须是static 18、 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 + \"\\"); } } } } 19、 package test; import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意这里的数组,不是int的 Integer[] arr = new Integer[10]; for (int i = 0; i < 10; i++) { arr[i] = in.nextInt(); } Arrays.sort(arr, new Comparator 实用标准文档 import java.util.Map; import java.util.Map.Entry; import java.util.Set; public class Test { public static void main(String[] args) { Map 文案大全 因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- oldu.cn 版权所有 浙ICP备2024123271号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务