SCJP认证考试题库1.docx
- 文档编号:6944131
- 上传时间:2023-01-12
- 格式:DOCX
- 页数:6
- 大小:351.40KB
SCJP认证考试题库1.docx
《SCJP认证考试题库1.docx》由会员分享,可在线阅读,更多相关《SCJP认证考试题库1.docx(6页珍藏版)》请在冰豆网上搜索。
SCJP认证考试题库1
●考试大纲
●第一部分:
Java语言基础
●第二部分:
流程控制
●第三部分:
面向对象封装,继承,多态
●第四部分:
异常处理
●第五部分:
多线程
●第六部分:
Java垃圾回收机制
●第七部分:
JavaI/O
●第八部分:
Java集合和泛型
●第九部分:
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();
Answer:
(D)
在反序列化方法中,从s对象中读取两个整数.序列化是写对象,反序列化是读对象…
参考大纲:
IO操作—对象的序列化
QUESTION3
Giventheexhibit.
Whatistheresult?
A.0
B.1
C.4
D.Compilationfails
E.Anexceptionisthrownatruntime
Answer:
(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.
Answer:
(D)
DateFormat用来格式日期,它放在java.text包里,它没有setLocale方法,Local.Ialy应该为Locale.ITALY. 代码语法有问题,,编译错误!
参考大纲:
实用API—java.util包和java.text包
QUESTION5
ThedoesFileExistmethodtakesanarrayofdirectorynamesrepresentingapath
fromtherootfilesystem and afilename.Themethodreturnstrueifthefileexists,
falseifdoesnot.
Placethecodefragmentsinpositiontocompletethismethod.
Answer:
( )
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.
Answer:
( )
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
Answer:
(E)
只有BufferedWriter具有newLine()方法;Reader才有mark功能。
参考大纲:
I/O操作—BufferWriter和FileWriter
QUESTION8
Giventheexhibit:
Whichtwocodefragments,insertedindependentlyatline3,generatetheoutput
4247?
(choosetwo)
A.Strings="123456789";
s.=(s-"123").replace(1,3,"24")-"89";//String中只有”+”表示连接,但是无”-”;产生poerator-cannotbeappliedtojava..lang.String的编译错误
B.StringBuffers=newStringBuffer("123456789");
s.delete(0,3).replace(1,3,"24").delete(4,6);//delete(0,3)表示从0下标开始删除到3下标以前
C.StringBuffers=newStringBuffer("123456789");
s.substring(3,6).delete(1,3).insert(1,"24").Substring()回传的是一个String而不是StringBuffer,String没有delete方法,产生cannotfindsymbol的编译错误
D.StringBuilders=newStringBuilder("123456789");
s.substring(3,6)delete(1,2).insert(1,"24")错误同上
E.StringBuilders=newStringBuilder("123456789");
s.delete(0,3)replace(1,3,””).delete(2,5).insert(1,"24")
Answer:
(B,E)
A,String没有“-”运算符;String不能修改!
B,正确4247
C,S.substring返回的是String,String没有delete()方法
继续阅读
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- SCJP 认证 考试 题库