java认证题库.docx

上传人:b****5 文档编号:6238166 上传时间:2023-01-04 格式:DOCX 页数:43 大小:2.68MB
下载 相关 举报
java认证题库.docx_第1页
第1页 / 共43页
java认证题库.docx_第2页
第2页 / 共43页
java认证题库.docx_第3页
第3页 / 共43页
java认证题库.docx_第4页
第4页 / 共43页
java认证题库.docx_第5页
第5页 / 共43页
点击查看更多>>
下载资源
资源描述

java认证题库.docx

《java认证题库.docx》由会员分享,可在线阅读,更多相关《java认证题库.docx(43页珍藏版)》请在冰豆网上搜索。

java认证题库.docx

java认证题库

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”没有这个转意字符,所以会产illegalescapecharacter的编译错误。

参考大纲:

实用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

fromtherootfilesystemandafilename.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十进制的科学计数法表示浮点数

%a16进制表示浮点型科学计数法的整数部分,以10进制表示指数

%0以8进制表示整数

%x以16进制表示整数

%s字符串个数输出

%cchar型格式输出,提供的值应为整数型

%t输出日期时间的前置?

参考大纲:

实用API—Formatter格式化输出工具

QUESTION7

Whencomparingjava.io.BufferedWritertojava.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()方法

D,S.substring返回的是String

E,正确4247

参考大纲:

实用API—

String、StringBuffer线程安全的适用于多线程、StringBuilder线程不安全,适合单线程,但是性能高.

StringBufferStringBuilder的用法一样

QUESTION9

Answer:

(B,D,E)

A错误,聚合中的对象实现了serializable就能被序列化一个类包含另外一个类就是聚合.A的描述和对象是否支持序列化没有直接关系

B正确java是跨平台的,序列化的工作也统一交给各个平台的jvm来处理

C错误,不是volatile而是transient;有这个transient瞬态关键字的话,就不能序列化了!

Volatile这个修饰符的变量,实现的和多线程同步的方法类似,但是不是很好用!

D正确transient瞬态的对象是不支持序列化的

E正确,只要子类实现serializable,不用考虑父类有无实现serializable

参考大纲:

IO操作—对象的序列化

QUESTION10

Giventheexhibit:

Whatistheresult?

A.shortLong

B.SHORTLONG

C.Compilationfails

D.Anexceptionisthrownatruntime

Answer:

(C)向上就近原则.

第20行的go(z)将会依序找go(inti),go(longl),go(floatf),go(doubled)或go(Integeri)方法.但是并不会自动向上转型Long然后再呼叫go(Longn),这种依顺序向上找的特性只会发生在对应端基本资料型别的情况下,

参考大纲:

面向对象—重载;实用API—自动封包、拆包

QUESTION11

Giventheexhibit:

*disvalid,non-nullDateobject

*dfisavalid,non-nullDateFormatobjectsettothecurrentlocal

Whatoutputsthecurrentlocal'scountrynameandtheappropriateversionofD'sdate?

A.Localeloc=Locale.getLocal();

System.outprintIn(loc.getDisplayCountry()

B.Localeloc=Locale.getDefault();

System.outprintIn(loc.getDisplayCountry()+""+df.format(d));

C.Localeloc=Locale.getLocal();

System.outprintIn(loc.getDisplayCountry()+""+df.setDateFormat(d));

D.Localeloc=Locale.getDefault();

System.outprintIn(loc.getDisplayCountry()+""+df.seDateFormat(d));

Answer:

(B)

ALocale类没有getLocal()方法,编译错误

B正确

C错误Locale类没有getLocal()方法DateFormat没有setDateFormat()方法,编译错误

DDateFormat没有setDateFormat()方法编译错误

参考大纲:

实用API—java.util包和java.text包

QUESTION12

Giventheexhibit:

Whatistheresult?

A.Compilationfails.

B.Anexceptionisthrownatruntime

C.Thecodeexecutesandprints"running"

D.Thecodeexecutesandprints"runningrunning"

E.Thecodeexecutesandprints"runningrunninigrunning

Answer:

(E)

t.run()调用main主线程去执行2-4行的run(),就是一次普通的方法调用;t.start()表示起用thread线程负责去执行2-4行的run();把2-4行的代码改为:

publicvoidrun(){

StringthreadName=Thread.currentThread().getName();

System.out.println(threadName+”:

running”);

}

这样就可以看出是谁调用了run()了,显示如下:

main:

running

main:

running

Thread-o:

running

参考大纲:

多线程

QUESTION13------------仔细看看

Exhibit:

Whichtwoarepossibleresults?

(choosetwo)

A.0,2,4,4,6,8,10,6,

B.0,2,4,6,8,10,2,4,

C.0,2,4,6,8,10,12,14,

D.0,0,2,2,4,4,6,6,8,8,10,10,12,12,14,14,

E.0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14,

Answer:

(A,C)

A第一个线程循环到第三遍使得x等于4,并执行完第8句后挂起(此时current也是4);第二个线程开始执行,执行完以后第一个线程接着执行最后一次循环,打印6

C两个线程依次执行

参考大纲:

多线程

QUESTION14

Giventheexhibit:

Whichstatementistrue?

A.ThiscodemaythrowanInterruptedException

B.ThiscodemaythrowanIllegalStateExcepion

C.ThiscodemaythrowaTimeOutExceptionaftertenminutes

D.Thiscodewillnotcompileunless"obj.wait()\"isreplacedwith"((Thread)obj).wait()"

E.Reversingtheorderofobj.wait()andobj.notify()mayvcausethismethodtocompletenormally

Answer:

(A)

首先编译通不过,

第5行:

voidwaitForSignal()throwsInterruptedException{…….}

第6行:

Objectobj=newObject();

obj=Thread.currentThread();

第7行应该是:

synchronized(obj);

-----在写wait()和notify()方法时,除了要写在synchronized区段,.还需要撰写InterruptedException异常的try-catch.本题就算写了try-catch,也可能会在执行的时候产生currentthreadnotowner的IllegalMonitorStateException的异常.

参考大纲:

多线程—同步处理

QUESTION15

Giventheexhibit:

Whatcanbearesult?

A.Compilationfails

B.Anexceptionisthrownatruntime

C.Thecodeexecutesandprints"StartedComplete"

D.Thecodeexecutesandprints"StartedComplete0123"

E.Thecodeexecutesandprints"Started0123Complete"

Answer:

(E)

Join()方法使得某个线程加入到正在执行的线程(本题是main线程)中,执行完该线程才继续执行main线程.本程序中第5行由main线程执行,6行因为下达了join(),所以mian的执行将被暂停,等t做完run()方法的全部工作之后,才论到main继续执行未完成的工作!

参考大纲:

多线程

QUESTION16

WhichtwocodefragmentswillexecutethemethoddoStuff()inaseparatethread?

(choosetwo)

A.newThread(){

publicvoidrun(){doStuff();}

};

B.newThread(){

publicvoidstart(){doStuff();}

};

C.newThread(){

publicvoidrun(){doStuff();}

}.run();

D.newThread(){

publicvoidrun(){doStuff();}

}.start();

E.newThread(newRunable(){

publicvoidrun(){doStuff();}

}).run();

F.newThread(newRunnable(){

publicvoidrun(){doStuff();}

}).start();

Answer:

(D、F)

D匿名类别中复写run方法,并调用start()方法启动线程

F利用匿名实现runnable接口中的run方法,并调用start()启动线程

参考大纲:

多线程

QUESTION17

Whichthreewillcompileandrunwithoutexception?

(choosethree)

A.privatesynchronizedobjecto;

B.voidgo(){

synchronized(){/*codehere*/}

}

C.publicsynchronizedvoidgo(){/*codehere*/}

D.privatesynchronized(this)voidgo(){/*codehere*/}

E.voidgo(){

synchronized(Object.class){/*codehere*/}

}

F.voidgo(){

synchronized(o){/*codehere*/}

}

Answer:

(C,E,F)

A错误synchronized不可以成为属性/变量的修饰符

B错误synchronized()中的括号中要加入欲锁定的物件或类型//synchronized(this)

C正确利用synchronized来修饰对象instance方法,锁定的物件将会是this,

D错误修饰方法时,this不用特别在synchronized()中指明

E正确合法的classliteralssynchronized//针对某个类同步

F正确合法的instanceblocksynchronized//针对某个对象同步

参考大纲:

多线程—线程同步

QUESTION18

Exhibit:

Whatistheresult?

A.Thecodewilldeadlock

B.Thecodemayrunwithnooutput

C.Anexceptionisthrownatruntime

D.Thecodemayrunwithoutput"06"

E.Thecodemayrunwithoutput"2064"

F.Thecodemayrunwithoutput"0246"

Answer:

(F)

情况1run方法运行以后运行再调用getResult();

情况2先调用getResult(),挂起,等待run()方法修改isComplete的值

线程0,线程1,线程2,线程3,main共有5个线程,中间线程执行的顺序如上面所说的,但是最后的结果是main的for(Compu

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1