SCJP真题库更新二

SCJP真题库更新2

QUESTION 3

Given the exhibit.

 

What is the result? 

A. 0

B. 1

C. 4

D. Compilation fails    

E. An exception is thrown at runtime  

 

 

Answer: ( D )   产生illegal escape character 非法转意符 的编译错误

split()字符切割器

本题是想用空格来分割字符串,只能用“ ”或者“\\ s”来分割,“\ s”没有这个转意字符!所以会报编译错误……    

tab可以用“\ t”; \”可以用”\\”表示.

Stringsplit方法用来分割字符串,这个方法接受一个正则表达式,根据表达式来分割,\\s”表示空格,“\s”没有这个转意字符,所以会产illegal  escape  character的编译错误。

参考大纲:实用API Stringsplit()方法和正则表达式

 

QUESTION 4

Given the exhibit:

 

The variable df is an object of type DateFormat that has been initialized in line 11.

What is the result if this code is run on December 14,2000? 

A. The value of S is 14 - dic-2004

B. The value of S is Dec 14, 2000

C. An exception is thrown at runtime

D. Compilation fails because of an error in line 13.

 

 

Answer: ( D )

DateFormat用来格式日期,它放在java.text包里,它没有setLocale方法,Local.Ialy 应该为 Locale.ITALY.  代码语法有问题,,编译错误!

参考大纲:实用API java.util java.text

 

QUESTION 5

The doesFileExist method takes an array of directory names representing a path

from the root filesystem  and  a file name. The method returns true if the file exists,

false if does not.

Place the code fragments in position to complete this method.

Answer: (  )

public static boolean doesFileExist(String[] directories, String filename) {

String path = "";

for (String dir : directories) {

path = path + File.separator + dir;

}
File file = new File(path, filename);
return file.exists();

}

参考大纲:IO操作 File