java工程師考試試題_第1頁
java工程師考試試題_第2頁
java工程師考試試題_第3頁
java工程師考試試題_第4頁
java工程師考試試題_第5頁
已閱讀5頁,還剩7頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

第一題:(過程可以寫在后面)

學(xué)校的畢業(yè)話劇演出由四個(gè)小美女來出演小紅帽、美羊羊、女巫和公主的角

色。沒人在排練時(shí)的角色與演出時(shí)的角色不同。

排練時(shí)出演小紅帽的人會撒謊,通過如下消息,請判斷四人在演出和排練時(shí)

分別出演什么角色。

梅:“排練時(shí),蘭的角色是演出時(shí)竹的角色?!?/p>

蘭:“菊排練時(shí)扮演的是美羊羊?!?/p>

竹:“演出時(shí)我演公主?!?/p>

菊:“蘭演出時(shí)扮演的是美羊羊?!?/p>

第二題:解數(shù)獨(dú)題

(數(shù)獨(dú)是九宮格(即3格寬x3格高))正方形狀,每一格又細(xì)分為一個(gè)九宮

格,在沒一個(gè)小九宮格中,分別填上廣9個(gè)數(shù)字,讓每一個(gè)大九宮格沒一列,沒

一行的數(shù)字都不重復(fù)。

8174

69

483

385

2756

96

6

51

183

1>Whichlinecontainsaconstructorinthisclassdefinition?

publicclassCounter!//(1)

intcurrent,step;

publicCounter(intstartVaue,intstepValue){//(2)

set(startValue);

setStepValue(steValue);

publicintget(){returncurrent;}//(3)

publicvoidset(intvalue){current==value;}//(4)

publicvoidsetStepValue(intstepValue){step==stepValue;}//(5)

1)Codemarkedwith(1)isaconstructor

2)Codemarkedwith(2)isaconstructor

3)Codemarkedwith(3)isaconstructor

4)Codemarkedwith(4)isaconstructor

5)Codemarkedwith(5)isaconstructor

2、Aninstancemember...

1)isalsocalledastaticmember

2)isalwaysavariable

3)isneveramethod

4)belongstoasingleinstance,nottotheclassasawhole

5)alwaysrepresentsanoperation

3、Giventhefollowingclass,whichstatementscanbeinsertedat

positionIwithoutcausingthecodetofailcompilation?

publicclassQ6db8{

inta

intb=0;

staticintc;

publicvoidm(){

intd;

inte=0;

//Position1

1)a++

2)b++

3)c++

4)d++

5)e++

7、Whatiswrongwiththefollowingcode?

ClassMyExceptionextendsException1!

Publicclassqb4ab{

Publicvoidfoo(){

Try{

Bar();

}finally{

Baz();

}catch(MyExceptione){

}

Publicvoidbar()throwsMyException{

ThrownewException();

}

Publicvoidbaz()throwsRuntimeException{

ThrownewRuntimeException();

4、)Sincethemethodfoo()doesnotcatchtheexceptiongeneratedby

themethodbaz(),itmustdeclaretheRuntimeExceptioninitsthrows

clause.

5、)Athetryblockcannotbefollowedbybothacatchandafinally

block.

6、)Anemptycatchblockisnotallowed.

7、)Acatchblockcannotfollowafinallyblock.

8、)Afinallyblockmustalwaysfollowoneormorecatchblocks.

5、Whatwillhappenwhenyouattempttocompileandrunthe

followingprogrambypassingtheTestclasstotheJavainterpreter?

ClassTest{

Publicstaticvoidmain{

(“hello");

}

}

Selecttheonerightanswer.

6.theprogramdoesnotcompilebecausemain()isnotdefined

correctly.

7.Theprogramcompilesbutwhenyoutrytoruntheinterpreter

compliesthatitcannotfindthemain()methoditneedstorun.

C)theprogramcompilesbutyoucannotrunitbecausetheclassisnot

declaredaspublic.

D)theprogramcompilesandrunswithoutanerrorbutdoesnotdisplay

anythinginthestandardoutput.

E)theprogramcompilesanddisplays“hello“inthestandardoutput

whenyouinrunit.

6、Givethosecodesnippets:

Booleanbl=newBoolean(true);

Booleanb2=newBoolean(true);

WhichexpressionsarelegalJavaexpressionsthatreturntrue?

Selectallvalidanswer.

3.bl=b2

4.bl.equals(b2)

C)bl&b2

D)bl|b2

E)bl&&b2

F)bl||b2

7、Giventhiscodesnippet:

try{

tryThis();

return;

}catch(lOExceptionxl){

("exception1〃);

return;

}catch(Exceptionx2){

("exception2〃);

return;

}finally{

("finally");

}

WhatwillappearinthestandardoutputiftryThis()throwsa

NumberFormatException?

Selecttheonerightanswer.

a)Nothing

b)“exceptionl/z,followedby"finally”

c)“exception2/z,followedby"finally”

d)“exception1〃

e)“exception2〃

選擇:C

8、Givertheseclassdefinitions;

classSuperclass{}

classSubclasslextendsSuperclass{}

classSubclass2extendsSuperclass{}

andtheseobjects;

Superclassa=newSuperclass();

Subclasslb=newSubclassl();

Subclass2c=newSubclass2();

whichofthefollowingexplainstheresultofthestatement;

b=(Subclassl)c;

Selectedtheonerightanswer;

a)Illegalatcompiletime

b)Legalatcompiletimebutpossiblyillegalatruntime

c)Definitelylegalatruntime

9、簡述以下代碼是在做什么事情?

PublicstaticgetEJBHome(StringJNDIName)throws

NameNotFoundException,NamingException

(

env=new(1);

initContext=new(env);

If(initContext==null){

ThrownewRuntimeException("getEJBHomecould'tretrieveinitial

context");

return()initContext.lookup(JNDIName);

}

10:請從空白處填寫代碼,滿足以下功能:

A)從請求中得到用戶名和口令(請求通過web瀏覽器中的HTML頁面提交,頁

面中用戶名對象名為userName,口令對象名為password)

B)如果用戶名為"admin",口令為password,則講登陸成功,將頁面轉(zhuǎn)到

loginSuccess.jsp頁面,并在session存放用戶名(username)和密碼

(password)

C(如果用戶名和空靈為其他值,轉(zhuǎn)到error.jsp

PublicclassTestServletextendsHttpServlet

(

Publicvoidservice(HttpServletRequestrequest,HttpServletResponse

resopnse)throwsServletException,lOException

(

//Includefollowinglinsinallservlet.....

Try{

//請?jiān)诖颂韺懘a

If(userName.equals("admin")&&

password,equals("password")){

request,getsession..setAttribute("username",^^admin");

request,getsession..setAttribute("passworcT,“password");

Request.sendRedirect("loginSuccess.jsp");

}else{

Request.sendRedirect("error.jsp");

)

}catch(Exceptione){

典道的筆試分A-B卷,題型有:

1.選擇題30道(每道2分共60分)

2.代碼閱讀題4道(每道5分共20分)

3.程序邏輯題2道(每道10分共20分)

不管是A-B卷,考察的范圍都是基礎(chǔ)知識,這個(gè)是和幾個(gè)做B卷的同學(xué)那了解到

的,主要的考點(diǎn)如下:

考點(diǎn)名稱考試頻率難易度備注

數(shù)組高易

值傳遞與址高中

傳遞

Main函數(shù)低中

線程低難

Swing與awt低中

Ascii碼高難請務(wù)必記住

常用ascii

碼,代碼題

都有考

運(yùn)算符優(yōu)先低中去網(wǎng)上百度

級一下

Oop思想高中

方法重載與高易

重寫

包低易

方法與類的低易

命名規(guī)則

邏輯思維高難

其他的記得不是很清楚了,不過不會超過基礎(chǔ)知識這個(gè)范圍,但光靠書

(accp6.0)上那些還不夠,建議找些參考書學(xué)習(xí)一下,越基礎(chǔ)越好。

以下是A卷代碼閱讀題

8、建一個(gè)數(shù)組,順序輸出10位數(shù),然后把這10位數(shù)再倒序輸出

publicclassTest{

publicstaticvoidmain(String[]args){

int[]arr=newint[]{1,2,3,4,5,6,7,8,9,10};

System.out.printIn("-------1l頁序輸出-------");

for(inti=0;i<arr.length;i++){

System.out.print(arr[i];

)

System.out.printIn();

System.out.printIn("-------倒敘輸出-------");

for(intj=arr.length-1;j>=0;j--){

System.out.print(arr[j];

)

)

9、考的是方法重載,它是將兩個(gè)方法的參數(shù)順序顛倒了一下,看題的時(shí)候要注

屆、O

3.

publicclassTest5{

publicstaticvoidmain(String[]args){

int[]arr=newint口{1,2,3,4,5,6,7,8};

a(arr);

b(arr);

a(arr);

)

staticvoida(intarr[]){

for(inttemp:arr){

System.out.printin(temp);

}

)

staticvoidb(intarr[]){

for(inti=0;i<arr.length;i++){

arr[i]*=i;

輸出結(jié)果是:56

以下是A卷手寫代碼題:

8.請用1、2、3、4組成N個(gè)數(shù)值不重復(fù)且個(gè)十百位都不重復(fù)的3位數(shù),一共有幾

個(gè)?分別是什么?

共有:24個(gè)

分別是:

123,124,132,134,142,143,213,214,231,234,241,243,312,314,321,3

24,341,342,412,413,421,423,431,432,

參考答案:

Intcount=0;

For(inti=l;i<=4;i++){

For(intj=l;j<=4;j++){

For(intk=l;k<=4;k-F+){

If(i!=j&&i!=k&&j!=k){

Count++;

(i*100+j*10+k);

一共有24個(gè),公式:4*3*2=24,具體數(shù)學(xué)公式請見排列算法。

9.查詢子串在父串中出現(xiàn)的次數(shù):

參考答案:

設(shè):strl為父串,str2為字串,貝U:

publicclassTest6{

publicstaticvoidmain(String[]args){

String

strl=HhdsajkfhuisadhifnokfasdfdasdoksdfsdsfsokH;

Stringstr2=nok";

Stringtemp="H;

intcount=0;

for(temp=strl;temp!=null&&str2.length()<=strl.length()

;)

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論