java学习笔记课后选择答案整理 下载本文

第一章

1哪个组织负责监督审察Java相关技术规格的演进?

? A、JCP ? B、Apache ? C、EU ? D、W3C

2Java技术规格必须以何种正式文件提交审察?

? A、RFC ? B、JSR ? C、ISO ? D、IEEE

3Java的原始码扩展名为何?编译完后是哪个扩展名?

? A、*.txt、*.java ? B、*.c、*.class ? C、*.java、*.class ? D、*.cpp、*.java

4对JVM来说,可执行文件案的扩展名为何?

? A、*.java ? B、*.class ? C、*.dll ? D、*.pyc

5在Java下载页面中,可看到JRE下载选项,这是哪种JRE?

? A、Web JRE ? B、Private JRE ? C、Server JRE ? D、Public JRE

6在Java下载页面中,哪个下载选项安装后,会有javac编译程序可以使用?

? A、JDK ? B、JRE ? C、JavaDoc ? D、NetBeans

7如果只是要运行Java程序,下载程序哪个安装即可

? A、JDK ? B、JRE ? C、JavaDoc

? D、NetBeans

8Java根据应用领域不同,区分为哪三大平台?

? A、Java SE ? B、Java EE ? C、Java ME ? D、Android

9哪些平台不在Java规范之中?

? A、Java ME ? B、Android ? C、iOS ? D、AVI

10以下哪些包括在JRE之中?

? A、开发工具程序 ? B、Java SE API ? C、JVM ? D、部署技术

第二章

1如果在hello.java中撰写以下的程序代码: public class Hello {

publicstaticdmain(String[]args) {

System.out.println(\ } }

以下描述何者正确?

? A、执行时显示Hello World

? B、执行时出现NoClassDefFoundError

? C、执行时出现出现找不到主要方法的错误 ? D、编译失败

2如果在Main.java中撰写以下的程序代码: public class Main {

public static main(String[] args) { System.out.println(\ } }

以下描述何者正确?

? A、执行时显示Hello World

? B、执行时出现NoClassDefFoundError ? C、执行时出现找不到主要方法的错误 ? D、编译失败

3如果在Main.java中撰写以下的程序代码: public class Main {

public static void main() {

System.out.println(\ } }

以下描述何者正确?

? A、执行时显示Hello World

? B、执行时出现NoClassDefFoundError

? C、执行时出现出现找不到主要方法的错误 ? D、编译失败

4如果在Main.java中撰写以下的程序代码: public class Main {

public static void main(string[] args) { System.out.println(\ } }

以下描述何者正确?

? A、执行时显示Hello World

? B、执行时出现NoClassDefFoundError

? C、执行时出现出现找不到主要方法的错误 ? D、编译失败

5如果C:\\workspace\\Hello\\classes中有以下原始码编译而成的Main.class: public class Main {

public static void main(String[] args) { System.out.println(\ } }

文本模式下你的工作路径是C:\\workspace,那么如何执行Main类别?

? A、java C:\\workspace\\Hello\\classes\\Main ? B、java Hello\\classes Main ? C、java –cp Hello\\classes Main ? D、以上皆非

6如果C:\\workspace\\Hello\\classes中有以下原始码编译而成的Main.class: package cc.openhome; public class Main {

public static void main(String[] args) { System.out.println(\ }

}

文本模式下你的工作路径是C:\\workspace,那么如何执行Main类别?

? A、java C:\\workspace\\Hello\\classes\\Main ? B、java Hello\\classes Main ? C、java –cp Hello\\classes Main ? D、以上皆非

7如果有个Console类别的原始码开头定义如下: package cc.openhome; public class Console { ... }

其完全吻合名称为何?

? A、cc.openhome.Console

? B、package.cc.openhome.Console ? C、cc.openhome.class.Console ? D、以上皆非 正确答案: A

8如果C:\\workspace\\Hello\\src中有Main.java如下: package cc.openhome; public class Main {

public static void main(String[]args) { System.out.println(\ } }

文本模式下你的工作路径是C:\\workspace\\Hello,那么如何编译与执行Main类别?

? A、javac src\\Main.java java C:\\workspace\\Hello\\classes\\Main ? B、javac –d classes src\\Main.java java –cp classes Main

? C、javac –d classes src\\Main.java java –cp classes cc.openhome.Main ? D、javac –d classes src\\Main.java java –cp classesccopenhome Main

9如果有个Console类别的原始码开头定义如下: package cc.openhome; public class Console { ... }

如何在另一个类别中撰写import?

? A、import cc.openhome.Console; ? B、import cc.openhome; ? C、import cc.openhome.*; ? D、import Console;

10关于包以下何者正确?

? A、要使用Java SE API的System类别必须import java.lang.System;

? B、在程序中撰写import java.lang.System;会发生编译错误,因为java.lang中的类别不用import

? C、import并不影响执行效能

? D、程序中撰写了import cc.openhome.Main,执行java指令时只要下java Main就可以了

第三章

1如果有以下的程序代码: int number;

System.out.println(number); 以下描述何者正确?

? A、执行时显示0

? B、执行时显示随机数字 ? C、执行时出现错误 ? D、编译失败

2如果有以下的程序代码:

System.out.println(10 / 3); 以下描述何者正确?

? A、执行时显示3 ? B、执行时显示3.33333... ? C、执行时出现错误 ? D、编译失败

3如果有以下的程序代码: float radius = 88.2;

double area= 2 * 3.14 * radius * radius; System.out.println(area); 以下描述何者正确?

? A、执行时显示48853.6272 ? B、执行时显示48853 ? C、执行时出现错误 ? D、编译失败 正确答案: D

4如果有以下的程序代码: byte a = 100; byte b = 200;

byte c = (byte) (a + b);

System.out.println(c); 以下描述何者正确?

? A、执行时显示300 ? B、执行时显示127 ? C、执行时出现错误 ? D、编译失败

5如果有以下的程序代码:

System.out.println(Integer.MAX_VALUE + 1 == Integer.MIN_VALUE); 以下描述何者正确?

? A、执行时显示true ? B、执行时显示false ? C、执行时出现错误 ? D、编译失败

6如果有以下的程序代码:

System.out.println(-Integer.MAX_VALUE == Integer.MIN_VALUE); 以下描述何者正确?

? A、执行时显示true ? B、执行时显示false ? C、执行时出现错误 ? D、编译失败

7如果有以下的程序代码: int i = 10;10 int number = i++; number = --i; 以下描述何者正确?

? A、执行后number为10,i为10 ? B、执行后number为10,i为11 ? C、执行后number为11,i为10 ? D、执行后number为11,i为11

8如果有以下的程序代码: int i = 10;

int number = ++i; number = ++i; 以下描述何者正确?

? A、执行后number为11,i为11 ? B、执行后number为11,i为12 ? C、执行后number为12,i为11 ? D、执行后number为12,i为12

9如果有以下的程序代码:

for(int i = 1; i < 10; i++) { if(i == 5) { continue; }

System.out.printf(\ 以下描述何者正确?

? A、显示i =1到4,以及6到9 ? B、显示i =1到9 ? C、显示i =1到4 ? D、显示i = 6到9

10如果有以下的程序代码:

for(int number = 0; number != 5; number = (int) (Math.random() * 10)) { System.out.println(number); }

以下描述何者正确?

? A、执行时显示数字永不停止 ? B、执行时显示数字0后停止 ? C、执行时显示数字5后停止

? D、执行时显示数字直到number为5后停止

第四章

1如果有以下的程序代码: int x = 100; int y = 100; Integer wx = x; Integer wy = y;

System.out.println(x == y); System.out.println(wx == wy);

在JDK5以上的环境编译与执行,请问显示结果为何?

? ? ? ?

A、true、true B、true、false C、false、true D、编译失败

2如果有以下的程序代码: int x = 200; int y = 200; Integer wx = x; Integer wy = y;

System.out.println(x == wx); System.out.println(y == wy);

在JDK5以上的环境编译与执行,请问显示结果为何?

? ? ? ?

A、true、true B、true、false C、false、true D、编译失败

3如果有以下的程序代码: int x = 300; int y = 300; Integer wx = x; Integer wy = y;

System.out.println(wx.equals(x)); System.out.println(wy.equals(y)); 以下描述何者正确?

? ? ? ?

A、true、true B、true、false C、false、true D、编译失败

4如果有以下的程序代码: int[] arr1 = {1, 2, 3}; int[] arr2 = arr1; arr2[1] = 20;

System.out.println(arr1[1]); 以下描述何者正确?

? ? ? ?

A、执行时显示2 B、执行时显示20

C、执行时出现ArrayIndexOutOfBoundException错误 D、编译失败

5如果有以下的程序代码: int[] arr1 = {1, 2, 3};

int[] arr2 = new int[arr1.length]; arr2 = arr1;

for(int value : arr2) {

System.out.printf(\ }

以下描述何者正确?

? ? ? ?

A、执行时显示123 B、执行时显示12300

C、执行时出现ArrayIndexOutOfBoundException错误 D、编译失败

6如果有以下的程序代码:

String[] strs = new String[5]; 以下描述何者正确?

? ? ? ?

A、产生5个String实例 B、产生1个String实例 C、产生0个String实例 D、编译失败

7如果有以下的程序代码:

String[] strs = {\以下描述何者正确?

? ? ? ?

A、产生5个String实例 B、产生1个String实例 C、产生0个String实例 D、编译失败

8如果有以下的程序代码:

String[][] strs = new String[2][5]; 以下描述何者正确?

? ? ? ?

A、产生10个String实例 B、产生2个String实例 C、产生0个String实例 D、编译失败

9如果有以下的程序代码: String[][] strs = {

{\

{\};

System.out.println(strs.length); System.out.println(strs[0].length); System.out.println(strs[1].length); 以下描述何者正确?

? ? ? ?

A、显示2、3、4 B、显示2、0、1 C、显示1、2、3 D、编译失败

10如果有以下的程序代码: String[][] strs = {

{\

{\};

for(________row : strs) {

for(________str : row) { .... } }

空白处应该分别填上什么?

? ? ? ?

A、String、String B、String、String[] C、String[]、String D、String[]、String[]

第五章

1

如果有以下程序片段: public class Some {

private Some some; private Some() {}

public static Some create() { if(some == null) {

some = new Some(); }

return some; } }

以下描述何者正确?

? A、 编译失败 ? B、 客户端必须new Some()产Some生实例

? C、 客户端必须new Some().create()产生Some实例 ? D、 客户端必须Some.create()产生Some实例

2 如果有以下程序片段:

int[] scores1 = {88, 81, 74, 68, 78, 76, 77, 85, 95, 93}; int[] scores2 = Arrays.copyOf(scores1, scores1.length);

其中Arrays完全吻合名称为java.util.Arrays,以下描述何者正确?

? A、 Arrays.copyOf()应该改为new Arrays().copyOf() ? B、 copyOf()是static成员 ? C、 copyOf()是public成员 ? D、 Arrays被宣告为public

3 如果有以下程序片段: public class Some { public int x;

public Some(int x) { this.x = x; } }

以下描述何者正确?

? A、 建构Some时,可使用new Some()或new Some(10)形式 ? B、 建构Some时,只能使用new Some()形式 ? C、 建构Some时,只能使用newSome(10)形式 ? D、 没有无自变量建构式,所以编译失败

4 如果有以下程序片段: public class Some { public int x;

public Some(int x) { x = x; } }

以下描述何者正确?

? A、 new Some(10)建构对象后,对象成员x值为10 ? B、 new Some(10)建构对象后,对象成员x值为0 ? C、 Some s = new Some(10)后,可使用s.x取得值 ? D、 编译失败

5 如果有以下程序片段: public class Some { private int x; public Some(int x) { this.x = x; } }

以下描述何者正确?

? A、 new Some(10) 建构物件后,成员 x值为 10 ? B、 new Some(10) 建构物件后,成员 x值为 0

? C、 Some s = new Some(10) 后,可使用 s.x 取得值 ? D、 编译失败

6 如果有以下程序片段: package cc.openhome.util; class Some {

public int x;

public Some(int x) {

this.x = x; } }

以下描述何者正确?

? A、 cc.openhome.util 套件中其它程序代码可以 new Some(10) ? B、 cc.openhome.util 套件外其它程序代码可以 new Some(10) ? C、 可以在其它套件 import cc.openhome.util.Some; ? D、 编译失败 7

如果有以下程序片段: public class Some {

private final int x;

public Some() {} public Some(int x) { this.x = x; } }

以下描述何者正确?

? A、 new Some(10)建构对象后,对象成员x值为10 ? B、 new Some(10)建构对象后,对象成员x值为0 ? C、 Some s = new Some(10)后,可使用s.x取得值 ? D、 编译失败

8 如果有以下程序片段: public class Some {

public static int sum(int... numbers) { int sum = 0;

for(int i = 10; i < numbers.length; i++) { sum += numbers[i];20 }

return sum; } }

以下描述何者正确?

? A、 可使用Some.sum(1, 2, 3)加总1、2、3 ? B、 可使用new Some.sum(1, 2, 3)加总1、2、3 ? C、 可使用Some.sum(new int[1,2, 3])加总1、2、3 ? D、 编译失败,因为不定长度自变量只能用增强式for循环语法 9

如果有以下程序片段: public class Some {

public static void someMethod(int i) {

System.out.println(\版本被呼叫\ }

public static void someMethod(Integer integer) { System.out.println(\版本被呼叫\ } }

以下描述何者正确?

? A、 Some.someMethod(1)显示「int版本被呼叫」 ? B、 Some.someMethod(1)显示「Integer版本被呼叫」

? C、 Some.someMethod(new Integer(1))显示「int版本被呼叫」 ? D、 编译失败

10 如果有以下程序片段: public class Main{

public intsome(int... numbers) { int sum = 0;

for(int number : numbers) { sum += number; }

return sum; }

public static void main(String[] args) { System.out.println(sum(1, 2, 3)); } }

以下描述何者正确?

? A、 显示6 ? B、 显示1 ? C、 无法执行 ? D、 编译失败

第六章

1

如果有以下程序片段: class Some {

void doService() {

System.out.println(\ } }

class Other extends Some {

@Override void doService() {

System.out.println(\ } }

public class Main {

public static void main(String[] args) { Other other = new Other(); other.doService(); } }

以下描述何者正确?

? A、 编译失败

? B、 显示some service ? C、 显示other service

? D、 先显示some service、后显示other service

2 承上题,如果main()中改为: Some some = new Other(); some.doService(); 以下描述何者正确?

? A、 编译失败

? B、 显示some service ? C、 显示other service

? D、 先显示some service、后显示other service

3 如果有以下程序片段: class Some {

String ToString() {

return \ } }

public class Main {

public static void main(String[] args) { Some some= new Some(); System.out.println(some); } }

以下描述何者正确?

? A、 显示Some instance

? B、 显示Some@XXXX,XXXX为16进位数字 ? C、 发生ClassCastException ? D、 编译失败

4 如果有以下程序片段: class Some {

int hashCode() { return 99; } }

public class Main {

public static void main(String[] args) { Some some = new Some();

System.out.println(some.hashCode()); } }

以下描述何者正确?

? A、 显示99 ? B、 显示0

? C、 发生ClassNotFoundException ? D、 编译失败

5 如果有以下程序片段: class Some { @Override

String ToString() {

return \ } }

public class Main {

public static void main(String[] args) { Some some = new Some(); System.out.println(some); } }

以下描述何者正确?

? A、 显示Some instance

? B、 显示Some@XXXX,XXXX为16进位数字 ? C、 发生ClassCastException ? D、 编译失败 6

如果有以下程序片段: class Some {

abstract void doService(); }

class Other extends Some { @Override

void doService() {

System.out.println(\ } }

public class Main {

public static void main(String[] args) { Some some = new Other(); some.doService(); } }

以下描述何者正确?

? A、 编译失败

? B、 显示other service

? C、 执行时发生ClassCastException ? D、 移除@Override可编译成功

7

如果有以下程序片段: class Some {

protected int x; Some(int x) { this.x = x; } }

class Other extends Some { Other(int x) { this.x = x; } }

以下描述何者正确?

? A、 new Other(10)后,物件成员x值为10 ? B、 new Other(10)后,物件成员x值为任意值 ? C、 Other中无法存取x的编译失败

? D、 Other中无法呼叫父类别建构式的编译失败

8 如果有以下程序片段:

public class IterableString extends String { public IterableString(String original) { super(original); }

public void iterate() { //... } }

以下描述何者正确?

? A、 String s = new IterableString(\可通过编译

? B、 IterableString s = new IterableString(\可通过编译 ? C、 因无法呼叫super()的编译失败 ? D、 因无法继承String的编译失败

9 如果有以下程序片段: class Some { Some() {

System.out.println(\ this(10); }

Some(int x) {

System.out.println(\ }

}

class Other extends Some {Other() { super(10);

System.out.println(\ }

Other(int y) {

System.out.println(\ } }

以下描述何者正确?

? A、 new Other()显示\、\ ? B、 new Other(10)显示\

? C、 newSome()显示\、\ ? D、 编译失败 10

如果有以下程序片段: class Some { Some() { this(10);

System.out.println(\ }

Some(int x) {

System.out.println(\ } }

class Other extends Some { Other() { super(10);

System.out.println(\ }

Other(int y) {

System.out.println(\ } }

以下描述何者正确?

? A、 new Other()显示\、\

? B、 new Other(10)显示\、\、\ ? C、 new Some()显示\、\ ? D、 编译失败

第七章

1 如果有以下程序片段: interface Some {

protected void doSome(); }

class SomeImpl implements Some { public void doSome() {

System.out.println(\作一些事\ } }

public class Main {

public static void main(String[] args) { Some s = new SomeImpl(); s.doSome(); } }

以下描述何者正确?

? A、 编译失败

? B、 显示\作一些事\

? C、 发生ClassCastException ? D、 执行时不显示任何讯息 2

如果有以下程序片段: interface Some { int x = 10; }

public class Main {

public static void main(String[] args) { System.out.println(Some.x); } }

以下描述何者正确?

? A、 编译失败 ? B、 显示10

? C、 必须建构Some实例才能存取x ? D、 显示0

3 如果有以下程序片段: interface Some { void doSome(); }

class SomeImpl implements Some { void doSome() {

System.out.println(\作一些事\ } }

public class Main {

public static void main(String[] args) { Some s = new SomeImpl(); s.doSome(); } }

以下描述何者正确?

? A、 编译失败

? B、 显示\作一些事\

? C、 发生ClassCastException ? D、 执行时不显示任何讯息 4

如果有以下程序片段: interface Some { void doSome(); }

class SomeImpl implements Some { public void doSome() {

System.out.println(\作一些事\ } }

public class Main {

public static void main(String[] args) { Some s = new SomeImpl(); s.doSome(); } }

以下描述何者正确?

? A、 编译失败

? B、 显示\作一些事\

? C、 发生ClassCastException ? D、 执行时不显示任何讯息

5 如果有以下程序片段: interface Some { void doSome(); }

interface Other { void doOther(); }

class SomeOtherImpl implements Some, Other { public void doSome() {

System.out.println(\作一些事\}

public void doOther() {

System.out.println(\作其它事\ } }

public class Main {

public static void main(String[] args) { Some s = new SomeOtherImpl(); s.doSome();Other o = (Other) s; o.doOther(); } }

以下描述何者正确?

? A、 编译失败

? B、 显示\作一些事\、\作其它事\ ? C、 发生ClassCastException ? D、 执行时不显示任何讯息 6

如果有以下程序片段: interface Some { void doSome(); }

abstract class AbstractSome implements Some { public abstract void doSome(); public void doService() {

System.out.println(\作一些服务\ } }

public class Main {

public static void main(String[] args) { AbstractSome s = new AbstractSome(); s.doService();

} }

以下描述何者正确?

? A、 编译失败

? B、 显示\作一些服务\

? C、 发生ClassCastException ? D、 执行时不显示任何讯息 正确答案: A

7 如果有以下程序片段: interface Some { void doSome(); }

abstract class AbstractSome implements Some { public abstract void doSome(); public void doService() {

System.out.println(\作一些服务\ } }

public class Main {

public static void main(String[] args) { AbstractSome s = new AbstractSome() { public void doSome() {

System.out.println(\作一些事\ }

public void doService() {} };

s.doService(); } }

以下描述何者正确?

? A、 编译失败

? B、 显示\作一些服务\

? C、 发生ClassCastException ? D、 执行时不显示任何讯息

8 如果有以下程序片段: interface Some { void doSome(); }

public class Main {

public static void main(String[] args) { Some s = new Some() { public void doSome() {

System.out.println(\作一些事\ }

public void doService() {

System.out.println(\作一些服务\ } };

s.doService(); } }

以下描述何者正确?

? A、 编译失败

? B、 显示\作一些服务\

? C、 发生ClassCastException ? D、 执行时不显示任何讯息 9

如果有以下程序片段: interface Some {

protected static final int x = 10; }

public class Main {

public static void main(String[] args) { System.out.println(Some.x); } }

以下描述何者正确?

? A、 编译失败 ? B、 显示10

? C、 必须建构Some实例才能存取x ? D、 显示0

10 如果有以下程序片段: interface Some { void doSome(); void doService() {

System.out.println(\作一些服务\ } }

class SomeImpl implements Some { public void doSome() {

System.out.println(\作一些事\ } }

public class Main {

public static void main(String[] args) { Some s = new SomeImpl(); s.doSome(); s.doService(); } }

以下描述何者正确?

? A、 编译失败

? B、 显示\作一些事\、\作一些服务\ ? C、 发生ClassCastException ? D、 执行时不显示任何讯息

第八章

1 如果有以下程序片段: public class Main {

public static void main(String[] args) { try {

int number = Integer.parseInt(args[0]); System.out.println(number++);

} catch(NumberFormatException ex) { System.out.println(\必须输入数字\ } } }

执行时若没有指定命令行自变量,以下描述何者正确?

? A、 编译错误

? B、 显示\必须输入数字\

? C、 显示ArrayIndexOutOfBoundException堆栈追踪 ? D、 不显示任何讯息

2 如果有以下程序片段: public class Main {

public static void main(String[] args) { Object[] objs = {\

Integer number = (Integer) objs[1]; System.out.println(number); } }

根据图8.2,以下描述何者正确?

? A、 编译错误 ? B、 显示7

? C、 显示ClassCastException堆栈追踪 ? D、 不显示任何讯息 3

如果有以下程序片段: public class Main {

public static void main(String[] args) { try {

int number = Integer.parseInt(args[0]); System.out.println(number++);

} catch(NumberFormatException ex) { System.out.println(\必须输入数字\ } } }

执行时若指定命令行自变量one,以下描述何者正确?

? A、 编译错误

? B、 显示\必须输入数字\

? C、 显示ArrayIndexOutOfBoundException堆栈追踪 ? D、 不显示任何讯息 正确答案: B

4

FileInputStream的建构式使用throws宣告了FileNotFoundException,如果有以下程序片段: public class FileUtil {

public static String readFile(String name) throws ______________ { FileInputStream input = new FileInputStream(name); ... } }

请问空格处填入以下哪些选项可以通过编译?

? A、 Throwable ? B、 Error

? C、 IOException

? D、 FileNotFoundException 5

FileInputStream的建构式使用throws宣告了FileNotFoundException,如果有以下程序片段: public class FileUtil {

public static String readFile(String name) { FileInputStream input = null; try {

input = new FileInputStream(name); ...

} catch(_____________________ ex) { ... } } }

请问空格处填入以下哪些选项可以通过编译?

? A、 Throwable ? B、 Error

? C、 IOException

? D、 FileNotFoundException

6 如果有以下程序片段: class Resource {

void doService() throws IOException { ... } }

class Some extends Resource { @Override

void doService() throws __________________{ ... } }

请问空格处填入以下哪些选项可以通过编译?

? A、 Throwable ? B、 Error

? C、 IOException

? D、 FileNotFoundException

7 如果有以下程序片段: public class Main {

public static void main(String[] args) { try {

int number = Integer.parseInt(args[0]); System.out.println(number++);

} catch(ArrayIndexOutOfBoundException | NumberFormatException ex) { System.out.println(\必须输入数字\ } } }

执行时若没有指定命令行自变量,以下描述何者正确?

? A、 编译错误

? B、 显示\必须输入数字\

? C、 显示ArrayIndexOutOfBoundException堆栈追踪 ? D、 不显示任何讯息

8 如果有以下程序片段: public class Main {

public static void main(String[] args) { try {

int number = Integer.parseInt(args[0]); System.out.println(number++);

} catch(RuntimeException | NumberFormatException ex) { System.out.println(\必须输入数字\ } } }

执行时若没有指定命令行自变量,以下描述何者正确?

? A、 编译错误

? B、 显示\必须输入数字\

? C、 显示ArrayIndexOutOfBoundException堆栈追踪 ? D、 不显示任何讯息 正确答案: A 9

FileInputStream的建构式使用throws宣告了FileNotFoundException,如果有以下程序片段: public class FileUtil {

public static String readFile(String name) {

try(FileInputStream input = new FileInputStream(name)) { ... } } }

以下描述何者正确?

? A、 编译失败 ? B、 编译成功

? C、 呼叫readFile时必须处理FileNotFoundException

? D、 呼叫readFile时不一定要处理FileNotFoundException

10 如果ResourceSome与ResourceOther都实作了AutoCloseable接口: publicclass Main {

public static void main(String[] args) {

try(ResourceSome some = new ResourceSome(); ResourceOther other = new ResourceOther()) { ... } } }

以下描述何者正确?

? A、 执行完try后会先关闭ResourceSome ? B、 执行完try后会先关闭ResourceOther

? C、 执行完main后才关闭ResourceSome与ResourceOther ? D、 编译失败

第九章

1

如果有以下程序片段: import java.util.*; public class Main {

public static void main(String[] args) { foreach(new HashSet()); foreach(new ArrayList()); }

private static void foreach(___________ elements) { for(Object o : elements) { ... } } }

空白部份指定哪些型态可以通过编译?

? A、 HashSet ? B、 ArrayList ? C、 Collection ? D、 Iterable

2

如果有以下程序片段: import java.util.*; public class Main {

public static void main(String[] args) { foreach(new_____________()); }

private static void foreach(Iterable iterable) { for(Object o : iterable) { ... } } }

空白部份指定哪些型态可以通过编译?

? A、 HashSet ? B、 ArrayList ? C、 Collection ? D、 Iterable 3

如果有以下程序片段: import java.util.*; public class Main {

public static void main(String[] args) { foreach(new HashSet()); }

private static void foreach(Collection collection) { __________ elements =collection.iterator(); while(elements.hasNext()) {

System.out.println(elements.next()); } } }

空白部份指定哪些型态可以通过编译?

? A、 List ? B、 Set ? C、 Iterator ? D、 Iterable

4

如果有以下程序片段: import java.util.*; class Student { String number; String name; int score;

Student(String number, String name, int score) { this.number = number; this.name= name; this.score= score; } }

public class Main {

public static void main(String[] args) { Setstudents= new TreeSet<>();

students.add(new Student(\ students.add(new Student(\ ...

foreach(students); }

private static void foreach(Collectionstudents) { for(Student student : students) {

System.out.println(student.score); } } }

以下描述何者正确?

? A、 依score从小至大显示结果

? B、 依toString自然排序由小至大显示结果 ? C、 依hashCode自然排序由小至大显示结果 ? D、 抛出ClassCastException

5 如果有以下程序片段: import java.util.*; class Student { String number; String name; int score;

Student(String number, String name, int score) { this.number = number; this.name= name; this.score= score; } }

public class Main {

public static void main(String[] args) { Setstudents= new HashSet<>();

students.add(new Student(\ students.add(new Student(\ students.add(new Student(\ students.add(new Student(\ students.add(new Student(\ System.out.println(students.size()); } }

以下描述何者正确?

? A、 显示2 ? B、 显示3 ? C、 显示4 ? D、 显示5

6 如果有以下程序片段: import java.util.*; public class Main {

public static void main(String[] args) { Setnumbers= new TreeSet<>(); numbers.add(1); numbers.add(2); numbers.add(1); numbers.add(3); foreach(numbers); }

private static void foreach(Collectionnumbers) { for(Integer number : numbers) { System.out.println(number);

} } }

以下描述何者正确?

? A、 从小至大显示数字结果 ? B、 从大至小显示数字结果 ? C、 编译失败

? D、 抛出ClassCastException

7 关于增强式for循环语法,可适用于以下哪些型态?以下描述何者正确?

? A、 数组 ? B、 List ? C、 Set ? D、 Map 8

如果有以下程序片段: import java.util.*; publicclass Main {

public static void main(String[] args) { Set numbers = new TreeSet(); numbers.add(1); numbers.add(2); numbers.add(1); numbers.add(3);

for(Integer number : numbers) { System.out.println(number); } } }

以下描述何者正确?

? A、 从小至大显示数字结果 ? B、 从大至小显示数字结果 ? C、 编译失败

? D、 抛出ClassCastException

9 如果有以下程序片段: import java.util.*; public class Main {

public static void main(String[] args) {

Set<____________> numbers = new TreeSet<>(); numbers.add(1); numbers.add(2);

numbers.add(1); numbers.add(3);

for(Integer number : numbers) { System.out.println(number); } } }

空白处要填入何种型态才可编译成功? -->

? A、 Object ? B、 Long ? C、 Integer ? D、 Short 正确答案: C 10

如果有以下程序片段: import java.util.*; public class Main {

public static void main(String[] args) { Mapmessages = new HashMap<>(); messages.put(\ messages.put(\ foreach(messages.values()); }

private static void foreach(_____________ values) { for(String value : values){ System.out.println(value); } } }

空白处要填入何种型态才可编译成功?

? A、 Set

? B、 Collection ? C、 Collection ? D、 Iterable

第十章-选择题

1输入输出串流的父类别是哪两个?

? A、InputStream ? B、Reader

? C、OutputStream ? D、Writer

2处理字符输入输出的父类别是哪两个?

? A、InputStream ? B、Reader ? C、OutputStream ? D、Writer

3以下哪两个类别为InputStream、OutputStream提供缓冲区作用?

? A、BufferedInputStream ? B、BufferedReader

? C、BufferedOutputStream ? D、BufferedWriter

4以下哪两个类别为Reader、Writer提供缓冲区作用?

? A、BufferedInputStream ? B、BufferedReader ? C、BufferedOutputStream ? D、BufferedWriter

5如果有以下程序片段:

ObjectInputStream input = new ObjectInputStream(new ________________); 空白部份指定哪些型态可以通过编译?

? A、FileInputStream(\? B、FileReader(\

? C、InputStreamReader(new FileReader(\ ? D、ObjectReader(\

6如果有以下程序片段:

BufferedReader reader = new BufferedReader(new ________________); 空白部份指定哪些型态可以通过编译?

? A、FileInputStream(\ ? B、FileReader(\? C、InputStreamReader(new FileInputStream(\? D、ObjectReader(\

7以下哪两个类别分别拥有readObject()、writeObject()方法?

? A、BufferedInputStream ? B、ObjectInputStream ? C、ObjectOutputStream ? D、BufferedOutputStream

8以下哪两个类别为InputStream、OutputStream提供编码转换作用?

? A、BufferedInputStream ? B、InputStreamReade ? C、BufferedOutputStream ? D、OutputStreamWriter

9以下哪两个类别为Reader、Writer提供编码转换作用?

? A、BufferedInputStream ? B、InputStreamReader ? C、BufferedOutputStream ? D、以上皆非 正确答案: D

10以下哪些类别位于java.io套件之中?

? A、BufferedInputStream ? B、IOException ? C、Scanner

? D、BufferedReader 正确答案: ABD

第十一章

1可以实作哪个接口,建立执行流程?

? A、Runnable ? B、Thread ? C、Future ? D、Executor 2

可以继承哪个类别,定义线程执行流程?

? A、Runnable ? B、Thread ? C、Future ? D、Executor

3呼叫Thread的start()后,线程会处于哪个状态?

? A、Running ? B、Runnable ? C、Wait Blocked ? D、IO Blocked

4以下哪些方法会使线程进入阻断状态?

? A、Thread.sleep() ? B、wait() ? C、notify() ? D、interrupt()

5如果有以下程序片段:

Thread thread = new Thread(new ________________() { public void run() {...} });

空白部份指定哪些型态可以通过编译?

? A、Runnable ? B、Thread ? C、Future ? D、Executor 正确答案: AB

6呼叫线程的interrupt()方法,会抛出哪个例外对象?

? A、IOException

? B、IllegalStateException ? C、RuntimeException ? D、InterruptedException

7如果有以下程序片段: ...

public ____________ void add(Object o) { if(next == list.length) {

list = Arrays.copyOf(list, list.length * 2); }

list[next++] = o; } ...

为了确保add()在多线程存取下的线程安全,应该加上哪个关键词?

? A、abstract

? B、synchronized ? C、static

? D、volatile

8在使用高阶并行API时,哪个接口的实作对象可实现synchronized的功能?

? A、Lock ? B、Condition ? C、Future ? D、Callable

9在使用高阶并行API时,哪个接口的实作对象可实现Object的wait()、notify()、notifyAll()功能?

? A、Lock ? B、Condition ? C、Future ? D、Callable 正确答案: B 10

在使用高阶并行API时,哪个接口的实作对象可以让你于未来取得执行结果?

? A、Lock ? B、Condition ? C、Future ? D、Callable 正确答案: C

第十五章-选择题已完成

1Java日志API中,哪个类别负责实际输出?

? A、Logger ? B、Handler ? C、Filter ? D、Formatter 正确答案: B

2Java日志API中,输出的日志会经过哪两个类别的过滤?

? A、Logger ? B、Handler ? C、Formatter ? D、Stream 正确答案: AB

3国际化的三个重要观念是?

? A、地区信息 ? B、资源包

? C、基础名称(Base name) ? D、格式化 正确答案: ABC

4Date的API有许多方法都不再建议使用,应改用哪个类别的相关方法取代?

? A、DateFormat ? B、TimeStamp ? C、Time ? D、Calendar 正确答案: D

5哪个类别代表可重用的规则表示式?

? A、Pattern ? B、Matcher ? C、Glob ? D、Regex

正确答案: A 我的答案:A

第十六章-选择题已完成

1哪些JDBC驱动程序可以有跨平台的特性?

? A、TYPE 1 ? B、TYPE 2 ? C、TYPE 3 ? D、TYPE 4 正确答案: CD

2哪种JDBC驱动程序是基于数据库所提供的API来进行实作?

? A、TYPE 1 ? B、TYPE 2 ? C、TYPE 3 ? D、TYPE 4 正确答案: B

3JDBC相关接口或类别,是放在哪个套件之下加以管理?

? A、java.lang ? B、javax.sql ? C、java.sql ? D、java.util 正确答案: C

4使用JDBC时,通常会需要处理哪个受检例外(Checked Exception)?

? A、RuntimeException ? B、SQLException ? C、DBException ? D、DataException 正确答案: B

5关于Connection的描述,何者正确?

? A、可以从DriverManager上取得Connection ? B、可以从DataSource上取得Connection ? C、在方法结束之后Connection会自动关闭 ? D、Connection是线程安全(Thread-safe) 正确答案: AB

6使用Statement来执行SELECT等查询用的SQL指令时,应使用下列哪个方法?

? A、executeSQL() ? B、executeQuery() ? C、executeUpdate() ? D、executeFind() 正确答案: B

7哪个对象正确使用下,可以适当地避免SQL Injection的问题?

? A、Statement ? B、ResultSet

? C、PreparedStatement ? D、Command 正确答案: C

8取得Connection之后,如何取得Statement对象?

? A、conn.createStatement()

B、conn.buildStatement() ? C、conn.getStatement()

? D、conn.createSQLStatement() 正确答案: A 9

以下描述何者有误?

? A、使用Statement一定会发生SQL Injection

? B、使用PreparedStatement就不会发生SQL Injection ? C、不使用Connection时必须加以关闭 ? D、ResultSet代表查询的结果集合 正确答案: AB 10

使用Statement的executeQuery()方法,会传回哪个型态?

? A、int

? B、boolean ? C、ResultSet ? D、Table 正确答案: C

?

第十七章-选择题已完成

1

以下哪个类别是.class档案载入JVM后的代表?

? A、java.lang.Class

? B、java.lang.ClassLoader ? C、java.lang.Object ? D、java.lang.Definition 正确答案: A 2

以下哪个类别类别中方法的代表?

? A、java.lang.Class

B、java.lang.reflect.Constructor ? C、java.lang.reflect.Method ? D、java.lang.reflect.Field 正确答案: C

3类别加载器都继承自哪个类别?

? A、java.lang.Class

? B、java.lang.ClassLoader ? C、java.lang.Object ? D、java.lang.Definition 正确答案: B 4

以下代码段建立ClassLoader实例,其父类别加载器是? URL url = new URL(\

ClassLoader loader = new URLClassLoader(new URL[] {url});

? A、Bootstrap Loader ? B、Extended Loader ? C、System Loader ? D、null 正确答案: C 5

如果file:/d:/workspace/文件夹为空,关于以下代码段,何者描述正确? String clz1 = String.class;

URL url = new URL(\

ClassLoader loader = new URLClassLoader(new URL[] {url}); Class clz2 = loader.loadClass(\

? A、clz1与clz2参考同一实例 ? B、clz1与clz2参考不同实例 ? C、抛出ClassNotFoundException ? D、抛出NoClassDefException 正确答案: A

?