SCJP认证考试题库1Word格式.docx
《SCJP认证考试题库1Word格式.docx》由会员分享,可在线阅读,更多相关《SCJP认证考试题库1Word格式.docx(6页珍藏版)》请在冰豆网上搜索。
●第九部分:
JavaSE实用API
QUESTION1
Giventhecodeintheexhibit.
Whatistheresult?
A.Compilationfails
B.Anexceptionisthrownatruntime.
C.AninstanceofForestisserialized.
D.AninstanceofForestandaninstanceofTreearebothserialized.
Answer:
(B)
执行时期会抛出java.io.NotSerializableExcetpion异常。
Tree必须实现Serialized接口;
因为Forest实现了序列化,并且引用了Tree,但是Tree没有实现序列化!
!
当一个实现序列化的类在类体里调用另外一个类的时候,那么另外一个类也要实现序列化!
如果没有实现,则会报出运行时异常!
!
如果要实现序列化,他的成员变量也必须实现序列化.本题中Tree没有实现序列化,所以会产生java.io.NotSerializableException的运行异常!
参考大纲:
IO操作—对象的序列化
序列化的过程就是对象写入字节流和从字节流中读取对象。
见SCJP.u1.SerializableTest
QUESTION2
Whichcode,insertedatline14,willallowthisclasstocorrectlyserializedand
desterilized?
A.s.defaultReadObject();
B.this=s.defaultReadObject();
C.y=s.default();
x=s.readInt();
D.x=s.readInt();
y=s.readInt();
(D)
在反序列化方法中,从s对象中读取两个整数.序列化是写对象,反序列化是读对象…
QUESTION3
Giventheexhibit.
A.0
B.1
C.4
D.Compilationfails
E.Anexceptionisthrownatruntime
(D)
产生illegalescapecharacter非法转意符的编译错误
split()字符切割器
本题是想用空格来分割字符串,只能用“”或者“\\s”来分割,“\s”没有这个转意字符!
所以会报编译错误……
tab可以用“\t”;
“\”可以用”\\”表示.
String的split方法用来分割字符串,这个方法接受一个正则表达式,根据表达式来分割,“\\s”表示空格,“\s”没有这个转意字符,所以会产illegal
escapecharacter的编译错误。
实用API—String的split()方法和正则表达式
QUESTION4
Giventheexhibit:
ThevariabledfisanobjectoftypeDateFormatthathasbeeninitializedinline11.
WhatistheresultifthiscodeisrunonDecember14,2000?
A.ThevalueofSis14-dic-2004
B.ThevalueofSisDec14,2000
C.Anexceptionisthrownatruntime
D.Compilationfailsbecauseofanerrorinline13.
DateFormat用来格式日期,它放在java.text包里,它没有setLocale方法,Local.Ialy应该为Locale.ITALY.
代码语法有问题,,编译错误!
实用API—java.util包和java.text包
QUESTION5
ThedoesFileExistmethodtakesanarrayofdirectorynamesrepresentingapath
fromtherootfilesystem
and
afilename.Themethodreturnstrueifthefileexists,
falseifdoesnot.
Placethecodefragmentsinpositiontocompletethismethod.
(
)
publicstaticbooleandoesFileExist(String[]directories,Stringfilename){
Stringpath="
"
;
for(Stringdir:
directories){
path=path+File.separator+dir;
}
Filefile=newFile(path,filename);
returnfile.exists();
IO操作—File
QUESTION6
Given:
System.out.printf("
Piisapproximately%fandEisapproximately%b"
Math.PI,Math.E);
Placethevalueswheretheywouldappearintheoutput.
3.141593
True
-----------判断E是否是NULL,
NULL是FALSE否则是TRUE.
Pi=3.1415926…….
E=2.718282……
Printf()是C中常用的语法;
%f表示浮点数(小数点后6位),
%b表示boolean,
%d表示整数.
%e十进制的科学计数法表示浮点数
%a
16进制表示浮点型科学计数法的整数部分,以10进制表示指数
%0以8进制表示整数
%x
以16进制表示整数
%s
字符串个数输出
%c
char型格式输出,提供的值应为整数型
%t
输出日期时间的前置
?
?
实用API—Formatter格式化输出工具
QUESTION7
Whencomparing
java.io.BufferedWriterto
java.io.FileWriter,whichcapability
existasamethodinonlyoneofthetwo?
A.closingthestream
B.flushingthestream
C.writingtothestream
D.markingalocationinthestream
E.writingalineseparatortothestream
(E)
只有BufferedWriter具有newLine()方法;
Reader才有mark功能。
I/O操作—BufferWriter和FileWriter
QUESTION8
Whichtwocodefragments,insertedindependentlyatline3,generatetheoutput
4247?
(choosetwo)
A.Strings="
123456789"
;
s.=(s-"
123"
).replace(1,3,"
24"
)-"
89"
//String中只有”+”表示连接,但是无”-”;
产生poerator-cannotbeappliedtojava..lang.String的编译错误
B.StringBuffers=newStringBuffer("
);
s.delete(0,3).replace(1,3,"
).delete(4,6);
//delete(0,3)表示从0下标开始删除到3下标以前
C.StringBuffers=newStringBuffer("
s.substring(3,6).delete(1,3).insert(1,"
).Substring()回传的是一个String而不是StringBuffer,String没有delete方法,产生cannotfindsymbol的编译错误
D.StringBuilders=newStringBuilder("
s.substring(3,6)delete(1,2).insert(1,"
)错误同上
E.StringBuilders=newStringBuilder("
s.delete(0,3)replace(1,3,””).delete(2,5).insert(1,"
)
(B,E)
A,String没有“-”运算符;
String不能修改!
B,正确4247
C,S.substring返回的是String,String没有delete()方法
继续阅读