?面試時候經常會問的一些問題(不斷補充中)
面試必備基礎題目(雖然不一定常用,?僅用于面試,?面試就是把人搞的都不會然后砍價,?當然您可以講我可以查資料完成,?但是面試的時候就是沒道理的,?起碼我是經常看到這些題).
如何把一段逗號分割的字符串轉換成一個數組?
request.getAttribute()?和?request.getParameter()?有何區別?
response.sendRedirect()?和?forward()?區別?
<%@include?file="xxx.jsp"%>
和?<jsp:include>?區別?
List?和?Map?區別?
Struts?和?Spring?自動填充表單參數到?Bean?的大致原理?
說一下你用的?Spring?+?Hibernate?的方框圖??您都用到了哪些部分??
請用英文簡單介紹一下自己.
請把?http://tomcat.apache.org/?首頁的這一段話用中文翻譯一下?
?
Apache?Tomcat?is?the?servlet?container?that?is?used?in?the?official?Reference?Implementation?for?the?Java?Servlet?and?JavaServer?Pages?technologies.?The?Java?Servlet?and?JavaServer?Pages?specifications?are?developed?by?Sun?under?the?Java?Community?Process.?
Apache?Tomcat?is?developed?in?an?open?and?participatory?environment?and?released?under?the?Apache?Software?License.?Apache?Tomcat?is?intended?to?be?a?collaboration?of?the?best-of-breed?developers?from?around?the?world.?We?invite?you?to?participate?in?this?open?development?project.?To?learn?more?about?getting?involved,?click?here.?
Apache?Tomcat?powers?numerous?large-scale,?mission-critical?web?applications?across?a?diverse?range?of?industries?and?organizations.?Some?of?these?users?and?their?stories?are?listed?on?the?PoweredBy?wiki?page.
?
try?{
Connection?conn?=?...;
Statement?stmt?=?...;
ResultSet?rs?=?stmt.executeQuery("select?*?from?table1");
while(rs.next())?{
}
}?catch(Exception?ex)?{
}?
這段代碼有什么不足之處??
HTML?的?form?提交之前如何驗證數值不為空??為空的話提示用戶并終止提交??
為什么要用?ORM???和?JDBC?有何不一樣??
Weblogic?的?Server,?Machine,?Node,?Domain?都有何區別??
簡要講一下?EJB?的?7?個?Transaction?Level??
最常見的:?用?JDBC?查詢學生成績單,?把主要代碼寫出來.?
Tomcat?5?用?query.jsp?name=中文,?怎么把這個變量無亂碼的取出來??
finally語句一定會執行么??
前幾天有一個朋友去面試,被問到這樣一個問題,如下?
?1?public?class??smallT
?2?{
?3?public?static?void??main(String?args[])
?4?{
?5?????????smallT?t??=?new??smallT();
?6?int??b??=??t.get();
?7?????????System.out.println(b);
?8?????}
?9?public?int??get()
10?{
11?try
12?{
13?return?2?;
14?????????}
15?catch?(Exception?e)
16?{
17?return?3?;
18?????????}
19?finally
20?{
21?return?4?;
22?????????}
23?????}
24?}
25?
輸出:
4
我記得學習的時候說有返回值的方法,執行完return語句后就會停止了;另一方面我還記得在try……catch語句中finally語句也是一定要執行的。于是在這里就產生了麻煩。試了一下,發現果然是執行了finally中的值。正好這兩天公司在培訓,我便把這個問題提給java很厲害的一個講師,他用斷點測試了一下,說是兩個值都返回了……
我又改了一小下,在get方法中逐個添上了輸出信息到控制臺的語句,發現居然能執行。如下?
?1public?class?test
?2{
?3?public?static?void?main(String?args[])
?4{
?5????????test?t?=?new?test();
?6?int?b?=?t.get();
?7????????System.out.println("Third:?a?=?"+b);
?8????}
?9?public?int?get()
10{
11?try
12{
13?????????System.out.println("First:?a?=?"+2);
14?return?2;
15????????}
16?catch(Exception?e)
17{
18?????????System.out.println(3);
19????????}
20?finally
21{
22????????????System.out.println("Second:?a?=?"+4);
23?return?4;
24????????}
25????}
26}
27
輸出:
First:?a?=?2
Second:?a?=?4
Third:?a?=?4
可這明明是一個需要返回一個int整數的方法啊。?
一道面試題目?
一個整數,大于0,不用循環和本地變量,按照n,2n,4n,8n的順序遞增,當值大于5000時,把值按照指定順序輸出來。
例:n=1237
則輸出為:
1237,
2474,
4948,
9896,
9896,
4948,
2474,
1237,?
美資軟件公司JAVA工程師電話面試題目?
1.?Talk?about?overriding,?overloading.
2.?Talk?about?JAVA?design?patterns?you?known.
3.?Talk?about?the?difference?between?LinkList,?ArrayList?and?Victor.
4.?Talk?about?the?difference?between?an?Abstract?class?and?an?Interface.
5.?Class?a?=?new?Class();?Class?b?=?new?Class();
?if(a?==?b)?returns?true?or?false,?why?
6.?Why?we?use?StringBuffer?when?concatenating?strings?
7.?Try?to?explain?Singleton?to?us??Is?it?thread?safe??If?no,?how?to?make?it?thread?safe?
8.?Try?to?explain?Ioc?
9.?How?to?set?many-to-many?relationship?in?Hibernate?
10.?Talk?about?the?difference?between?INNER?JOIN?and?LFET?JOIN.
11.?Why?we?use?index?in?database??How?many?indexes?is?the?maximum?in?one?table?as?your?suggestion?
12.?When?‘Final’?is?used?in?class,?method?and?property,?what?dose?it?mean?
13.?Do?you?have?any?experience?on?XML??Talk?about?any?XML?tool?you?used?,e.g.?JAXB,?JAXG.
14.?Do?you?have?any?experience?on?Linux?
15.?In?OOD?what?is?the?reason?when?you?create?a?Sequence?diagram??
補一個內部培訓用的?PPT:??SQL?Tuning?in?Sybase.zip?17KB,?英文,?Sybase?調優,?大部分道理是通用的.
數據庫三范式是什么??別看問題簡單,?我也經常答不上來被面試的人寫上數據庫不行.
還有就是?Sun?Java?認證時候會考的一些英文選擇題,?填空題,?模擬題也成.
赴港JAVA開發工程師的面試題目?
?
也是上個星期五的上午,按照與獵頭的約定,接受了香港某軟件供應商的面試。工作是分析程序員,需赴港工作,以下是面試過程以及題目(大概記下了90%),記下來與大家分享。
第一部分:例行公事的英文自我介紹;
以下部分必須以粵語回答,本人非廣東人,粵語會講,但是不標準。
第二部分:項目經驗介紹,著重介紹項目背景,開發流程以及本人在項目開發過程中的角色;
第三部分:面試官根據簡歷提問:
(1)說出Abstract?class與interface的不同?
(2)Oracle中如何進行錯誤處理?如果用戶反應速度慢,你如何著手解決問題?
(3)圖畫板上列了兩個table,問查詢結果,主要是考inner?join與left?join的。
(4)union和union?all有什么不同?
(5)你用什么軟件做設計?
(6)是否用過Websphere?
(7)iBatis與Hibernate有什么不同?
(8)談談Struts中的Action?servlet。
(9)是否開發過IBM?portal項目。
(10)是否介意加班?
(11)如果你去香港工作,你認為你最大的困難是什么?
第四部分:筆試,三個英文考試題目選一個作答,內容都是寫一份email。
出來后問了獵頭,他說最遲一個星期內就有結果。
結果,晚上就接到電話說通過了,并收到了合同和赴港申請的電子文件。工作地點是九龍,月薪18K(中等偏低),合同期一年。獵頭催我盡快簽合同,然后他們馬上就去辦工作簽證。
猶豫ing。
每個JAVA初學者應該知道的問題?
對于這個系列里的問題,每個學Java的人都應該搞懂。當然,如果只是學Java玩玩就無所謂了。如果你認為自己已經超越初學者了,卻不很懂這些問題,請將你自己重歸初學者行列。內容均來自于CSDN的經典老貼。
問題一:我聲明了什么!
String?s?=?"Hello?world!";
許多人都做過這樣的事情,但是,我們到底聲明了什么?回答通常是:一個String,內容是“Hello?world!”。這樣模糊的回答通常是概念不清的根源。如果要準確的回答,一半的人大概會回答錯誤。
這個語句聲明的是一個指向對象的引用,名為“s”,可以指向類型為String的任何對象,目前指向"Hello?world!"這個String類型的對象。這就是真正發生的事情。我們并沒有聲明一個String對象,我們只是聲明了一個只能指向String對象的引用變量。所以,如果在剛才那句語句后面,如果再運行一句:
String?string?=?s;
我們是聲明了另外一個只能指向String對象的引用,名為string,并沒有第二個對象產生,string還是指向原來那個對象,也就是,和s指向同一個對象。
問題二:"=="和equals方法究竟有什么區別?
==操作符專門用來比較變量的值是否相等。比較好理解的一點是:
int?a=10;
int?b=10;
則a==b將是true。
但不好理解的地方是:
String?a=new?String("foo");
String?b=new?String("foo");
則a==b將返回false。
根據前一帖說過,對象變量其實是一個引用,它們的值是指向對象所在的內存地址,而不是對象本身。a和b都使用了new操作符,意味著將在內存中產生兩個內容為"foo"的字符串,既然是“兩個”,它們自然位于不同的內存地址。a和b的值其實是兩個不同的內存地址的值,所以使用"=="操作符,結果會是?false。誠然,a和b所指的對象,它們的內容都是"foo",應該是“相等”,但是==操作符并不涉及到對象內容的比較。
對象內容的比較,正是equals方法做的事。
看一下Object對象的equals方法是如何實現的:
boolean?equals(Object?o){
return?this==o;
}
Object?對象默認使用了==操作符。所以如果你自創的類沒有覆蓋equals方法,那你的類使用equals和使用==會得到同樣的結果。同樣也可以看出,?Object的equals方法沒有達到equals方法應該達到的目標:比較兩個對象內容是否相等。因為答案應該由類的創建者決定,所以Object把這個任務留給了類的創建者。
看一下一個極端的類:
Class?Monster{
private?String?content;
...
boolean?equals(Object?another){?return?true;}
}
我覆蓋了equals方法。這個實現會導致無論Monster實例內容如何,它們之間的比較永遠返回true。
所以當你是用equals方法判斷對象的內容是否相等,請不要想當然。因為可能你認為相等,而這個類的作者不這樣認為,而類的equals方法的實現是由他掌握的。如果你需要使用equals方法,或者使用任何基于散列碼的集合(HashSet,HashMap,HashTable),請察看一下?java?doc以確認這個類的equals邏輯是如何實現的。
問題三:String到底變了沒有?
沒有。因為String被設計成不可變(immutable)類,所以它的所有對象都是不可變對象。請看下列代碼:
String?s?=?"Hello";
s?=?s?+?"?world!";
s?所指向的對象是否改變了呢?從本系列第一篇的結論很容易導出這個結論。我們來看看發生了什么事情。在這段代碼中,s原先指向一個String對象,內容是?"Hello",然后我們對s進行了+操作,那么s所指向的那個對象是否發生了改變呢?答案是沒有。這時,s不指向原來那個對象了,而指向了另一個?String對象,內容為"Hello?world!",原來那個對象還存在于內存之中,只是s這個引用變量不再指向它了。
通過上面的說明,我們很容易導出另一個結論,如果經常對字符串進行各種各樣的修改,或者說,不可預見的修改,那么使用String來代表字符串的話會引起很大的內存開銷。因為?String對象建立之后不能再改變,所以對于每一個不同的字符串,都需要一個String對象來表示。這時,應該考慮使用StringBuffer類,它允許修改,而不是每個不同的字符串都要生成一個新的對象。并且,這兩種類的對象轉換十分容易。
同時,我們還可以知道,如果要使用內容相同的字符串,不必每次都new一個String。例如我們要在構造器中對一個名叫s的String引用變量進行初始化,把它設置為初始值,應當這樣做:
public?class?Demo?{
private?String?s;
...
public?Demo?{
s?=?"Initial?Value";
}
...
}
而非
s?=?new?String("Initial?Value");
后者每次都會調用構造器,生成新對象,性能低下且內存開銷大,并且沒有意義,因為String對象不可改變,所以對于內容相同的字符串,只要一個String對象來表示就可以了。也就說,多次調用上面的構造器創建多個對象,他們的String類型屬性s都指向同一個對象。
上面的結論還基于這樣一個事實:對于字符串常量,如果內容相同,Java認為它們代表同一個String對象。而用關鍵字new調用構造器,總是會創建一個新的對象,無論內容是否相同。
至于為什么要把String類設計成不可變類,是它的用途決定的。其實不只String,很多Java標準類庫中的類都是不可變的。在開發一個系統的時候,我們有時候也需要設計不可變類,來傳遞一組相關的值,這也是面向對象思想的體現。不可變類有一些優點,比如因為它的對象是只讀的,所以多線程并發訪問也不會有任何問題。當然也有一些缺點,比如每個不同的狀態都要一個對象來代表,可能會造成性能上的問題。所以Java標準類庫還提供了一個可變版本,即?StringBuffer。
問題四:final關鍵字到底修飾了什么?
final使得被修飾的變量"不變",但是由于對象型變量的本質是“引用”,使得“不變”也有了兩種含義:引用本身的不變,和引用指向的對象不變。
引用本身的不變:
final?StringBuffer?a=new?StringBuffer("immutable");
final?StringBuffer?b=new?StringBuffer("not?immutable");
a=b;//編譯期錯誤
引用指向的對象不變:
final?StringBuffer?a=new?StringBuffer("immutable");
a.append("?broken!");?//編譯通過
可見,final只對引用的“值”(也即它所指向的那個對象的內存地址)有效,它迫使引用只能指向初始指向的那個對象,改變它的指向會導致編譯期錯誤。至于它所指向的對象的變化,final是不負責的。這很類似==操作符:==操作符只負責引用的“值”相等,至于這個地址所指向的對象內容是否相等,==操作符是不管的。
理解final問題有很重要的含義。許多程序漏洞都基于此----final只能保證引用永遠指向固定對象,不能保證那個對象的狀態不變。在多線程的操作中,一個對象會被多個線程共享或修改,一個線程對對象無意識的修改可能會導致另一個使用此對象的線程崩潰。一個錯誤的解決方法就是在此對象新建的時候把它聲明為final,意圖使得它“永遠不變”。其實那是徒勞的。
問題五:到底要怎么樣初始化!
本問題討論變量的初始化,所以先來看一下Java中有哪些種類的變量。
1.?類的屬性,或者叫值域
2.?方法里的局部變量
3.?方法的參數
對于第一種變量,Java虛擬機會自動進行初始化。如果給出了初始值,則初始化為該初始值。如果沒有給出,則把它初始化為該類型變量的默認初始值。
int類型變量默認初始值為0
float類型變量默認初始值為0.0f
double類型變量默認初始值為0.0
boolean類型變量默認初始值為false
char類型變量默認初始值為0(ASCII碼)
long類型變量默認初始值為0
所有對象引用類型變量默認初始值為null,即不指向任何對象。注意數組本身也是對象,所以沒有初始化的數組引用在自動初始化后其值也是null。
對于兩種不同的類屬性,static屬性與instance屬性,初始化的時機是不同的。instance屬性在創建實例的時候初始化,static屬性在類加載,也就是第一次用到這個類的時候初始化,對于后來的實例的創建,不再次進行初始化。這個問題會在以后的系列中進行詳細討論。
對于第二種變量,必須明確地進行初始化。如果再沒有初始化之前就試圖使用它,編譯器會抗議。如果初始化的語句在try塊中或if塊中,也必須要讓它在第一次使用前一定能夠得到賦值。也就是說,把初始化語句放在只有if塊的條件判斷語句中編譯器也會抗議,因為執行的時候可能不符合if后面的判斷條件,如此一來初始化語句就不會被執行了,這就違反了局部變量使用前必須初始化的規定。但如果在else塊中也有初始化語句,就可以通過編譯,因為無論如何,總有至少一條初始化語句會被執行,不會發生使用前未被初始化的事情。對于try-catch也是一樣,如果只有在try塊里才有初始化語句,編譯部通過。如果在?catch或finally里也有,則可以通過編譯。總之,要保證局部變量在使用之前一定被初始化了。所以,一個好的做法是在聲明他們的時候就初始化他們,如果不知道要出事化成什么值好,就用上面的默認值吧!
其實第三種變量和第二種本質上是一樣的,都是方法中的局部變量。只不過作為參數,肯定是被初始化過的,傳入的值就是初始值,所以不需要初始化。
問題六:instanceof是什么東東?
instanceof是Java的一個二元操作符,和==,>,<是同一類東東。由于它是由字母組成的,所以也是Java的保留關鍵字。它的作用是測試它左邊的對象是否是它右邊的類的實例,返回boolean類型的數據。舉個例子:
String?s?=?"I?AM?an?Object!";
boolean?isObject?=?s?instanceof?Object;
我們聲明了一個String對象引用,指向一個String對象,然后用instancof來測試它所指向的對象是否是Object類的一個實例,顯然,這是真的,所以返回true,也就是isObject的值為True。
instanceof有一些用處。比如我們寫了一個處理賬單的系統,其中有這樣三個類:
public?class?Bill?{//省略細節}
public?class?PhoneBill?extends?Bill?{//省略細節}
public?class?GasBill?extends?Bill?{//省略細節}
在處理程序里有一個方法,接受一個Bill類型的對象,計算金額。假設兩種賬單計算方法不同,而傳入的Bill對象可能是兩種中的任何一種,所以要用instanceof來判斷:
public?double?calculate(Bill?bill)?{
if?(bill?instanceof?PhoneBill)?{
//計算電話賬單
}
if?(bill?instanceof?GasBill)?{
//計算燃氣賬單
}
...
}
這樣就可以用一個方法處理兩種子類。
然而,這種做法通常被認為是沒有好好利用面向對象中的多態性。其實上面的功能要求用方法重載完全可以實現,這是面向對象變成應有的做法,避免回到結構化編程模式。只要提供兩個名字和返回值都相同,接受參數類型不同的方法就可以了:
public?double?calculate(PhoneBill?bill)?{
//計算電話賬單
}
public?double?calculate(GasBill?bill)?{
//計算燃氣賬單
}
所以,使用instanceof在絕大多數情況下并不是推薦的做法,應當好好利用多態。
BeanSoft?參加過的一次面試:
?
2004年8月18日?星期三?〖農歷?甲申?猴年?七月初三〗?
筆試題目
1.?寫出常用的?Linux?命令
a)?列出當前目錄
b)?列出所有系統變量
c)?重命名文件
d)?etc...?記不住了.?
2.?Write?a?Java?application?use?the?Singleton?pattern,?it?should?have?one?instance?per?class.?It?should?have?two?integer?variable,?one?is?count,?on?is?inita.?There?should?be?two?methods?in?this?class,?and?the?method?should?be?thread?safely?in?multi-thread?environment.
a)?a?count()?method,?after?each?call?the?count?should?be?added?on?by?1;
b)?a?reset()?method,?after?each?call?the?count?should?be?set?to?the?value?of?inita.?
3.?Write?a?JavaBean?and?a?JSP?file.?The?page?should?output?a?date?string?in?this?pattern?"今天是2004年8月15日上午10:00",?the?value?is?taken?from?the?bean.?
4.?以下三個題目,?任選其一或多個:
1)?忘了...,?是關于?Java?的.
2)?寫一個應用程序,?讀出?STUDENT?表中的數據并打印出所有名稱.?數據庫系統任選.
3)?寫一個?Servlet,?讀取名為?url?的參數,?并連接到此字符串指定的地址上,?讀取所有內容后顯示給客戶.?
5.?6.?7.?都是關于?SQL?的,?例如?SELECT,?UPDATE,?DELETE?之類的,?還有的有子查詢.?數據庫系統沒有限制.?
8.?Write?a?html?file,?it?shoud?has?follow?functions:
1)?check?whether?the?user's?name?is?empty;
2)?the?email?address?should?has?a?'@';
3)?telephone?number?must?be?'1'-'9',?'-',?'?'(space).
Page?picture:
Please?input?your?name:
[____________________]?[Check?input]
Please?input?your?address:
[abc@________________]?[Check?input]
Please?input?your?telephone?number:
[____123a____________]?[Check?input]?
Java?面試題及其答案?
前段時間因為要參加一個筆試,在準備期間在網上找到了兩條關于筆試題目的文章,其中一篇為<<有感:應聘Java筆試時可能出現問題>>,還有一篇忘了名字,讀后深受啟發。?
在尋找這些答案的過程中,我將相關答案記錄下來,就形成了以下這些東西。需要說明的是以下答案肯定有很多不完整甚至錯誤的地方,需要各位來更正與完善它,千萬不要扔我的雞蛋啊。?
希望本文能夠給即將奔赴筆試考場的同仁些許幫助,更希望更多的人加入到收集整理筆試題與完善答案的這些工作中來,為大家更好的獲得工作機會做一點貢獻。?
在此感謝前面兩文的作者的對筆試題目的收集與整理。?
如有任何意見與建議請通過QQ:6045306,Mail:huijunzi@21cn.com與我聯系。?
Java基礎方面:?
1、作用域public,private,protected,以及不寫時的區別?
答:區別如下:?
作用域?當前類?同一package?子孫類?其他package?
public?√?√?√?√?
protected?√?√?√?×?
friendly?√?√?×?×?
private?√?×?×?×?
不寫時默認為friendly?
2、ArrayList和Vector的區別,HashMap和Hashtable的區別?
答:就ArrayList與Vector主要從二方面來說.?
一.同步性:Vector是線程安全的,也就是說是同步的,而ArrayList是線程序不安全的,不是同步的?
二.數據增長:當需要增長時,Vector默認增長為原來一培,而ArrayList卻是原來的一半?
就HashMap與HashTable主要從三方面來說。?
一.歷史原因:Hashtable是基于陳舊的Dictionary類的,HashMap是Java?1.2引進的Map接口的一個實現?
二.同步性:Hashtable是線程安全的,也就是說是同步的,而HashMap是線程序不安全的,不是同步的?
三.值:只有HashMap可以讓你將空值作為一個表的條目的key或value?
3、char型變量中能不能存貯一個中文漢字?為什么??
答:是能夠定義成為一個中文的,因為java中以unicode編碼,一個char占16個字節,所以放一個中文是沒問題的?
4、多線程有幾種實現方法,都是什么?同步有幾種實現方法,都是什么??
答:多線程有兩種實現方法,分別是繼承Thread類與實現Runnable接口?
同步的實現方面有兩種,分別是synchronized,wait與notify?
5、繼承時候類的執行順序問題,一般都是選擇題,問你將會打印出什么??
答:父類:?
package?test;?
public?class?FatherClass?
{?
public?FatherClass()?
{?
System.out.println("FatherClass?Create");?
}?
}?
子類:?
package?test;?
import?test.FatherClass;?
public?class?ChildClass?extends?FatherClass?
{?
public?ChildClass()?
{?
System.out.println("ChildClass?Create");?
}?
public?static?void?main(String[]?args)?
{?
FatherClass?fc?=?new?FatherClass();?
ChildClass?cc?=?new?ChildClass();?
}?
}?
輸出結果:?
C:\>java?test.ChildClass?
FatherClass?Create?
FatherClass?Create?
ChildClass?Create?
6、內部類的實現方式??
答:示例代碼如下:?
package?test;?
public?class?OuterClass?
{?
private?class?InterClass?
{?
public?InterClass()?
{?
System.out.println("InterClass?Create");?
}?
}?
public?OuterClass()?
{?
InterClass?ic?=?new?InterClass();?
System.out.println("OuterClass?Create");?
}?
public?static?void?main(String[]?args)?
{?
OuterClass?oc?=?new?OuterClass();?
}?
}?
輸出結果:?
C:\>java?test/OuterClass?
InterClass?Create?
OuterClass?Create?
再一個例題:?
public?class?OuterClass?{?
private?double?d1?=?1.0;?
//insert?code?here?
}?
You?need?to?insert?an?inner?class?declaration?at?line?3.?Which?two?inner?class?declarations?are?
valid?(Choose?two.)?
A.?class?InnerOne{?
public?static?double?methoda()?{return?d1;}?
}?
B.?public?class?InnerOne{?
static?double?methoda()?{return?d1;}?
}?
C.?private?class?InnerOne{?
double?methoda()?{return?d1;}?
}?
D.?static?class?InnerOne{?
protected?double?methoda()?{return?d1;}?
}?
E.?abstract?class?InnerOne{?
public?abstract?double?methoda();?
}?
說明如下:?
一.靜態內部類可以有靜態成員,而非靜態內部類則不能有靜態成員。?故?A、B?錯?
二.靜態內部類的非靜態成員可以訪問外部類的靜態變量,而不可訪問外部類的非靜態變量;return?d1?出錯。?
故?D?錯?
三.非靜態內部類的非靜態成員可以訪問外部類的非靜態變量。?故?C?正確?
四.答案為C、E?
7、垃圾回收機制,如何優化程序??
希望大家補上,謝謝?
8、float型float?f=3.4是否正確??
答:不正確。精度不準確,應該用強制類型轉換,如下所示:float?f=(float)3.4?
9、介紹JAVA中的Collection?FrameWork(包括如何寫自己的數據結構)??
答:Collection?FrameWork如下:?
Collection?
├List?
│├LinkedList?
│├ArrayList?
│└Vector?
│ └Stack?
└Set?
Map?
├Hashtable?
├HashMap?
└WeakHashMap?
Collection是最基本的集合接口,一個Collection代表一組Object,即Collection的元素(Elements)?
Map提供key到value的映射?
10、Java中異常處理機制,事件機制??
11、JAVA中的多形與繼承??
希望大家補上,謝謝?
12、抽象類與接口??
答:抽象類與接口都用于抽象,但是抽象類(JAVA中)可以有自己的部分實現,而接口則完全是一個標識(同時有多重繼承的功能)。?
13、Java?的通信編程,編程題(或問答),用JAVA?SOCKET編程,讀服務器幾個字符,再寫入本地顯示??
答:Server端程序:?
package?test;?
import?java.net.*;?
import?java.io.*;?
public?class?Server?
{?
private?ServerSocket?ss;?
private?Socket?socket;?
private?BufferedReader?in;?
private?PrintWriter?out;?
public?Server()?
{?
try?
{?
ss=new?ServerSocket(10000);?
while(true)?
{?
socket?=?ss.accept();?
String?RemoteIP?=?socket.getInetAddress().getHostAddress();?
String?RemotePort?=?":"+socket.getLocalPort();?
System.out.println("A?client?come?in!IP:"+RemoteIP+RemotePort);?
in?=?new?BufferedReader(new?
InputStreamReader(socket.getInputStream()));?
String?line?=?in.readLine();?
System.out.println("Cleint?send?is?:"?+?line);?
out?=?new?PrintWriter(socket.getOutputStream(),true);?
out.println("Your?Message?Received!");?
out.close();?
in.close();?
socket.close();?
}?
}catch?(IOException?e)?
{?
out.println("wrong");?
}?
}?
public?static?void?main(String[]?args)?
{?
new?Server();?
}?
};?
Client端程序:?
package?test;?
import?java.io.*;?
import?java.net.*;?
public?class?Client?
{?
Socket?socket;?
BufferedReader?in;?
PrintWriter?out;?
public?Client()?
{?
try?
{?
System.out.println("Try?to?Connect?to?127.0.0.1:10000");?
socket?=?new?Socket("127.0.0.1",10000);?
System.out.println("The?Server?Connected!");?
System.out.println("Please?enter?some?Character:");?
BufferedReader?line?=?new?BufferedReader(new?
InputStreamReader(System.in));?
out?=?new?PrintWriter(socket.getOutputStream(),true);?
out.println(line.readLine());?
in?=?new?BufferedReader(new?InputStreamReader(socket.getInputStream()));?
System.out.println(in.readLine());?
out.close();?
in.close();?
socket.close();?
}catch(IOException?e)?
{?
out.println("Wrong");?
}?
}?
public?static?void?main(String[]?args)?
{?
new?Client();?
}?
};?
14、用JAVA實現一種排序,JAVA類實現序列化的方法(二種)??如在COLLECTION框架中,實現比較要實現什么樣的接口??
答:用插入法進行排序代碼如下?
package?test;?
import?java.util.*;?
class?InsertSort?
{?
ArrayList?al;?
public?InsertSort(int?num,int?mod)?
{?
al?=?new?ArrayList(num);?
Random?rand?=?new?Random();?
System.out.println("The?ArrayList?Sort?Before:");?
for?(int?i=0;i<num?;i++?)?
{?
al.add(new?Integer(Math.abs(rand.nextInt())?%?mod?+?1));?
System.out.println("al["+i+"]="+al.get(i));?
}?
}?
public?void?SortIt()?
{?
Integer?tempInt;?
int?MaxSize=1;?
for(int?i=1;i<al.size();i++)?
{?
tempInt?=?(Integer)al.remove(i);?
if(tempInt.intValue()>=((Integer)al.get(MaxSize-1)).intValue())?
{?
al.add(MaxSize,tempInt);?
MaxSize++;?
System.out.println(al.toString());?
}?else?{?
for?(int?j=0;j<MaxSize?;j++?)?
{?
if?
(((Integer)al.get(j)).intValue()>=tempInt.intValue())?
{?
al.add(j,tempInt);?
MaxSize++;?
System.out.println(al.toString());?
break;?
}?
}?
}?
}?
System.out.println("The?ArrayList?Sort?After:");?
for(int?i=0;i<al.size();i++)?
{?
System.out.println("al["+i+"]="+al.get(i));?
}?
}?
public?static?void?main(String[]?args)?
{?
InsertSort?is?=?new?InsertSort(10,100);?
is.SortIt();?
}?
}?
JAVA類實現序例化的方法是實現java.io.Serializable接口?
Collection框架中實現比較要實現Comparable?接口和?Comparator?接口?
15、編程:編寫一個截取字符串的函數,輸入為一個字符串和字節數,輸出為按字節截取的字符串。?但是要保證漢字不被截半個,如“我ABC”4,應該截為“我AB”,輸入“我ABC漢DEF”,6,應該輸出為“我ABC”而不是“我ABC+漢的半個”。?
答:代碼如下:?
package?test;?
class?SplitString?
{?
String?SplitStr;?
int?SplitByte;?
public?SplitString(String?str,int?bytes)?
{?
SplitStr=str;?
SplitByte=bytes;?
System.out.println("The?String?is:′"+SplitStr+"′SplitBytes="+SplitByte);?
}?
public?void?SplitIt()?
{?
int?loopCount;?
loopCount=(SplitStr.length()%SplitByte==0)?(SplitStr.length()/SplitByte):(SplitStr.length()/Split?
Byte+1);?
System.out.println("Will?Split?into?"+loopCount);?
for?(int?i=1;i<=loopCount?;i++?)?
{?
if?(i==loopCount){?
System.out.println(SplitStr.substring((i-1)*SplitByte,SplitStr.length()));?
}?else?{?
System.out.println(SplitStr.substring((i-1)*SplitByte,(i*SplitByte)));?
}?
}?
}?
public?static?void?main(String[]?args)?
{?
SplitString?ss?=?new?SplitString("test中dd文dsaf中男大3443n中國43中國人?
0ewldfls=103",4);?
ss.SplitIt();?
}?
}?
16、JAVA多線程編程。?用JAVA寫一個多線程程序,如寫四個線程,二個加1,二個對一個變量減一,輸出。?
希望大家補上,謝謝?
17、STRING與STRINGBUFFER的區別。?
答:STRING的長度是不可變的,STRINGBUFFER的長度是可變的。如果你對字符串中的內容經常進行操作,特別是內容要修改時,那么使用StringBuffer,如果最后需要String,那么使用StringBuffer的toString()方法?
Jsp方面?
1、jsp有哪些內置對象?作用分別是什么??
答:JSP共有以下9種基本內置組件(可與ASP的6種內部組件相對應):?
request?用戶端請求,此請求會包含來自GET/POST請求的參數?
response?網頁傳回用戶端的回應?
pageContext?網頁的屬性是在這里管理?
session?與請求有關的會話期?
application?servlet?正在執行的內容?
out?用來傳送回應的輸出?
config?servlet的構架部件?
page?JSP網頁本身?
exception?針對錯誤網頁,未捕捉的例外?
2、jsp有哪些動作?作用分別是什么??
答:JSP共有以下6種基本動作?
jsp:include:在頁面被請求的時候引入一個文件。?
jsp:useBean:尋找或者實例化一個JavaBean。?
jsp:setProperty:設置JavaBean的屬性。?
jsp:getProperty:輸出某個JavaBean的屬性。?
jsp:forward:把請求轉到一個新的頁面。?
jsp:plugin:根據瀏覽器類型為Java插件生成OBJECT或EMBED標記?
3、JSP中動態INCLUDE與靜態INCLUDE的區別??
答:動態INCLUDE用jsp:include動作實現?
<jsp:include?page="included.jsp"?flush="true"?/>它總是會檢查所含文件中的變化,適合用于包含動態頁面,并且可以帶參數?
靜態INCLUDE用include偽碼實現,定不會檢查所含文件的變化,適用于包含靜態頁面?
<%@?include?file="included.htm"?%>?
4、兩種跳轉方式分別是什么?有什么區別??
答:有兩種,分別為:?
<jsp:include?page="included.jsp"?flush="true">?
<jsp:forward?page=?"nextpage.jsp"/>?
前者頁面不會轉向include所指的頁面,只是顯示該頁的結果,主頁面還是原來的頁面。執行完后還會回來,相當于函數調用。并且可以帶參數.后者完全轉向新頁面,不會再回來。相當于go?to?語句。?
Servlet方面?
1、說一說Servlet的生命周期??
答:servlet有良好的生存期的定義,包括加載和實例化、初始化、處理請求以及服務結束。這個生存期由javax.servlet.Servlet接口的init,service和destroy方法表達。?
2、Servlet版本間(忘了問的是哪兩個版本了)的不同??
希望大家補上,謝謝?
3、JAVA?SERVLET?API中forward()?與redirect()的區別??
答:前者僅是容器中控制權的轉向,在客戶端瀏覽器地址欄中不會顯示出轉向后的地址;后者則是完全的跳轉,瀏覽器將會得到跳轉的地址,并重新發送請求鏈接。這樣,從瀏覽器的地址欄中可以看到跳轉后的鏈接地址。所以,前者更加高效,在前者可以滿足需要時,盡量使用forward()方法,并且,這樣也有助于隱藏實際的鏈接。在有些情況下,比如,需要跳轉到一個其它服務器上的資源,則必須使用sendRedirect()方法。?
4、Servlet的基本架構?
public?class?ServletName?extends?HttpServlet?{?
public?void?doPost(HttpServletRequest?request,?HttpServletResponse?response)?throws?
ServletException,?IOException?{?
}?
public?void?doGet(HttpServletRequest?request,?HttpServletResponse?response)?throws?
ServletException,?IOException?{?
}?
}?
Jdbc、Jdo方面?
1、可能會讓你寫一段Jdbc連Oracle的程序,并實現數據查詢.?
答:程序如下:?
package?hello.ant;?
import?java.sql.*;?
public?class?jdbc?
{?
String?dbUrl="jdbc:oracle:thin:@127.0.0.1:1521:orcl"?
String?theUser="admin"?
String?thePw="manager"?
Connection?c=null;?
Statement?conn;?
ResultSet?rs=null;?
public?jdbc()?
{?
try{?
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();?
c?=?DriverManager.getConnection(dbUrl,theUser,thePw);?
conn=c.createStatement();?
}catch(Exception?e){?
e.printStackTrace();?
}?
}?
public?boolean?executeUpdate(String?sql)?
{?
try?
{?
conn.executeUpdate(sql);?
return?true;?
}?
catch?(SQLException?e)?
{?
e.printStackTrace();?
return?false;?
}?
}?
public?ResultSet?executeQuery(String?sql)?
{?
rs=null;?
try?
{?
rs=conn.executeQuery(sql);?
}?
catch?(SQLException?e)?
{?
e.printStackTrace();?
}?
return?rs;?
}?
public?void?close()?
{?
try?
{?
conn.close();?
c.close();?
}?
catch?(Exception?e)?
{?
e.printStackTrace();?
}?
}?
public?static?void?main(String[]?args)?
{?
ResultSet?rs;?
jdbc?conn?=?new?jdbc();?
rs=conn.executeQuery("select?*?from?test");?
try{?
while?(rs.next())?
{?
System.out.println(rs.getString("id"));?
System.out.println(rs.getString("name"));?
}?
}catch(Exception?e)?
{?
e.printStackTrace();?
}?
}?
}?
2、Class.forName的作用?為什么要用??
答:調用該訪問返回一個以字符串指定類名的類的對象。?
3、Jdo是什么??
答:JDO是Java對象持久化的新的規范,為java?data?object的簡稱,也是一個用于存取某種數據倉庫中的對象的標準化API。JDO提供了透明的對象存儲,因此對開發人員來說,存儲數據對象完全不需要額外的代碼(如JDBC?API的使用)。這些繁瑣的例行工作已經轉移到JDO產品提供商身上,使開發人員解脫出來,從而集中時間和精力在業務邏輯上。另外,JDO很靈活,因為它可以在任何數據底層上運行。JDBC只是面向關系數據庫(RDBMS)JDO更通用,提供到任何數據底層的存儲功能,比如關系數據庫、文件、XML以及對象數據庫(ODBMS)等等,使得應用可移植性更強。?
4、在ORACLE大數據量下的分頁解決方法。一般用截取ID方法,還有是三層嵌套方法。?
答:一種分頁方法?
<%?
int?i=1;?
int?numPages=14;?
String?pages?=?request.getParameter("page")?;?
int?currentPage?=?1;?
currentPage=(pages==null)?(1):{Integer.parseInt(pages)}?
sql?=?"select?count(*)?from?tables"?
ResultSet?rs?=?DBLink.executeQuery(sql)?;?
while(rs.next())?i?=?rs.getInt(1)?;?
int?intPageCount=1;?
intPageCount=(i%numPages==0)?(i/numPages):(i/numPages+1);?
int?nextPage?;?
int?upPage;?
nextPage?=?currentPage+1;?
if?(nextPage>=intPageCount)?nextPage=intPageCount;?
upPage?=?currentPage-1;?
if?(upPage<=1)?upPage=1;?
rs.close();?
sql="select?*?from?tables"?
rs=DBLink.executeQuery(sql);?
i=0;?
while((i<numPages*(currentPage-1))&&rs.next()){i++;}?
%>?
//輸出內容?
//輸出翻頁連接?
合計:<%=currentPage%>/<%=intPageCount%><a?href="List.jsp?page=1"?temp_href="List.jsp?page=1">第一頁</a><a?
href="List.jsp?page=<%=upPage%>"?temp_href="List.jsp?page=<%=upPage%>">上一頁</a>?
<%?
for(int?j=1;j<=intPageCount;j++){?
if(currentPage!=j){?
%>?
<a?href="list.jsp?page=<%=j%>"?temp_href="list.jsp?page=<%=j%>">[<%=j%>]</a>?
<%?
}else{?
out.println(j);?
}?
}?
%>?
<a?href="List.jsp?page=<%=nextPage%>"?temp_href="List.jsp?page=<%=nextPage%>">下一頁</a><a?href="List.jsp?page=<%=intPageCount%>"?temp_href="List.jsp?page=<%=intPageCount%>">最后頁?
</a>?
Xml方面?
1、xml有哪些解析技術?區別是什么??
答:有DOM,SAX,STAX等?
DOM:處理大型文件時其性能下降的非常厲害。這個問題是由DOM的樹結構所造成的,這種結構占用的內存較多,而且DOM必須在解析文件之前把整個文檔裝入內存,適合對XML的隨機訪問SAX:不現于DOM,SAX是事件驅動型的XML解析方式。它順序讀取XML文件,不需要一次全部裝載整個文件。當遇到像文件開頭,文檔結束,或者標簽開頭與標簽結束時,它會觸發一個事件,用戶通過在其回調事件中寫入處理代碼來處理XML文件,適合對XML的順序訪問?
STAX:Streaming?API?for?XML?(StAX)?
2、你在項目中用到了xml技術的哪些方面?如何實現的??
答:用到了數據存貯,信息配置兩方面。在做數據交換平臺時,將不能數據源的數據組裝成XML文件,然后將XML文件壓縮打包加密后通過網絡傳送給接收者,接收解密與解壓縮后再同XML文件中還原相關信息進行處理。在做軟件配置時,利用XML可以很方便的進行,軟件的各種配置參數都存貯在XML文件中。?
3、用jdom解析xml文件時如何解決中文問題?如何解析??
答:看如下代碼,用編碼方式加以解決?
package?test;?
import?java.io.*;?
public?class?DOMTest?
{?
private?String?inFile?=?"c:\\people.xml"?
private?String?outFile?=?"c:\\people.xml"?
public?static?void?main(String?args[])?
{?
new?DOMTest();?
}?
public?DOMTest()?
{?
try?
{?
javax.xml.parsers.DocumentBuilder?builder?=?
javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder();?
org.w3c.dom.Document?doc?=?builder.newDocument();?
org.w3c.dom.Element?root?=?doc.createElement("老師");?
org.w3c.dom.Element?wang?=?doc.createElement("王");?
org.w3c.dom.Element?liu?=?doc.createElement("劉");?
wang.appendChild(doc.createTextNode("我是王老師"));?
root.appendChild(wang);?
doc.appendChild(root);?
javax.xml.transform.Transformer?transformer?=?
javax.xml.transform.TransformerFactory.newInstance().newTransformer();?
transformer.setOutputProperty(javax.xml.transform.OutputKeys.ENCODING,?"gb2312");?
transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT,?"yes");?
transformer.transform(new?javax.xml.transform.dom.DOMSource(doc),?
new?
javax.xml.transform.stream.StreamResult(outFile));?
}?
catch?(Exception?e)?
{?
System.out.println?(e.getMessage());?
}?
}?
}?
4、編程用JAVA解析XML的方式.?
答:用SAX方式解析XML,XML文件如下:?
<?xml?version="1.0"?encoding="gb2312"?>?
<person>?
<name>王小明</name>?
<college>信息學院</college>?
<telephone>6258113</telephone>?
<notes>男,1955年生,博士,95年調入海南大學</notes>?
</person>?
事件回調類SAXHandler.java?
import?java.io.*;?
import?java.util.Hashtable;?
import?org.xml.sax.*;?
public?class?SAXHandler?extends?HandlerBase?
{?
private?Hashtable?table?=?new?Hashtable();?
private?String?currentElement?=?null;?
private?String?currentValue?=?null;?
public?void?setTable(Hashtable?table)?
{?
this.table?=?table;?
}?
public?Hashtable?getTable()?
{?
return?table;?
}?
public?void?startElement(String?tag,?AttributeList?attrs)?
throws?SAXException?
{?
currentElement?=?tag;?
}?
public?void?characters(char[]?ch,?int?start,?int?length)?
throws?SAXException?
{?
currentValue?=?new?String(ch,?start,?length);?
}?
public?void?endElement(String?name)?throws?SAXException?
{?
if?(currentElement.equals(name))?
table.put(currentElement,?currentValue);?
}?
}?
JSP內容顯示源碼,SaxXml.jsp:?
<HTML>?
<HEAD>?
<TITLE>剖析XML文件people.xml</TITLE>?
</HEAD>?
<BODY>?
<%@?page?errorPage="ErrPage.jsp"?
contentType="text/html;charset=GB2312"?%>?
<%@?page?import="java.io.*"?%>?
<%@?page?import="java.util.Hashtable"?%>?
<%@?page?import="org.w3c.dom.*"?%>?
<%@?page?import="org.xml.sax.*"?%>?
<%@?page?import="javax.xml.parsers.SAXParserFactory"?%>?
<%@?page?import="javax.xml.parsers.SAXParser"?%>?
<%@?page?import="SAXHandler"?%>?
<%?
File?file?=?new?File("c:\\people.xml");?
FileReader?reader?=?new?FileReader(file);?
Parser?parser;?
SAXParserFactory?spf?=?SAXParserFactory.newInstance();?
SAXParser?sp?=?spf.newSAXParser();?
SAXHandler?handler?=?new?SAXHandler();?
sp.parse(new?InputSource(reader),?handler);?
Hashtable?hashTable?=?handler.getTable();?
out.println("<TABLE?BORDER=2><CAPTION>教師信息表</CAPTION>");?
out.println("<TR><TD>姓名</TD>"?+?"<TD>"?+?
(String)hashTable.get(new?String("name"))?+?"</TD></TR>");?
out.println("<TR><TD>學院</TD>"?+?"<TD>"?+?
(String)hashTable.get(new?String("college"))+"</TD></TR>");?
out.println("<TR><TD>電話</TD>"?+?"<TD>"?+?
(String)hashTable.get(new?String("telephone"))?+?"</TD></TR>");?
out.println("<TR><TD>備注</TD>"?+?"<TD>"?+?
(String)hashTable.get(new?String("notes"))?+?"</TD></TR>");?
out.println("</TABLE>");?
%>?
</BODY>?
</HTML>?
EJB方面?
1、EJB2.0有哪些內容?分別用在什么場合??EJB2.0和EJB1.1的區別??
答:規范內容包括Bean提供者,應用程序裝配者,EJB容器,EJB配置工具,EJB服務提供者,系統管理員。這里面,EJB容器是EJB之所以能夠運行的核心。EJB容器管理著EJB的創建,撤消,激活,去活,與數據庫的連接等等重要的核心工作。JSP,Servlet,EJB,JNDI,JDBC,JMS.....?
2、EJB與JAVA?BEAN的區別??
答:Java?Bean?是可復用的組件,對Java?Bean并沒有嚴格的規范,理論上講,任何一個Java類都可以是一個Bean。但通常情況下,由于Java?Bean是被容器所創建(如Tomcat)的,所以Java?Bean應具有一個無參的構造器,另外,通常Java?Bean還要實現Serializable接口用于實現Bean的持久性。Java?Bean實際上相當于微軟COM模型中的本地進程內COM組件,它是不能被跨進程訪問的。Enterprise?Java?Bean?相當于DCOM,即分布式組件。它是基于Java的遠程方法調用(RMI)技術的,所以EJB可以被遠程訪問(跨進程、跨計算機)。但EJB必須被布署在諸如Webspere、WebLogic這樣的容器中,EJB客戶從不直接訪問真正的EJB組件,而是通過其容器訪問。EJB容器是EJB組件的代理,EJB組件由容器所創建和管理。客戶通過容器來訪問真正的EJB組件。?
3、EJB的基本架構?
答:一個EJB包括三個部分:?
Remote?Interface?接口的代碼?
package?Beans;?
import?javax.ejb.EJBObject;?
import?java.rmi.RemoteException;?
public?interface?Add?extends?EJBObject?
{?
//some?method?declare?
}?
Home?Interface?接口的代碼?
package?Beans;?
import?java.rmi.RemoteException;?
import?jaax.ejb.CreateException;?
import?javax.ejb.EJBHome;?
public?interface?AddHome?extends?EJBHome?
{?
//some?method?declare?
}?
EJB類的代碼?
package?Beans;?
import?java.rmi.RemoteException;?
import?javax.ejb.SessionBean;?
import?javx.ejb.SessionContext;?
public?class?AddBean?Implements?SessionBean?
{?
//some?method?declare?
}?
J2EE,MVC方面?
1、MVC的各個部分都有那些技術來實現?如何實現??
答:MVC是Model-View-Controller的簡寫。"Model"?代表的是應用的業務邏輯(通過JavaBean,EJB組件實現),?"View"?是應用的表示面(由JSP頁面產生),"Controller"?是提供應用的處理過程控制(一般是一個Servlet),通過這種設計模型把應用邏輯,處理過程和顯示邏輯分成不同的組件實現。這些組件可以進行交互和重用。?
2、應用服務器與WEB?SERVER的區別??
希望大家補上,謝謝?
3、J2EE是什么??
答:Je22是Sun公司提出的多層(multi-diered),分布式(distributed),基于組件(component-base)的企業級應用模型(enterpriese?application?model).在這樣的一個應用系統中,可按照功能劃分為不同的組件,這些組件又可在不同計算機上,并且處于相應的層次(tier)中。所屬層次包括客戶層(clietn?tier)組件,web層和組件,Business層和組件,企業信息系統(EIS)層。?
4、WEB?SERVICE名詞解釋。JSWDL開發包的介紹。JAXP、JAXM的解釋。SOAP、UDDI,WSDL解釋。?
答:Web?Service描述語言WSDL?
SOAP即簡單對象訪問協議(Simple?Object?Access?Protocol),它是用于交換XML編碼信息的輕量級協議。?
UDDI?的目的是為電子商務建立標準;UDDI是一套基于Web的、分布式的、為Web?Service提供的、信息注冊中心的實現標準規范,同時也包含一組使企業能將自身提供的Web?Service注冊,以使別的企業能夠發現的訪問協議的實現標準。?
5、BS與CS的聯系與區別。?
希望大家補上,謝謝?
6、STRUTS的應用(如STRUTS架構)?
答:Struts是采用Java?Servlet/JavaServer?Pages技術,開發Web應用程序的開放源碼的framework。?采用Struts能開發出基于MVC(Model-View-Controller)設計模式的應用構架。?Struts有如下的主要功能:?
一.包含一個controller?servlet,能將用戶的請求發送到相應的Action對象。?
二.JSP自由tag庫,并且在controller?servlet中提供關聯支持,幫助開發員創建交互式表單應用。?
三.提供了一系列實用對象:XML處理、通過Java?reflection?APIs自動處理JavaBeans屬性、國際化的提示和消息。?
設計模式方面?
1、開發中都用到了那些設計模式?用在什么場合??
答:每個模式都描述了一個在我們的環境中不斷出現的問題,然后描述了該問題的解決方案的核心。通過這種方式,你可以無數次地使用那些已有的解決方案,無需在重復相同的工作。主要用到了MVC的設計模式。用來開發JSP/Servlet或者J2EE的相關應用。簡單工廠模式等。?
2、UML方面?
答:標準建模語言UML。用例圖,靜態圖(包括類圖、對象圖和包圖),行為圖,交互圖(順序圖,合作圖),實現圖,?
JavaScript方面?
1、如何校驗數字型??
var?re=/^\d{1,8}$|\.\d{1,2}$/;?
var?str=document.form1.all(i).value;?
var?r=str.match(re);?
if?(r==null)?
{?
sign=-4;?
break;?
}?
else{?
document.form1.all(i).value=parseFloat(str);?
}?
CORBA方面?
1、CORBA是什么?用途是什么??
答:CORBA?標準是公共對象請求代理結構(Common?Object?Request?Broker?Architecture),由對象管理組織?(Object?Management?Group,縮寫為?OMG)標準化。它的組成是接口定義語言(IDL),?語言綁定(binding:也譯為聯編)和允許應用程序間互操作的協議。?其目的為:?
用不同的程序設計語言書寫?
在不同的進程中運行?
為不同的操作系統開發?
LINUX方面?
1、LINUX下線程,GDI類的解釋。?
答:LINUX實現的就是基于核心輕量級進程的"一對一"線程模型,一個線程實體對應一個核心輕量級進程,而線程之間的管理在核外函數庫中實現。?
GDI類為圖像設備編程接口類庫。
Hibernate:?簡述?Hibernate?和?JDBC?的優缺點??如何書寫一個?one?to?many?配置文件.
Spring?的依賴注入是什么意思??給一個?Bean?的?message?屬性,?字符串類型,?注入值為?"Hello"?的?XML?配置文件該怎么寫?
SCJP?模擬題200道附答案
Q1?Which?of?the?following?statements?are?valid,?given?the?following?variable?declarations:?boolean?a;?boolean?b;?int?c;?
1)?(a?|?b)?
2)(a?||?a)?
3)(a?^?b)?|?c?
4)(a?&?c)?
5)(a?&&?c)?
Q2?Which?of?the?following?can?be?applied?to?constructors:?
1)?final?
2)?static?
3)?synchronized?
4)?native?
5)?None?of?these.?
Q3?Which?of?the?following?retain?their?preferred?size?(width?and?height)?when?added?(individually)?to?the?North?section?of?a?container?with?a?BorderLayout?(assume?that?no?other?components?or?containers?are?present?in?the?North?section).?
1)?TextArea?
2)?Button?
3)?TextField?
4)?Checkbox?
5)?None.?All?of?these?mentioned?components?will?only?retain?their?preferred?height.?
Q4?Which?of?the?following?are?legal?names?for?variables.?
1)?_int?
2)?%large?
3)?$fred?
4)?Integer?
5)?2much?
Q5?Which?of?the?following?are?correct?ways?to?create?a?font.?
1)?Font?f?=?new?Font("Serif",?Font.BOLD,?24);?
2)?Font?f?=?new?Font(Font.SERIF,?"Bold",?24);?
3)?Font?f?=?new?Font("Serif",?"Bold",?24);?
4)?Font?f?=?new?Font(Font.SERIF,?Font.BOLD,?24);?
Q6?Select?the?correct?statements?regarding?the?following?piece?of?code.?
File?f?=?new?File("c:\\large.txt");?
1)?On?execution,?a?file?called?"large.txt"?will?be?created?on?the?local?harddisk.?
2)?The?code?fails?to?compile?on?a?UNIX?machine,?because?the?directory?separator?is?not?correct.?
3)?A?file?is?NOT?created?on?the?harddisk?when?this?code?is?executed.?
4)?An?exception?is?thrown?at?runtime?if?the?file?"large.txt"?already?exists.?
5)?The?code?fails?to?compile,?since?this?is?not?a?valid?constructor?for?the?File?class.?
Q7?Which?of?the?following?statements?are?correct?regarding?the?RandomAccessFile?class??
1)?An?IOException?is?thrown?if?the?specified?file?doesn't?exist?when?created?using?the?"r"?mode.?
2)?This?class?has?a?method?which?allows?a?file?to?be?deleted?from?the?harddisk.?
3)?It?is?possible?to?use?this?class?in?conjunction?with?the?DataInputStream?class.?
4)?When?used?with?the?"rw"?mode,?the?specified?file?is?created?on?a?diskdrive,?if?it?doesn't?already?exist.?
5)?There?are?methods?to?read?and?write?primatives?(eg,?readInt(),?writeInt(),?etc).?
Q8?Consider?the?following?piece?of?code?and?select?the?correct?statement?from?the?following.?
1.String?s?=?new?String("abcdefgh");?
2.s.replace('d',?'q');?
3.System.out.println(s);?
1)?The?code?fails?to?compile,?reporting?an?error?at?line?2.?Strings?are?immutable,?and?therefore?a?replace()?method?is?meaningless.?
2)?The?code?compiles?correctly,?and?displays?the?text?"abcqefgh".?
3)?The?code?compiles?correctly,?and?displays?the?text?"abcdefgh".?
4)?The?code?compiles,?but?an?exception?is?thrown?when?line?2?is?executed.?
5)?The?code?compiles,?but?an?exception?is?thrown?at?line?3.?
Q9?Which?of?the?following?keywords?can?be?applied?to?the?variables?or?methods?of?an?interface.?
1)?static?
2)?private?
3)?synchronised?
4)?protected?
5)?public?
Q10?True?or?False.?
Only?Frames?can?contain?menu?bars?or?pull-down?menus.?
1)?True?
2)?False.?
Q11?Consider?the?following?piece?of?code?and?select?the?correct?statement(s):?
1.?class?A{?
2.?protected?int?method(){?
3.?}?
4.?}?
5.?
6.?class?B?extends?A{?
7.?int?method(){?
8.?}?
9.?}?
1)?The?code?fails?to?compile,?because?you?can't?override?a?method?to?be?more?private?than?its?parent.?
2)?The?code?fails?to?compile,?because?method()?is?declared?as?protected,?and?is?therefore?not?available?to?any?subclass.?
3)?The?code?compiles?correctly,?but?throws?a?NullPointerException?at?runtime.?
4)?The?code?fails?to?compile.?However,?it?can?be?made?to?compile?correctly?by?prefixing?line?7?with?the?access?qualifier?"public".?
5)?The?code?fails?to?compile.?However,?it?can?be?made?to?compile?correctly?by?prefixing?line?7?with?the?access?qualifier?"protected".?
Q12?True?or?False.?
The?Throwable?class?is?the?superclass?of?all?exceptions?in?the?Java?language.?
1)?True?
2)?False?
Q13?Consider?the?following?piece?of?code?(assume?the?Graphics?context?g?is?defined?correctly):?
g.setBackground(Color.red);?
g.setForeground(Color.white);?
g.drawLine(10,?10,?50,?10);?
g.setForeground(Color.blue);?
g.drawRect(100,?100,?50,?50);?
What?is?displayed?when?this?code?is?executed.?
1)?A?blue?line?from?(10,10)?to?(50,10)?and?a?blue?rectangle?with?upper?left?corner?at?(100,100).?
2)?A?white?line?from?(10,10)?to?(50,10)?and?a?blue?square?with?top?left?corner?at?(100,100).?
3)?A?white?line?from?(10,10)?to?(10,50)?and?a?blue?square?with?lower?left?corner?at?(100,100).?
4)?A?red?line?from?(10,?10)?to?(50,10)?and?a?red?square?with?upper?left?corner?at?(100,100).?
5)?Nothing?is?displayed.?You?must?first?issue?a?repaint()?command.?
Q14?Consider?the?following?piece?of?code.?
class?Test{?
public?static?void?main(String?[]?args){?
System.out.println(args[3]);?
}?
}?
When?the?following?is?typed?at?the?command?line,?what?is?displayed:?
java?Test?Metallica?Justice?For?All?
1)?All?
2)?For?
3)?Justice?
4)?Nothing.?
5)?Nothing.?An?ArrayIndexOutOfBoundsException?is?thrown?
Q15?Consider?the?following?piece?of?code.?
1.?String?s?=?"abcd";?
2.?Integer?x?=?new?Integer(3);?
3.?String?s2?=?s?+?4;?
4.?s2?=?null;?
5.?s?=?null;?
Following?the?execution?of?which?line?above,?is?the?object?referenced?by?s2?available?for?garbage?collection.?
1)?Line?5?
2)?It?is?not?possible?to?say?when?an?object?is?available?for?garbage?collection.?
3)?Line?4?
4)?The?objects?are?not?available?until?the?executing?thread?is?ended.?
Q16?What?is?displayed?when?the?following?piece?of?code?is?compiled?and?executed:?
class?Test{?
public?static?void?main(String?[]?args){?
Base?b?=?new?Subclass();?
System.out.println(b.x);?
System.out.println(b.method());?
}?
}?
class?Base{?
int?x?=?2;?
int?method(){?
return?x;?
}?
}?
class?Subclass?extends?Base{?
int?x?=?3;?
int?method(){?
return?x;?
}?
}?
1)?Nothing.?The?code?fails?to?compile?because?the?object?b?is?not?created?in?a?valid?way.?
2)?2?
3?
3)?2?
2?
4)?3?
3?
5)?3?
2?
Q17?What?is?displayed?when?the?following?is?executed:?
String?s1?=?"aaa";?
s1.concat("bbb");?
System.out.println(s1);?
1)?The?string?"aaa".?
2)?The?string?"aaabbb".?
3)?Nothing.?concat()?is?not?a?valid?method?in?the?String?class.?
4)?The?string?"bbbaaa".?
5)?The?string?"bbb".?
Q18?True?or?False.?
The?following?is?a?valid?way?to?construct?a?StringBuffer.?
StringBuffer?sb1?=?"abcd";?
1)?True?
2)?False?
Q19?What?is?the?output?of?the?following?piece?of?code:?
1.?int?x?=?6;?
2.?double?d?=?7.7;?
3.?
4.?System.out.println((x?>?d)???99.9?:?9);?
1)?9?
2)?9.0?
3)?99.9?
4)?Nothing.?An?ArithmeticException?is?thrown?at?line?4.?
5)?6?
Q20?Which?of?the?following?can?be?put?in?applet?tags??(select?all?the?correct?answers)?
1)?CODE?
2)?WIDTH?
3)?HEIGHT?
4)?PARAM?
5)?ARCHIVE?
Q21?What?is?printed?out?following?the?execution?of?the?code?below:?
1.?class?Test{?
2.?static?String?s;?
3.?public?static?void?main(String?[]args){?
4.?int?x?=?4;?
5.?if?(x?<?4)?
6.?System.out.println("Val?=?"?+?x);?
7.?else?
8.?System.out.println(s);?
9.?}?
10.?}?
Nothing.?The?code?fails?to?compile?because?the?String?s?isn't?declared?correctly.?
1)?The?text?"Val?=?null"?is?displayed.?
2)?The?string?"Val?=?"?is?displayed.?
3)?The?text?"null"?is?displayed.?
4)?A?blank?line?of?text?is?printed.?
Q22?True?or?False.?
The?StringBuffer?class?does?not?have?a?concat()?method.?
1)?True?
2)?False?
Q23?What?is?displayed?when?the?following?piece?of?code?is?executed?(assume?the?graphics?context,?g,?is?correctly?set?up):?
g.drawString("abc",?10,?10);?
1)?The?text?"abc"?with?the?lower?left?part?of?"a"?located?at?x?=?10,?y?=?10.?
2)?The?text?"abc"?with?the?upper?left?part?of?"a"?located?at?x?=?10,?y?=?10.?
3)?Nothing.?This?is?not?a?valid?method.?
Q24?True?or?False.?
Anonymous?classes?cannot?have?constructors.?
1)?True?
2)?False?
Q25?To?reference?a?JAR?from?a?web?page,?which?of?the?following?keywords?are?used:?
1)?jar?
2)?class?
3)?zip?
4)?archive?
5)?package?
Q26?
Analyse?the?following?2?classes?and?select?the?correct?statements.?
class?A{?
private?int?x?=?0;?
static?int?y?=?1;?
protected?int?q?=?2;?
}?
class?B?extends?A{?
void?method(){?
System.out.println(x);?
System.out.println(y);?
System.out.println(q);?
}?
}?
1)?The?code?fails?to?compile?because?the?variable?x?is?not?available?to?class?B.?
2)?The?code?compiles?correctly,?and?the?following?is?displayed:?0?1?2?
3)?The?code?fails?to?compile?because?you?can't?subclass?a?class?with?private?variables.?
4)?Removing?the?line?"System.out.println(x)"?will?allow?the?code?to?compile?correctly.?
5)?The?compiler?will?complain?that?the?variable?x?in?class?B?is?undefined.?
Q27?Which?of?the?following?interfaces?can?be?used?to?manage?a?collection?of?elements,?with?no?duplication.?
1)?List?
2)?Vector?
3)?Set?
Q28?Which?of?the?following?statements?are?true?regarding?inner?classes.?
1)?Variables?defined?inside?inner?classes?cannot?be?static.?
2)?Variables?defined?inside?inner?classes?cannot?be?static?unless?the?inner?class?itself?is?static.?
3)?Non-static?inner?classes?(which?are?not?defined?in?a?method)?have?access?to?all?class?and?instance?variables,?regardless?of?the?access?qualifier?of?those?variables.?
4)?An?inner?class?can?actually?be?a?subclass?of?the?outer?class?
5)?Inner?classes?can?be?declared?as?private.?Top?level,?outer?classes?cannot.?
Q29?Which?of?the?following?are?valid?ways?to?define?an?abstract?method.?
1)?abstract?void?Test();?
2)?abstract?void?Test()?{}?
3)?static?abstract?void?Test();?
4)?final?abstract?void?Test();?
5)?Methods?cannot?be?defined?as?abstract,?only?variables?can?be?abstract.?
Q30?Consider?the?following:?
class?A?extends?Integer{?
int?x?=?0;?
}?
Select?all?valid?statements.?
1)?The?code?will?compile?correctly.?
2)?The?code?will?not?compile?because?Integer?is?final?and?cannot?be?subclassed.?
3)?The?code?will?not?compile?because?class?A?has?no?methods?or?constructor.?
4)?The?code?will?compile?correctly,?but?will?throw?an?ArithmeticException?at?runtime.?
Q31?Consider?the?following?and?select?the?correct?statement(s):?
interface?A{?
int?x?=?0;?
A(){?
x=?5;?
}?
A(int?s){?
x?=?s;?
}?
}?
1)?This?is?a?valid?piece?of?code?and?it?compiles?correctly.?
2)?The?default?constructor?is?not?required?since?the?compiler?will?create?one?for?you.?
3)?The?code?fails?to?compile?because?interfaces?cannot?have?more?than?1?constructor.?
4)?The?code?fails?to?compile?because?an?interface?cannot?have?any?constructors.?
5)?The?code?fails?to?compile,?because?a?class?must?have?more?than?1?character?in?it's?name.?
Q32?True?or?False.?
A?try?block?always?needs?a?catch?or?a?finally?block?(either?or?both,?but?not?none).?
1)?True?
2)?False
Q33?Which?of?the?following?are?valid?ways?to?declare?the?main()?method?which?is?used?to?start?a?Java?program.?
1)?public?static?void?main(String?[]?args)?
2)?static?public?void?main(String?[]?args)?
3)?public?void?main(String?args?[])?
4)?public?static?void?main(String?args[])?
5)?public?static?void?main(String?args)?
Q34?Consider?the?following?piece?of?code:?
boolean?b?=?true;?
System.out.println(b);?
What?is?displayed?when?this?code?is?executed??
1)?The?text?"true"?is?displayed.?
2)?The?text?"1"?is?displayed?
3)?The?code?fails?to?compile,?because?conversion?string?conversion?in?ths?System.out.println()?method?only?applies?to?integers.?
4)?The?code?compiles?but?nothing?is?displayed?upon?execution.?
5)?The?code?fails?to?compile.?However,?changing?the?first?line?to?"boolean?b?=?TRUE;"?will?correctly?declare?a?boolean,?and?the?code?will?compile?and?display?"TRUE".?
Q35?Which?of?the?following?pieces?of?code?compiles?without?any?errors??
1)?StringBuffer?sb1?=?"abcd";?
2)?Boolean?b?=?new?Boolean("abcd");?
3)?byte?b?=?255;?
4)?int?x?=?0x1234;?
5)?float?fl?=?1.2;?
Q36?Which?of?the?following?are?valid?statements?regarding?the?following?piece?of?code??
1.?String?s1?=?"abcd";?
2.?StringBuffer?sb1?=?new?StringBuffer("abcd");?
3.?int?val?=?6;?
4.?System.out.println(s1?+?val);?
5.?System.out.println(sb1?+?val);?
1)?The?text?"abcd6"?is?displayed?followed?by?"abcd6".?
2)?The?code?fails?to?compile?because?String?conversion?does?not?apply?to?StringBuffer.?
3)?The?code?compiles?but?upon?execution,?throws?a?NullPointerException?at?line?5.?
4)?The?code?fails?to?compile?at?line?2,?because?this?is?not?a?valid?way?to?create?a?StringBuffer.?
5)?The?code?fails?to?compile?at?line?1,?because?this?is?not?a?valid?way?to?create?a?String.?
Q37?True?or?False.?
Abstract?methods?can?be?declared?as?static.?
1)?True?
2)?False?
Q38?FlowLayout?is?the?default?layout?manager?for?which?of?the?following?containers:?
1)?Panel?
2)?Applet?
3)?Frame?
4)?Window?
5)?Dialog?
Q39?In?which?class?are?the?following?methods?defined:?
-?wait()?
-?notify()?
-?notifyAll()?
1)?Thread?
2)?Runnable?
3)?Object?
4)?Event?
5)?Synchronize?
Q40?Which?one?of?the?following?creates?an?instance?of?Vector?with?an?initial?capacity?of?10,?and?an?incremental?capacity?of?5.?
1)?new?Vector(10,?5);?
2)?new?Vector(5,10);?
3)?None.?There?is?no?constructor?of?Vector?which?provides?this?feature.?
4)?Vector?is?declared?as?final,?and?it?is?therefore?not?possible?to?instantiate?it.?
Q41?True?of?False.?
CheckboxGroup?is?a?subclass?of?Component.?
1)?True?
2)?False?
Q42?Which?statements(s)?below?are?true?about?the?following?piece?of?code.?
class?Test?implements?Runnable{?
public?static?void?main(String?[]?args){?
Thread?t?=?new?Thread(new?Test());?
t.start();?
}?
public?void?run(int?limit){?
for?(int?x?=?0;?x?<?limit;?x++)?
System.out.println(x);?
}?
}?
1)?All?the?numbers?up?to?(but?not?including)?"limit"?are?printed?out.?
2)?Nothing?is?displayed.?There?is?no?explicit?call?to?the?run()?method.?
3)?The?code?fails?to?compile?because?the?Runnable?interface?is?not?implemented?correctly.?
4)?The?code?can?be?made?to?compile?by?declaring?the?class?Test?to?be?abstract.?
5)?The?code?can?be?made?to?compile?by?removing?the?words?"implements?Runnable".?
Q43?Consider?the?following?code?and?select?the?statement(s)?which?are?true:?
1.?class?Test?extends?Frame{?
2.?
3.?public?static?void?main(String?[]?args){?
4.?Test?t?=?new?Test();?
5.?}?
6.?
7.?Test(){?
8.?Button?b?=?new?Button("Hello");?
9.?add(b,?BorderLayout.SOUTH);?
10.?}?
11.?
12.?}?
1)?The?code?compiles.?When?executed,?nothing?is?displayed.?
2)?The?code?compiles.?When?executed,?a?button?with?the?text?"Hello"?is?located?at?the?bottom?on?the?screen.?The?button?is?as?tall?as?the?text,?but?is?the?width?of?the?frame.?
3)?Adding?in?the?following?two?lines?between?lines?9?and?10?will?display?a?frame?with?a?button?at?the?bottom?of?the?frame:?setSize(100,?100);?setVisible(true);?
4)?The?code?fails?to?compile,?because?a?layout?manager?was?not?specified.?
5)?The?code?fails?to?compile?because?you?cannot?subclass?the?Frame?class.?
Q44?Before?which?of?the?following?can?the?keyword?"synchronized"?be?placed,?without?causing?a?compile?error.?
1)?class?methods?
2)?instance?methods?
3)?any?block?of?code?within?a?method?
4)?variables?
5)?a?class?
Q45?Consider?the?following?class?definitions:?
class?Base{}?
class?Subclass1?extends?Base{}?
class?Subclass2?extends?Base();?
Now?consider?the?following?declarations:?
Base?b?=?new?Base();?
Subclass1?s1?=?new?Subclass1();?
Subclass2?s2?=?new?Subclass2();?
Now,?consider?the?following?assignment:?
s1?=?(Subclass1)s2;?
Which?of?the?following?statements?are?correct?regarding?this?assignment?(select?one).?
1)?The?assignment?is?legal?and?compiles?without?an?error.?No?exception?is?thrown?at?runtime.?
2)?The?code?fails?to?compile.?The?compiler?complains?that?the?assignment?"s1?=?(Subclass1)s2"?is?illegal.?
3)?The?code?compiles?but?ClassCastException?is?thrown?at?runtime.?
4)?The?code?fails?to?compile.?You?cannot?subclass?a?parent?class?more?than?once.?
Q46?Select?all?the?valid?ways?of?initialising?an?array.?
1)?int?x[]?=?{1,2,3};?
2)?int?[]x[]?=?{{1,2,3},{1,2,3}};?
3)?int?x[3]?=?{1,2,3};?
4)?int?[]x?=?{0,0,0};?
5)?char?c[]?=?{'a',?'b'};?
Q47?What?is?the?valid?declaration?for?the?finalize()?method.?
1)?protected?void?finalize()?throws?Throwable?
2)?final?finalize()?
3)?public?final?finalize()?
4)?private?boolean?finalize()?
5)?private?final?void?finalize()?throws?Exception?
Q48?What?is?the?method?used?to?retrieve?a?parameter?passed?into?an?applet?using?the?PARAM?tag.?
1)?getParam()?
2)?getParameter()?
3)?getVariable()?
4)?getVar()?
5)?There?is?no?method?available.?You?must?use?"String?[]?args"?approach.?
Q49?You?have?a?button,?which?is?in?a?panel.?The?panel?is?inside?a?frame.?You?assign?the?Frame?a?24-point?font?and?a?background?colour?of?yellow.?You?set?the?panel?to?have?a?background?colour?of?red.?Which?of?the?following?statements?are?true?(select?all?valid?statements).?
1)?The?font?size?of?the?button?is?24-point.?
2)?The?background?colour?of?the?button?is?the?same?as?that?of?the?frame.?
3)?The?panel?has?a?font?size?of?8-point.?
4)?The?button?inherits?the?font?from?the?panel.?
5)?This?is?not?a?valid?configuration.?It?is?not?valid?to?place?a?panel?into?a?frame.?
Q50?Consider?the?following?piece?of?code?and?select?the?correct?statement(s):?
public?class?Test{?
final?int?x?=?0;?
Test(){?
x?=?1;?
}?
final?int?aMethod(){?
return?x;?
}?
}?
1)?The?code?fails?to?compile.?The?compiler?complains?because?there?is?a?final?method?("aMethod")?in?a?non-final?class.?
2)?The?code?compiles?correctly.?On?execution,?an?exception?is?thrown?when?the?Test()?constructor?is?executed.?
3)?The?code?fails?to?compile?because?an?attempt?is?made?to?alter?the?value?of?a?final?variable.?
4)?Removing?the?"final"?keyword?from?the?line?"final?int?x?=?0"?will?allow?the?code?to?compile?correctly.?
5)?The?code?fails?to?compile?because?only?methods?can?be?declared?as?final?(and?therefore?"final?int?x?=?0"?is?not?valid).?
Q51?What?is?displayed?when?the?following?code?fragment?is?compiled?and?executed?(assume?that?the?enveloping?class?and?method?is?correctly?declared?and?defined):?
StringBuffer?sb1?=?new?StringBuffer("abcd");?
StringBuffer?sb2?=?new?StringBuffer("abcd");?
String?s1?=?new?String("abcd");?
String?s2?=?"abcd";?
System.out.println(s1==s2);?
System.out.println(s1=s2);?
System.out.println(sb1==sb2);?
System.out.println(s1.equals(sb1));?
System.out.println(sb1.equals(sb2));?
1)?The?code?fails?to?compile,?complaining?that?the?line?System.out.println(s1=s2);?is?illegal.?
2)?The?code?fails?to?compile?because?the?equals()?method?is?not?defined?for?the?StringBuffer?class.?
3)?false?
true?
true?
false?
false?
4)?false?
abcd?
false?
false?
false?
5)?false?
true?
false?
false?
true?
Q52?What?is?the?default?layout?manager?for?applets?and?panels??
1)?FlowLayout?
2)?BorderLayout?
3)?GridBagLayout?
4)?GridLayout?
5)?None?of?these?
Q53?Which?of?the?following?statements?will?compile?without?an?error??
1)?Boolean?b?=?new?Boolean("abcd");?
2)?float?f?=?123;?
3)?byte?b?=?127;?
4)?int?x?=?(int)(1.23);?
5)?short?s?=?128;?
Q54?True?or?False.?
Menus?can?be?added?to?containers.?
1)?True?
2)?False?
Q55?Which?of?the?following?statements?are?true?regarding?the?graphical?methods?
paint(),?repaint()?and?update().?
1)?paint()?schedules?a?call?to?repaint().?
2)?repaint()?schedules?a?call?to?update().?
3)?update()?calls?paint().?
4)?update()?schedules?a?call?to?repaint().?
5)?repaint()?calls?paint()?directly.?
Q56?To?which?of?the?following?can?a?menubar?component?be?added??
1)?Applet?
2)?Panel?
3)?Frame?
4)?Canvas?
Q57?With?regard?to?apply?applet?by?HTML?tags,?which?of?the?following?statements?are?correct??
1)?The?CODE,?WIDTH?and?HEIGHT?tags?are?mandatory?and?the?order?is?insignificant.?
2)?CODE?and?CODEBASE?are?case?insensitive,?and?the?.class?extension?is?optional.?
3)?The?PARAM?tag?is?case?insensitive.?
4)?It?is?possible?to?download?multiple?JAR's?with?the?ARCHIVE?tag?(eg,?ARCHIVE?=?"a.jar,?b.jar").?
5)?The?CODE?tag?is?the?only?mandatory?tag.?
Q58?Consider?the?following?piece?of?code?and?select?the?correct?statements.?
1.?Object?o?=?new?String("abcd");?
2.?String?s?=?o;?
3.?System.out.println(s);?
4.?System.out.println(o);?
1)?The?following?is?displayed:?
abcd?
abcd?
2)?The?code?fails?to?compile?at?line?1.?
3)?The?code?fails?to?compile?at?line?2?
4)?The?code?fails?to?compile?at?line?4.?
5)?The?code?can?be?made?to?compile?by?changing?line?1?to?the?following:?
String?o?=?new?String("abcd");?
Q59?Which?of?the?following?are?legal?methods?for?the?String?class??
1)?length()?
2)?toUpper()?
3)?toUpperCase()?
4)?toString()?
5)?equals()?
Q60?What?is?the?output?from?the?following?piece?of?code:?
loop1:?
for(int?i?=?0;?i?<?3;?i++){?
loop2:?
for(int?j?=?0;?j?<?3;?j++){?
if?(i?==?j){?
break?loop2;?
}?
System.out.print("i?=?"?+?i?+?"?j?=?"?+?j?+?"?");?
}?
}?
1)?
i?=?1?
j?=?0?
2)?
i?=?1?
j?=?0?
i?=?2?
j?=?1?
3)?i?=?0?
j?=?1?
i?=?0?
j?=?2?
i?=?1?
j?=?0?
i?=?2?
j?=?0?
i?=?2?
j?=?1?
4)?i?=?1?
j?=?0?
i?=?2?
j?=?0?
i?=?2?
j?=?1?
5)?
i?=?1?j?=?0?i?=?2?j?=?0?i?=?2?j?=?1?
Q61?What?is?displayed?when?the?following?piece?of?code?is?executed:?
loop1:?
for(int?i?=?0;?i?<?3;?i++){?
loop2:?
for(int?j?=?0;?j?<?3;?j++){?
if?(i?==?j){?
continue?loop2;?
}?
System.out.println("i?=?"?+?i?+?"?j?=?"?+?j);?
}?
}?
1)?i?=?0?j?=?0?
i?=?0?j?=?1?
i?=?1?j?=?0?
i?=?1?j?=?1?
i?=?2?j?=?0?
i?=?2?j?=?1?
2)?i?=?0?j?=?0?
i?=?1?j?=?1?
i?=?2?j?=?2?
3)?i?=?0?j?=?1?
i?=?0?j?=?2?
i?=?1?j?=?0?
i?=?1?j?=?2?
i?=?2?j?=?0?
i?=?2?j?=?1?
4)?None?of?the?above.?
Q62?Consider?the?following?piece?of?code,?and?select?the?correct?statement(s):?
long?val?=?2;?
...?
...?
Switch?(val){?
default:?
System.out.println("Default");?
break;?
case?1:?
System.out.println("1");?
break;?
case?2:?
System.out.println("2");?
case?3:?
System.out.println("3");?
break;?
}?
1)?The?following?is?displayed:?
2?
3?
2)?The?following?is?displayed:?
2?
3)?The?code?fails?to?compile?because?the?default?case?must?be?the?last?case?in?the?switch?statement.?
4)?The?code?fails?to?compile?because?the?argument?for?a?switch?statement?cannot?be?a?variable?of?type?long.?
5)?The?following?is?displayed:?
2?
3?
Default?
Q63?Consider?the?following?piece?of?code,?and?select?the?correct?statement(s):?
public?class?Test?extends?Applet{?
public?void?init(){?
setLayout(new?GridLayout(1,2));?
add(new?Button("#1"));?
add(new?Button("#2"));?
add(new?Button("#3"));?
add(new?Button("#4"));?
}?
}?
1)?The?Gridlayout?is?created?with?1?row?and?2?columns.?
2)?Adding?the?button?with?the?label?"#3"?will?cause?an?exception?to?be?thrown.?
3)?Adding?the?button?with?label?"#3"?will?cause?it?to?overwrite?the?button?with?label?"#2".?
4)?The?layout?automatically?extends?to?accommodate?the?additional?buttons.?
5)?Only?2?buttons?are?displayed,?one?with?label?"#1"?and?one?with?label?"#4".?
Q64?Which?of?the?following?layout?managers?will?retain?the?preferred?width?and?height?of?the?contained?components.?
1)?GridLayout?
2)?GridBagLayout?
3)?BoxLayout?
4)?FlowLayout?
5)BorderLayout?
Q65?You?construct?a?List?by?calling?List(5,?false).?
Which?statements?below?are?correct?(assume?the?layout?managers?do?not?modify?the?List?properties).?
1)?The?list?supports?multiple?selection.?
2)?The?list?has?5?visible?items.?
3)?A?vertical?scroll?bar?will?be?added?automatically?if?needed.?
4)?The?code?fails?to?compile.?The?given?constructor?is?not?a?valid?one.?
Q66?Which?of?the?following?will?definitely?stop?a?thread?from?executing:?
1)?wait()?
2)?notify()?
3)?yield()?
4)?suspend()?
5)?sleep()?
Q67?Which?of?the?following?is?the?correct?method?to?call?to?change?the?layout?manager?for?a?container:?
1)?setLayoutManager()?
2)?setLayManager()?
3)?changeLayout()?
4)?You?can't?change?the?layout?manager?for?a?container.?
5)?setLayout()?
Q68?Which?is?the?correct?way?to?add?a?button,?referenced?by?b,?to?a?panel,?referenced?by?p.?
1)?add(p,?b);?
2)?p.add(b)?
3)?b.add(p)?
4)?Buttons?can't?be?added?to?panels.?
5)?add(p)?
Q69?What?is?displayed?when?the?following?code?is?compiled?and?executed:?
long?val?=?2;?
switch(val){?
case?1:?
System.out.println("1");?
case?2:?
System.out.println("2");?
default:?
System.out.println("default");?
}?
1)?default?
2)?2?
default?
3)?The?code?fails?to?compile?because?there?are?no?break?statements?in?the?case?clauses.?
4)?The?code?fails?to?compile?because?a?long?data?type?is?not?a?valid?parameter?for?a?switch?statement.?
Q70?What?is?displayed?following?the?execution?of?the?code?below:?
1.?class?Test{?
2.?String?s;?
3.?public?static?void?main(String?[]args){?
4.?int?x?=?4;?
5.?if?(x?<?4)?
6.?System.out.println("Val?=?"?+?x);?
7.?else?
8.?System.out.println(s);?
9.?}?
10.?}?
1)?Nothing.?The?code?doesn't?compile?because?the?variable?s?wasn't?initialised.?
2)?The?string?"null"?is?displayed.?
3)?The?code?runs,?but?a?NullPointerException?is?thrown?at?line?8.?
4)?The?code?compiles.?No?exception?is?thrown?but?nothing?is?displayed.?
5)?Nothing.?The?code?doesn't?compile?because?you?can't?make?a?static?reference?to?a?non-static?variable.?
Q71?Consider?the?following?piece?of?code:?
class?Test{?
int?x;?
String?s;?
float?fl;?
boolean?[]?b?=?new?boolean?[5];?
public?static?void?main(String?[]args){?
System.out.println(x);?
System.out.println(s);?
System.out.println(fl);?
System.out.println(b[2]);?
}?
}?
What?is?displayed?when?this?code?is?executed.?
1)?0?
null?
0.0?
false?
2)?0?
"?"?
0.0?
true?
3)?Nothing.?The?code?fails?to?compile?because?the?boolean?array?is?incorrectly?declared.?
4)?Nothing.?The?code?will?not?compile?because?the?static?method?cannot?access?the?variables?since?there?is?no?instance?of?the?Test?class.?
Q72?What?is?displayed?when?the?following?code?is?compiled?and?executed:?
String?s?=?"abcd";?
String?s1?=?new?String(s);?
if?(s?==?s1)?
System.out.println("the?same");?
if?(s.equals(s1))?
System.out.println("equals");?
1)?the?same?
equals?
2)?equals?
3)?the?same?
4)?The?code?compiles,?but?nothing?is?displayed?upon?execution.?
5)?The?code?fails?to?compile.?
Q73?What?is?the?legal?range?for?the?byte?data?type:?
1)?0?to?+255?
2)?-127?to?+128?
3)?-128?to?+127?
4)?0?to?65535?
5)?-32767?to?+32768?
Q74?What?is?displayed?when?the?following?code?is?executed:?
String?s?=?"abcdef";?
System.out.println(s.charAt(4));?
1)?d?
2)?e?
3)?Nothing.?An?ArrayIndexOutOfBoundsException?is?thrown?
4)?The?code?does?not?compile.?charAt()?is?not?a?valid?method?of?the?String?class.?
5)?The?code?does?not?compile?because?the?string?s?is?not?created?correctly.?
Q75?True?or?False.?
The?String?class?does?not?have?an?append()?method.?
1)?True?
2)?False?
Q76?Consider?the?following?code?segment.?
double?d?=?-11.1;?
double?d1?=?method(d);?
System.out.println(d1);?
If?the?output?of?this?code?segment?is?-12.0,?then?what?methods?could?be?called?in?method()?above.?
1)?floor()?
2)?ceil()?
3)?round()?
4)?abs()?
5)?min()?
Q77?What?outputs?are?possible?from?invoking?Math.random().?
1)?-0.12?
0.56E3?
2)?0.12?
1.1E1?
3)?-23.45?
0.0?
4)?0.356?
0.03?
5)?1.00?
0.99?
Q78?In?a?thread,?the?wait()?method?must?be?called?inside?which?of?the?following:?
1)?A?while()?loop?
2)?The?run()?method?
3)?synchronised?code?
4)?The?constructor?
5)?It?doesn't?matter?where?the?wait()?is?called?from.?
Q79?Consider?the?following?piece?of?code:?
public?class?Test?extends?Applet{?
public?void?init(){?
setLayout(new?BorderLayout());?
add("South",?new?Button("B1"));?
add("North",?new?Button("B2"));?
add("South",?new?Button("B3"));?
}?
}?
Select?the?correct?statements?regarding?the?above.?
1)?There?are?2?buttons?displayed?in?the?SOUTH?section,?B1?and?B3.?
2)?Only?B3?is?displayed?in?the?SOUTH?section.?
3)?An?exception?is?thrown?when?an?attempt?is?made?to?add?a?second?component?to?SOUTH.?
4)?Only?B1?is?displayed?in?the?SOUTH?section.?
5)?You?can't?add?buttons?to?applets.?
Q80?What?is?displayed?when?the?following?piece?of?code?is?executed:?
1.?String?val?=?null;?
2.?int?x?=?Integer.parseInt(val);?
3.?
4.?System.out.println(x);?
1)?0?
2)?null?
3)?A?NumberFormatException?is?thrown?at?line?2.?
4)?Nothing?is?displayed?
Q81?Consider?the?following?piece?of?code:?
class?A{?
int?x?=?0;?
A(int?w){?
x?=?w;?
}?
}?
class?B?extends?A{?
int?x?=?0;?
B(int?w){?
x?=?w?+1;?
}?
}?
1)?The?code?compiles?correctly.?
2)?The?code?fails?to?compile,?because?both?class?A?and?B?do?not?have?valid?constructors.?
3)?The?code?fails?to?compile?because?there?is?no?default?no-args?constructor?for?class?A.?
Q82?Given?an?object?myListener?(whose?class?implements?the?ActionListener?interface),?which?of?the?following?are?valid?ways?to?enable?myListener?to?receive?all?action?events?from?component?smallButton??
1)?smallButton.add(myListener);?
2)?smallButton.addListener(myListener);?
3)?smallButton.addActionListener(myListener);?
4)?smallButton.addItem(myListener);?
Q83?Which?of?the?following?are?valid?listener?interfaces??
1)?ActionListener?
2)?MouseMotionListener?
3)?SystemEventListener?
4)?MouseClickListener?
5)?WindowListener?
Q84?Which?of?the?following?is?the?correct?way?to?set?the?foreground?colour?of?a?component,?c.?
1)?c.setForeground("red");?
2)?c.setColor("Color.red");?
3)?c.Foreground(Color.red);?
4)?c.setForegroundColor("red");?
5)?c.setForeground(Color.red);?
Q85?Which?of?the?following?are?valid?ways?to?create?a?Map?collection.?
1)?Map?m?=?new?Map();?
2)?Map?m?=?new?Map(init?capacity,?increment?capacity);?
3)?Map?m?=?new?Map(new?Collection());?
4)Map?is?an?interface,?and?cannot?be?instantiated.?
Q86?Select?all?the?correct?statements?relating?to?the?following?piece?of?code??
1.?public?class?A{?
2.?abstract?int?method();?
3.?void?anotherMethod(){?
4.?}?
5.?
6.?class?B?extends?A{?
7.?int?method(){?
8.?return?2;?
9.?}?
10.?}?
1)?Changing?"extends"?to?"implements"?on?line?6?will?allow?the?code?to?compile?correctly.?
2)?The?method()?in?class?A?cannot?be?abstract?without?the?entire?class?being?declared?as?abstract.?
3)?Declaring?class?A?to?be?abstract?will?allow?the?code?to?compile?correctly.?
4)?The?class?A?must?have?an?explicit?default?constructor?in?order?for?it?to?be?subclassed?correctly.?
5)?The?code?fails?to?compile,?because?class?B?does?not?implement?anotherMethod().?
Q87?Which?layout?manager?do?the?comments?below?refer?to:?
All?components?contained?in?it?have?the?same?width?and?height.?Contained?components?are?stretched?to?have?the?same?dimensions.?
1)?FlowLayout?
2)?BorderLayout?
3)?GridLayout?
Q88?Select?all?valid?statements.?
1)?When?typing?text?into?a?TextField,?scroll?bars?will?automatically?appear?when?the?TextField?becomes?full.?
2)?When?typing?text?into?a?TextArea,?scroll?bars?will?appear?when?text?is?typed?past?the?boundaries?of?the?TextArea.?
3)?TextFields?can?have?more?than?1?row?of?text.?
4)?The?class?TextArea?is?a?super?class?of?the?class?TextField.?
5)?Both?TextAreas?and?TextFields?have?a?method?called?setEditable(),?which?can?enable?or?disable?editing?of?the?component.?
Q89?In?which?class?is?the?paint()?method?defined??
1)?Object?
2)?Applet?
3)?Component?
4)?Thread?
5)?Graphics?
Q90?Select?the?statement?which?most?closely?describes?the?user?interface?of?an?applet?with?the?following?init()?method:?
public?void?init(){?
Panel?p?=?new?Panel();?
p.setLayout(new?BorderLayout());?
p.add(new?Button("Hello"),?BorderLayout.EAST);?
p.add(new?Button("Bye"),?BorderLayout.WEST);?
add(p);?
}?
1)?Two?buttons?are?displayed.?A?button?with?"Hello"?is?on?the?right?side?of?the?applet.?The?button?with?"Bye"?is?on?the?left?side?of?the?applet.?Both?buttons?extend?from?the?centre?of?the?applet?to?each?side,?and?are?the?height?of?the?applet.?
2)?Two?buttons?are?displayed.?A?button?with?"Hello"?is?on?the?right?side?of?the?applet.?The?button?with?"Bye"?is?on?the?left?side?of?the?applet.?Both?buttons?are?only?as?wide?as?the?text?on?the?button,?but?are?the?height?of?the?applet.?
3)?Two?buttons?are?displayed.?A?button?with?"Hello"?is?on?the?right?side?of?the?applet.?The?button?with?"Bye"?is?on?the?left?side?of?the?applet.?Both?buttons?are?only?large?enough?to?support?the?associated?button?texts.?
Q91?What?is?wrong?about?the?following?piece?of?code?(assume?the?relevant?import?statements?are?present):?
public?class?Test{?
public?static?void?main?(String?[]?args)?throws?IOException{?
if?(args[0]?==?"hello")?
throw?new?IOException();?
}?
}?
1)?Nothing.?The?code?compiles?correctly.?
2)?The?code?fails?to?compile.?You?can't?throw?an?exception?from?the?main()?method.?
3)?The?code?fails?to?compile.?IOException?is?a?system?exception,?and?cannot?be?thrown?by?application?code.?
Q92?Consider?the?following?piece?of?code,?and?select?the?statements?which?are?true.?
class?Test{?
int?x?=?5;?
static?String?s?=?"abcd";?
public?static?void?method(){?
System.out.println(s?+?x);?
}?
}?
1)?The?code?compiles?and?displays?"abcd5".?
2)?The?code?compiles,?but?throws?an?exception?at?runtime,?because?variable?x?isn't?declared?as?static.?
3)?The?code?fails?to?compile?because?you?can't?make?a?static?reference?to?a?non-static?variable.?
4)?The?code?will?compile?if?x?is?declared?to?be?static.?
5)?The?code?will?compile?by?removing?the?static?keyword?from?the?declaration?of?method().?
Q93?Select?all?legal?code?fragments?from?the?following.?
1)?char?c?=?"c";?
2)?Boolean?b?=?new?Boolean("qwerty");?
3)?String?s?=?"null";?
4)?int?q;?
for?(int?p?=?0,?q?=?0;?p?<?5;?p++){?
System.out.println("Val?=?"?+?p?+?q);?
}?
5)?int?x?=?3;?
Float?f?=?new?Float(x);?
Q94?Which?of?the?following?are?legal?ways?to?construct?a?RandomAccessFile??
1)?RandomAccessFile("file",?"r");?
2)?RandomAccessFile("r",?"file");?
3)?RandomAccessFile('r',?"file");?
4)?RandomAccessFile("file",?'r');?
5)?RandomAccessFile("file",?"rw");?
Q95?Consider?the?following?code?and?select?the?most?appropriate?statements.?
1.?class?Test{?
2.?public?int?doubleValue(int?a)?
3.?System.out.println(a);?
4.?return?(int)(a?*?2);?
5?}?
6.?
7?public?float?doubleValue(int?a){?
8.?System.out.println(a);?
9.?return?(float)(a?*?2);?
10.?}?
11.}?
1)?The?code?compiles?since?the?two?doubleVal()?methods?have?different?return?types.?
2)?The?code?doesn't?compile?because?the?compiler?sees?two?methods?with?the?same?signature.?
3)?The?code?can?be?made?to?compile?by?redefining?the?parameter?for?doubleVal()?on?line?7?to?be?"float?a"?instead?of?"int?a".?
4)?The?code?can?be?made?to?compile?by?replacing?the?public?declaration?on?line?7?with?private.?
Q96?What?is?displayed?when?the?following?piece?of?code?is?executed:?
class?Test?extends?Thread{?
public?void?run(){?
System.out.println("1");?
yield();?
System.out.println(2");?
suspend();?
System.out.println("3");?
resume();?
System.out.println("4");?
}?
public?static?void?main(String?[]args){?
Test?t?=?new?Test();?
t.start();?
}?
}?
1)?1?
2?
3?
4?
2)?1?
2?
3?
3)?1?
2?
4)?Nothing.?This?is?not?a?valid?way?to?create?and?start?a?thread.?
5)?1?
Q97?Consider?the?following?piece?of?code,?and?select?the?most?appropriate?statements.?
TextField?t?=?new?TextField("Hello",?20);?
1)?The?user?will?be?able?to?edit?the?string.?
2)?The?field?will?be?20?characters?wide.?
3)?The?text?field?will?be?same?size?on?all?platforms,?since?Java?is?platform?independent.?
4)?When?entering?text?into?the?field,?only?20?characters?can?be?entered.?
5)?If?the?font?is?changed,?the?size?of?the?textfield?will?adjust?to?allow?20?characters?to?be?displayed.?
Q98?True?of?False.?
Using?the?instanceof?operator?on?an?interface?will?cause?a?runtime?exception.?
1)?True?
2)?False?
Q99?Which?of?the?following?are?valid?ways?to?create?a?Button?component??
1)?new?Button();?
2)?new?Button(30,?10);?where?30?is?the?width?of?the?button?and?10?is?the?height?
3)?new?Button("hello");?
4)?new?Button(new?String("hello"));?
5)?new?Button(String("hello"));?
Q100?Which?of?the?following?are?NOT?valid?subclasses?of?AWTEvent??
1)?MouseClickEvent?
2)?OutputEvent?
3)?MouseMotionEvent?
4)?KeyAdapter?
5)?WindowMinimizeEvent?
Q101?Which?of?the?following?are?valid?methods?for?the?Graphics?class??
1)?drawOval(int?x,?int?y,?int?width,?int?height)?
2)?toString()?
3)?drawArc(int?x,?int?y,?int?width,?int?height,?int?startAngle,?int?arcAngle)?
4)?drawPolygon(int[]?xPoints,?int[]?yPoints,?int?nPoints)?
5)?fillArc(int?x,?int?y,?int?width,?int?height,?int?startAngle,?int?arcAngle)?
Q102?Which?of?the?following?are?valid?methods?in?the?Math?class??
1)?arcTan(double?a)?
2)?atan(double?a)?
3)?sqrt(double?a)?
4)?min(int?a,?int?b)?
5)?cosine(double?a)?
Q103?Which?of?the?following?will?display?the?string?"ica",?given:?
String?s?=?"Metallica";?
1)?System.out.println(s.subString(7));?
2)?System.out.println(s.substring(6));?
3)?System.out.println(s.subString(6,?8));?
4)?System.out.println(s.substring(7,?9));?
5)?None?of?these.?
Q104?Which?of?the?following?are?defined?in?the?Object?class??
1)?toString()?
2)?equals(Object?o)?
3)?public?static?void?main(String?[]?args)?
4)?System.out.println()?
5)?wait()?
Q105?Select?all?valid?statements?relating?to?the?paint()?method?defined?in?the?Component?class.?
1)?It?takes?4?int?types?as?parameters,?representing?the?x?and?y?co-ordinates,?width?and?height,?respectively.?
2)?It?is?declared?as?final,?and?so?it?cannot?be?overridden.?
3)?It?is?declared?as?static.?
4)?It?takes?an?instance?of?the?Graphics?component?as?a?parameter.?
5)?When?overriding?the?paint()?method,?you?must?handle?the?identification?and?repair?of?damaged?components.?
Q106?Which?of?the?following?keywords?can?be?applied?to?a?method??
1)?transient?
2)?volatile?
3)?private?
4)?protected?
5)?final?
Q107?Which?of?the?following?keywords?can?be?applied?to?a?top-level?class?(i.e.,?not?an?inner?class)??
1)?private?
2)?protected?
3)?transient?
4)?public?
5)?final?
Q108?Consider?the?following?piece?of?code,?and?select?all?relevant?statements:?
1.?class?Test{?
2.?public?static?void?main(String?[]?args){?
3.?aMethod();?
4.?}?
5.?
6.?static?void?aMethod(){?
7.?try{?
8.?System.out.println("abcd");?
9.?return;?
10.?}?finally?{?
11.?System.out.println("1234");?
12.?}?
13.?}?
14.}?
1)?An?exception?is?thrown?at?line?9.?
2)?The?code?fails?to?compile.?The?compiler?complains?about?the?return?statement?at?line?9.?
3)?abcd?
1234?
4)?abcd?
5)?The?code?fails?to?compile,?complaining?that?a?'catch'?clause?is?missing?from?line?10.?
Q109?Which?of?the?following?statements?are?true.?
1)?The?type?"int"?is?a?32-bit?signed?integer?value.?
2)?The?type?"short"?is?a?16-bit?unsigned?integer?value.?
3)?The?type?"char"?is?a?16-bit?Unicode?character.?
4)?The?type?"float"?is?a?64-bit?floating?point?value.?
5)?The?type?"long"?is?a?64-bit?signed?integer?value.?
Q110?Which?layout?manager?is?described?by?the?following:?
It?aligns?components?vertically?and?horizontally,?without?requiring?that?the?components?be?of?the?same?size.?It?maintains?a?dynamic?rectangular?grid?of?cells,?with?each?component?occupying?one?or?more?cells,?called?its?display?area.?
1)?GridLayout?
2)?FlowLayout?
3)?GridBagLayout?
4)?BoxLayout?
Q111?True?of?False.?
The?StringBuffer?class?overrides?the?toString()?method?to?return?a?String?representation?of?the?StringBuffer.?
1)?True?
2)?False?
Q112?Select?the?correct?statements?from?the?following:?
1)?The?class?RandomAccessFile?is?a?subclass?of?the?java.io.File?class.?
2)?The?class?java.io.FileWriter?contains?methods?to?write?primitives?(eg,?writeInt(),?writeFloat(),?etc)?
3)?The?class?java.io.BufferedOutputStream?contains?methods?to?write?primitives?(eg,?writeInt(),?writeFloat(),?etc)?
4)?The?File?class?defines?a?method?which?can?be?used?to?delete?files?and?directories?from?a?disk.?
5)?The?RandomAccessFile?class?defines?a?method?which?can?be?used?to?delete?files?and?directories?from?a?disk.?
Q113?True?or?False.?
A?class?can?implement?more?than?one?interface,?but?can?only?inherit?from?a?single?parent?class.?
1)?True?
2)?False?
Q114?What?is?the?result?of?compiling?and?executing?the?following?code.?
public?class?ThreadTest?extends?Thread?{?
public?void?run()?{?
System.out.println("In?run");?
yield();?
System.out.println("Leaving?run");?
}?
public?static?void?main(String?args?[])?{?
(new?ThreadTest()).start();?
}?
}?
1)?The?code?fails?to?compile?in?the?main()?method.?
2)?The?code?fails?to?compile?in?the?run()?method.?
3)?Only?the?text?"In?run"?will?be?displayed.?
4)?The?text?"In?run"?followed?by?"Leaving?run"?will?be?displayed.?
5)?The?code?compiles?correctly,?but?nothing?is?displayed.?
Q115?Which?of?the?following?will?compile?without?errors.?
1)?Byte?b?=?new?Byte(123);?
2)?Byte?b?=?new?Byte("123");?
3)?Byte?b?=?new?Byte();?
b?=?123;?
4)?Byte?b?=?new?Byte((int)123.4);?
5)?Byte?b?=?new?Byte(0x123);?
Q116?Consider?the?following?piece?of?code?and?select?the?correct?statement(s):?
1.?public?class?Test{?
2.?static?int?x;?
3.?static?public?void?main(String?[]?args){?
4.?x?=?x?+?1;?
5.?System.out.println("Value?is?"?+?x);?
6.?}?
7.?}?
1)?The?code?fails?to?compile.?The?compiler?complains?that?the?variable?x?is?used?before?it?is?initialised.?
2)?The?code?compiles?correctly?and?displays?"Value?is?1"?when?executed.?
3)?The?code?compiles?correctly,?but?throws?a?NullPointerException?at?line?5.?
4)?The?code?fails?to?compile?because?the?'main'?method?is?incorrectly?declared.?
Q117?Which?of?the?following?are?termed?"short?circuit"?logical?operators.?
1)?&?
2)?&&?
3)?|?
4)?||?
5)?^?
Q118?Which?of?the?following?are?valid?expressions.?
1)?Object?o?=?new?String("abcd");?
2)?Boolean?b?=?true;?
3)?Panel?p?=?new?Frame();?
4)?Applet?a?=?new?Panel()?
5)?Panel?p?=?new?Applet()?
Q119?Which?of?the?following?is?a?valid?way?to?declare?an?abstract?method?which?is?intended?to?be?public.?
1)?public?abstract?method();?
2)?public?abstract?void?method();?
3)?public?abstract?void?method(){}?
4)?public?virtual?void?method();?
5)?public?void?method()?implements?abstract;?
Q120?Which?of?the?following?are?valid?ways?to?define?a?constructor?for?class?Test.?
1)?public?void?Test(){}?
2)?public?Test(){}?
3)?private?Test(){}?
4)?public?static?Test(){}?
5)?final?Test(){}?
Q121?Which?of?the?following?statements?are?valid?for?a?method?which?is?overriding?the?following:?
protected?void?method(int?x){..}?
1)?The?overriding?method?must?take?an?int?as?its?only?parameter.?
2)?The?overriding?method?must?return?a?void.?
3)?The?overriding?method?can?be?declared?as?private.?
4)?The?overriding?method?can?return?any?value?it?wishes.?
Q122?True?or?False.?
An?inner?class?can?implement?an?interface?or?extend?a?class.?
1)?True?
2)?False?
Q123?Which?of?the?following?are?valid?return?types?for?listener?methods.?
1)?boolean?
2)?void?
3)?An?object?of?type?Event?
4)?An?object?of?type?Object?
5)?A?long?value,?representing?the?Object?ID.?
Q124?Consider?the?following?piece?of?code?and?select?the?correct?statements.?
1.?public?class?Test{?
2.?public?static?void?main(String?[]?args){?
3.?print();?
4.?}?
5.?
6.?public?static?void?print(){?
7.?System.out.println("Test");?
8.?}?
9.?
10.?public?void?print(){?
11.?System.out.println("Another?Test");?
12?}?
13.?}?
1)?The?code?compiles?successfully?and?displays?"Test".?
2)?Changing?the?code?at?line?10?to?the?following,?will?allow?the?code?to?compile?correctly:?
public?void?print(int?x){?
3)?The?code?fails?to?compile.?The?compiler?complains?about?a?static?reference?to?a?non-static?method,?print().?
4)?The?code?fails?to?compile.?The?compiler?complains?about?duplicate?methods.?
5)?Changing?the?return?type?on?line?10?from?'void'?to?'int'?will?allow?the?code?to?compile?correctly.?
Q125?Consider?the?following?list?of?tags?and?attributes?of?tags?and?select?the?ones?which?can?legally?be?placed?between?the?APPLET?and?/APPLET?delimiters.?
1)?JAVAC?
2)?JAR?
3)?CODE?
4)?NAME?
5)?PARAM?
Q126?Which?variables?can?an?inner?class?access?from?the?class?which?encapsulates?it.?
1)?All?static?variables?
2)?All?final?variables?
3)?All?instance?variables?
4)?Only?final?instance?variables?
5)?Only?final?static?variables?
Q127?Using?a?FlowLayout?manager,?which?of?the?following?is?the?correct?way?to?add?a?conponent?referenced?by?the?variable?"c"?to?a?container:?
1)?add(c);?
2)?add("Center",?c);?
3)?c.add();?
4)?c.set();?
5)?set(c);?
Q128?Assuming?there?is?a?class?X?which?implements?the?ActionListener?interface.?
Which?method?should?be?used?to?register?this?with?a?Button??
1)?addListener(new?X());?
2)?addActionListener(new?X());?
3)?addButtonListener(new?X());?
4)?addActionAdapter(new?X());?
5)?(new?X()).addActionListener();?
Q129?What?is?the?result?of?compiling?and?executing?the?following?fragment?of?code:?
boolean?flag?=?false;?
if?(flag?=?true)?
{?
System.out.println("true");?
}?
else?
{?
System.out.println("false");?
}?
1)?The?code?fails?to?compile?at?the?"if"?statement.?
2)?An?exception?is?thrown?at?run-time?at?the?"if"?statement.?
3)?The?text?"true"?is?displayed.?
4)?The?text?"false"?is?displayed.?
5)?Nothing?is?displayed.?
Q130?Which?of?the?following?is?not?a?subclass?of?java.awt.Component??
1)?Frame?
2)?Container?
3)?CheckboxGroup?
4)?Canvas?
5)?Applet?
Q131?What?is?the?result?when?the?following?piece?of?code?is?compiled?and?executed.?
1.?public?class?Calc?{?
2.?public?static?void?main?(String?args?[])?{?
3.?int?total?=?0;?
4.?
5?.?for?(int?i?=?0,?j?=?10;?total?<?30;?++i,?--j)?{?
6.?System.out.println("?i?=?"?+?i?+?"?:?j?=?"?+?j);?
7.?
8.?total?+=?(i?+?j);?
9.?
10.?}?
11.?
12.?System.out.println("Total?"?+?total);?
13.?}?
14.?}?
1)?The?code?fails?to?compile?at?line?5,?because?the?variable?"j"?is?not?declared?correctly.?
2)?The?code?fails?to?compile?at?line?2,?because?you?can't?have?a?static?method?in?a?non-static?class.?
3)?The?code?compiles?correctly,?but?throws?an?exception?at?line?5.?
4)?The?code?compiles?correctly?but?throws?an?exception?at?line?2.?
5)?The?code?compiles?correctly?and?displays?the?following?when?executed:?
i?=?0?:?j?=?10?
i?=?1?:?j?=?9?
i?=?2?:?j?=?8?
Total?30?
Q132?Which?of?the?following?will?create?a?TextField?capable?of?displaying?10?characters,?with?the?initial?text?"hello"??
1)?TextField?t?=?new?TextField("hello",?10);?
2)?TextField?t?=?new?TextField(10,?"hello");?
3)?TextField?t?=?new?TextField();?
t.setCols(10);?
t.setText("hello");?
4)?TextField?t?=?new?TextField();?
t.setFieldSize(10);?
t.setText("hello");?
5)?None?of?the?above.?
Q133?What?is?the?effect?of?adding?the?sixth?element?to?a?Vector?created?using?the?following?code:?
new?Vector(5,?10);?
1)?An?IndexOutOfBounds?exception?is?thrown.?
2)?The?vector?grows?in?size?to?a?capacity?of?10?elements.?
3)?The?vector?grows?in?size?to?a?capacity?of?15?elements.?
4)?Nothing.?The?Vector?will?have?grown?when?the?fifth?element?was?added,?because?Vector?elements?are?zero-based.?
5)?Nothing.?This?is?not?a?valid?way?to?create?a?Vector.?
Q134?When?is?the?text?"Hi?there"?displayed??
public?class?StaticTest?{?
static?{?
System.out.println("Hi?there");?
}?
public?void?print()?{?
System.out.println("Hello");?
}?
public?static?void?main(String?args?[])?{?
StaticTest?st1?=?new?StaticTest();?
st1.print();?
StaticTest?st2?=?new?StaticTest();?
st2.print();?
}?
}?
1)?Never.?
2)?Each?time?a?new?object?of?type?StaticTest?is?created.?
3)?Once?when?the?class?is?loaded?into?the?Java?virtual?machine.?
4)?Only?when?the?main()?method?is?executed.?
Q135?Which?of?the?following?are?valid?ways?to?assign?the?value?of?5?to?a?variable?of?type?"int"?called?testValue??
1)?int?testValue?=?0x5;?
2)?int?testValue?=?(int)(2.1F?+?3.4D);?
3)?int?testValue?=?(octal)5;?
4)?int?testValue?=?(0x0A?>>?1);?
5)?int?testValue?=?(0x0A?>>>?1);?
Q136?Which?of?the?following?operations?will?cause?an?ActionEvent?to?be?generated.?
1)?Clicking?a?checkbox.?
2)?Selecting?an?option?from?a?Choice?box.?
3)?Scrolling?a?scroll?bar.?
4)?Clicking?a?button.?
5)?Hitting?ENTER?when?typing?in?a?text?field.?
Q137?True?or?False.?
All?Listener?interfaces?methods?are?declared?as?public?and?void.?
1)?True?
2)?False?
Q138?True?or?False.?
In?a?GridLayout,?the?width?and?height?of?all?cells?are?the?same.?
1)?True?
2)?False?
Q139?True?or?False.?
The?BorderLayout?manager?only?allows?a?single?component?to?be?displayed?in?each?sector.?
1)?True?
2)?False?
Q140?You?want?to?extend?the?functionality?of?the?String?class,?and?decide?that?the?best?approach?is?to?subclass?String.?Which?of?the?following?statements?are?correct.?
1)?The?approach?fails,?because?the?String?class?is?declared?as?final?and?cannot?be?subclassed.?
2)?The?approach?succeeds,?and?it?is?therefore?possible?to?override?the?standard?functionality?provided?by?String.?
3)?The?approach?fails,?because?the?String?class?is?declared?as?abstract,?and?therefore?it?cannot?be?subclassed.?
Q141?Which?of?the?following?are?valid?ways?to?determine?the?number?of?elements?in?an?array?defined?as?follows:?
int?intArray[]?=?{1,2,3};?
1)?intArray.size;?
2)?intArray.size();?
3)?intArray.length;?
4)?intArray.length();?
5)?intArray.getSize();?
Q142?You?have?a?check?box?within?a?panel,?and?the?panel?is?contained?within?an?applet.?There?are?no?other?components?within?the?applet.?
Using?"setBackground(Color.white)",?you?assign?the?background?colour?of?the?applet?to?white.?
Which?of?the?following?statements?are?true.?
1)?The?background?colour?of?the?panel?is?white.?
2)?The?foreground?colour?of?the?checkbox?is?the?same?as?the?foreground?colour?of?the?applet.?
3)?It?is?impossible?to?determine?the?background?colour?of?the?checkbox?from?the?imformation?supplied.?
4)?You?can't?put?a?panel?inside?an?applet.?
Q143?Which?of?the?following?can?be?added?to?a?menu??
1)?A?panel?
2)?A?button?
3)?A?menu?
4)?A?checkbox?
5)?A?menubar?
Q144?You?construct?an?application?by?making?the?following?call:?
Frame?app?=?new?Frame();?
app.setSize(100,100);?
Which?of?the?following?statements?are?correct.?
1)?An?empty?frame?of?size?100x100?is?displayed,?located?in?the?top?left?corner?of?the?screen.?
2)?An?empty?frame?of?size?100x100?is?displayed,?located?in?the?centre?of?the?screen.?
3)?Nothing?is?displayed.?There?is?no?setSize()?method?in?the?Frame?class.?
4)?Nothing?is?displayed.?The?frame?will?only?be?displayed?by?setting?the?forground?and?background?colours.?
5)?Nothing?is?displayed.?A?frame?is?created?by?default?with?zero?size,?and?invisible.?
Q145?Which?of?the?following?are?valid?methods?in?the?java.awt.Graphics?class??
1)?drawString()?
2)?drawOval()?
3)?fillRect()?
4)?drawPolyline()?
5)?fillPolyline()?
Q146?Which?of?the?following?are?valid?command?line?options?for?the?JAR?utility:?
1)?c?(create?a?new?or?empty?archive)?
2)?m?(indicates?that?first?argument?is?the?name?of?a?user-supplied?manifest)?
3)?M?(do?not?create?a?manifest)?
4)?z?(ZIP?the?contents?of?the?archive)?
5)?L?(list?the?archive?contents)?
Q147?Consider?the?following?code?segment?and?select?the?correct?statement(s):?
1.?class?FinalTest{?
2.?final?int?q;?
3.?final?int?w?=?0;?
4.?
5.?FinalTest(){?
6.?q?=?1;?
7.?}?
8.?
9.?FinalTest(int?x){?
10.?q?=?x;?
11.?}?
12.?}?
1)?The?code?fails?to?compile?because?a?class?cannot?have?more?than?1?constructor.?
2)?The?code?fails?to?compile?because?the?class?FinalTest?has?no?constructors.?
3)?The?code?fails?to?compile?because?the?an?attempt?is?made?to?initialise?a?final?variable?at?lines?6?and?10.?
4)?The?code?compiles?correctly?without?any?warnings?or?errors.?
5)?The?code?fails?to?compile?because?the?final?variable?q?is?not?initialised?correctly?at?line?2.?
Q148?True?or?False.?
It?is?valid?to?throw?(and?re-throw)?an?exception?inside?a?catch{}?clause.?
For?example:?
...?
catch?(Exception?e){?
throw?e;?
}?
1)?True?
2)?False?
Q149?True?or?False.?
A?scrollbar?will?appear?in?a?TextField?if?more?text?is?typed?than?can?be?displayed?within?the?TextField.?
1)?True?
2)?False?
Q150?True?or?False.?
It?is?valid?to?declare?an?inherited?method?as?abstract.?
1)?True?
2)?False?
Q151?Consider?the?following?code?segments?and?select?the?correct?statement:?
Segment?1:?
1.?int?a?=?3;?
2.?int?b?=?0;?
3.?int?c?=?a/b;?
Segment?2:?
4.?float?a?=?1.0F;?
5.?float?b?=?0.0F;?
6.?float?c?=?a/b;?
1)?When?executed,?both?segments?will?cause?an?exception?to?be?thrown.?
2)?When?executed,?neither?segment?will?cause?an?exception?to?be?thrown.?
3)?Only?Segment?1?will?throw?an?exception.?
4)?Only?Segment?2?will?throw?an?exception.?
Q152?Which?of?the?following?classes?override?the?equals()?method.?
1)?String?
2)?Integer?
3)?Double?
4)?Date?
5)?File?
Q153?Which?of?the?following?is?the?default?layout?manager?for?a?panel.?
1)?BorderLayout?
2)?FlowLayout?
3)?GridBagLayout?
4)?GridLayout?
5)?None?of?the?above.?
Q154?True?or?False.?
The?StringBuffer?class?inherits?from?the?String?class.?
1)?True?
2)?False?
Q155?True?or?False.?
The?class?String?has?a?concat()?method,?while?the?StringBuffer?class?has?an?append()?method.?
1)?True?
2)?False?
Q156?True?or?False.?
The?primative?wrapper?classes?Integer,?Double?and?Float?all?inherit?directly?from?the?java.lang.Wrapper?class.?
1)?True?
2)?False?
Q157?Which?of?the?following?are?valid?methods?for?the?Applet?class.?
1)?start()?
2)?stop()?
3)?init()?
4)?destroy()?
5)?kill()?
Q158?True?or?False.?
A?label?can?only?display?a?single?line?of?text.?
1)?True?
2)?False?
Q159?Which?of?the?following?are?valid?methods?for?the?Math?class.?
1)?random()?
2)?Random()?
3)?toDegrees()?
4)?square()?
5)?sqr()?
Q160?True?or?False.?
JDK?1.2?contains?an?Arrays?class?which?provides?various?methods?for?manipulating?arrays?(such?as?searching?and?sorting).?
1)?True?
2)?False?
Q161?True?or?False.?
The?Class?class?has?no?public?constructor.?
1)?True?
2)?False?
Q162?Which?of?the?following?statements?is?true?with?regard?to?persistence.?
1)?"Serializable"?is?a?keyword?within?the?Java?language.?
2)?"Serializable"?is?an?interface,?which?classes?can?implement.?
3)?"Serializable"?is?a?class,?which?other?classes?can?extend.?
4)?None?of?the?above.?
Q163?Which?of?the?following?statements?is?correct?with?regard?to?threads.?
1)?"Runnable"?is?a?keyword?within?the?Java?language,?used?to?identify?classes?which?can?exist?as?separate?threads.?
2)?"Runnable"?is?an?interface,?which?classes?can?implement?when?they?wish?to?execute?as?a?separate?thread.?
3)?"Runnable"?is?a?class,?which?classes?can?extend?when?they?wish?to?execute?as?a?separate?thread.?
4)?None?of?the?above.?
5)?java?does?not?support?threads.?
Q164?Select?the?statements?which?are?valid?from?the?list?below.?
1)?The?primative?data?type?"char"?is?16-bits?wide.?
2)?Unicode?uses?16-bits?to?represent?a?character.?
3)?Unicode?uses?32-bits?to?represent?a?character.?
4)?UTF?uses?24-bits?to?represent?a?character.?
5)?UTF?uses?as?many?bits?as?are?needed?to?represent?a?character.?
Q165?When?a?Frame?is?constructed,?it?has?no?size?and?is?not?displayed.?Which?of?the?following?methods?can?be?called?to?display?the?Frame.?
1)?setSize()?
2)?setBounds()?
3)?setDisplayable()?
4)?setVisible()?
5)?setState()?
Q166?Which?one?of?the?following?is?correct?(assume?A?and?B?are?correctly?defined).?
1)?if?(A?instanceOf?B)?
2)?if?(A?instanceof?B)?
3)?if?(A.instanceOf(B))?
4)?if?(A?instanceof(B))?
Q167?What?is?displayed?when?the?following?is?executed:?
double?d1?=?-0.5;?
System.out.println("Ceil?d1?=?"?+?Math.ceil(d1));?
System.out.println("floor?d1?=?"?+?Math.floor(d1));?
1)?Ceil?d1?=?-0.0?
floor?d1?=?-1.0?
2)?Ceil?d1?=?0.0?
floor?d1?=?-1.0?
3)?Ceil?d1?=?-0.0?
floor?d1?=?-0.0?
4)?Ceil?d1?=?0.0?
floor?d1?=?0.0?
5)?Ceil?d1?=?0?
floor?d1?=?-1?
Q168?Select?the?layour?manager?which?is?described?by?the?following:?
"It?arranges?its?constituent?components?in?horizontal?rows.?It?will?attempt?to?fit?as?many?components?as?possible?into?the?first?row,?and?remaining?components?will?spill?over?into?subsequent?rows.?Components?always?appear?left?to?right,?in?the?order?they?were?added?to?the?container."?
1)?FlowLayout?
2)?GridLayout?
3)?CardLayout?
4)?TransverseFlowLayout?
5)?GridBagLayout?
Q169?True?or?False?
The?argument?for?a?"case"?statement?must?be?a?constant?or?a?constant?expression?which?can?be?evaluated?at?compile?time.?
1)?True?
2)?False?
Q170?Select?the?valid?code?fragments?from?the?following?list:?
1)?public?transient?static?final?int?_FRAMEX?=?850;?
2)?this("a",?"b");?
[assuming?a?constructor?of?the?type?xxx(String,?String)?exists?for?this?class]?
3)?private?transient?static?final?int?_FRAMEX?=?850;?
4)?boolean?b?=?0;?
Q171?True?or?False.?
The?File?class?can?represent?either?a?file?or?a?directory?within?a?file?system.?
1)?True?
2)?False?
Q172?True?or?False.?
The?argument?for?a?while()?statement?MUST?be?a?boolean.?
1)?True?
2)?False?
Q173?True?or?False.?
The?right-hand?operand?of?the?instanceof?operator?can?be?an?interface;?eg?
a?instanceof?b?
where?b?is?an?interface.?
1)?True?
2)?False?
Q174?Consider?the?following?class:?
public?class?Test{?
public?int?secret;?
}?
Which?of?the?following?is?the?correct?way?to?make?the?variable?'secret'?read-only.?
1)?Declare?'secret'?to?be?private.?
2)?Declare?the?class?Test?to?be?private.?
3)?Declare?'secret'?to?be?private?and?write?a?method?getSecret()?which?returns?the?value?of?'secret'.?
4)?Declare?'secret'?to?be?transient.?
5)?Declare?'secret'?to?be?static.?
Q175?Which?one?of?the?following?methods?of?the?Math?class?can?be?used?to?find?the?square?root?of?a?number.?
1)?squareRoot()?
2)?sqrt()?
3)?root()?
4)?sqr()?
5)?None?of?the?above.?You?use?the?pow()?method.?
Q176?To?which?layout?manager?does?the?following?statement?refer:?
"it?preserves?the?preferred?size?(width?and?height)?of?each?component".?
1)?Flow?Layout?
2)?Border?Layout?
3)?Grid?Layout?
4)?Grid?Bag?Layout?
5)?None?of?the?above.?All?layout?managers?alter?the?dimensions?of?their?containing?components.?
Q177?Consider?the?following?code?fragment,?and?select?the?correct?statements(s):?
1.?public?class?Test?extends?MyBase?implements?MyInterface{?
2.?int?x?=?0;?
3.?
4.?public?Test(int?inVal)?throws?Exception{?
5.?if?(inVal?!=?this.x){?
6.?throw?new?Exception("Invalid?input");?
7.?}?
8.?}?
9.?
10.?public?static?void?main(String?args[]){?
11.?Test?t?=?new?Test(4);?
12.?}?
13.}?
1)?The?code?fails?to?compile?at?line?1.?It?is?not?valid?to?both?implement?an?interface?and?extend?from?a?parent?class?simultaneously.?
2)?The?code?fails?to?compile?at?line?4.?It?is?not?valid?for?constructors?to?throw?exceptions.?
3)?The?code?fails?to?compile?at?line?6,?because?this?is?not?valid?way?to?throw?an?exception.?
4)?The?code?fails?to?compile?at?line?11.?The?compiler?complains?that?there?is?an?uncaught?exception.?
5)?The?code?fails?to?compile?at?line?5,?because?this?is?not?a?valid?way?to?reference?variable?x.?
Q178?Consider?the?following?real-life?relationships,?and?select?the?code?fragment?which?most?closely?represents?it.?
An?employee?is?a?person.?An?employee?has?zero?or?more?dependants.?
?[for?the?code?fragments,?assume?that?all?relevant?packages?are?imported,?and?all?relevant?class?definitions?exist].?
1)?class?Employee?extends?Dependants{?
Person?p;?
}?
2)?class?Person?extends?Employee{?
Vector?dependants;?
}?
3)?class?Employee?extends?Person{?
Vector?dependants;?
}?
4)?abstract?class?Person?extends?Dependants{?
Employee?e;?
}?
5)?class?Dependant?implements?Employee{?
Vector?person;?
}?
Q179?Which?of?the?following?are?valid?declarations?for?a?native?method.?
1)?public?native?void?aMethod();?
2)?private?native?String?aMethod();?
3)?private?native?boolean?aMethod(int?val){};?
4)?public?native?int?aMethod(String?test);?
5)private?native?boolean?aMethod(boolean?flag,?Integer?val);?
Q180?Which?of?the?following?are?valid?ways?to?define?an?octal?literal?of?value?17?(octal).?
1)?private?final?int?theNumber?=?0x17;?
2)?private?final?int?theNumber?=?017;?
3)?public?int?theNumber?=?017;?
4)?public?int?theNumber?=?(octal)17;?
5?)public?int?THE_NUMBER?=?017;?
Q181?Consider?the?following?piece?of?code?and?select?all?statements?which?yield?a?boolean?value?of?true?as?a?result.?
Double?d1=new?Double(10.0);?
Double?d2=new?Double(10.0);?
int?x=10;?
float?f=10.0f;?
1)?d1?==?d2;?
2)?d1?==?x;?
3)?f?==?x;?
4)?d1.equals(d2);?
5)?None?of?the?above?
Q182?Given?the?following?definition:?
String?s?=?null;?
Which?code?fragment?will?cause?an?exception?of?type?NullPointerException?to?be?thrown.?
1)?if?((s?!=?null)?&?(s.length()>0))?
2)?if?((s?!=?null)?&&?(s.length()>0))?
3)?if?((s?!=?null)?|?(s.length()>0))?
4)?if?((s?!=?null)?||?(s.length()>0))?
5)?None?of?the?above.?
Q183?Which?of?the?following?are?valid?declarations?for?a?2x2?array?of?integers.?
1)?int?a[][]?=?new?int[10,10];?
2)?int?a[][]?=?new?int?[10][10];?
3)?int?a[10,10]?=?new?int?[10][10];?
4)?int?[][]a?=?new?int?[10][10];?
5)?int?[]a[]?=?new?int?[10][10];?
Q184?Which?values?of?variable?x?will?show?"Message?2".?
switch(x)?
{?
case?1?:?
System.out.println("Message?1");?
case?2?:?
case?3?:?
System.out.println("Message?2");?
default?:?
System.out.println("End");?
}?
1)?1?
2)?2?
3)?3?
4)?4?
5)?none?
Q185?What?is?the?result?of?the?following?code?:?
public?class?SuperEx?{?
String?r;?
String?s;?
public?SuperEx(String?a,String?b)?{?
r?=?a;?
s?=?b;?
}?
public?void?aMethod()?{?
System.out.println("r?:"?+?r);?
}?
}?
public?class?NewSuper?extends?SuperEx?{?
public?NewSuper(String?a,String?b)?{?
super(a,b);?
}?
public?static?void?main(String?args?[])?{?
SuperEx?a?=?new?SuperEx("Hi","Tom");?
SuperEx?b?=?new?NewSuper("Hi","Bart");?
a.aMethod();?
b.aMethod();?
}?
public?void?aMethod()?{?
System.out.println("r?:"?+?r?+?"?s:"?+?s);?
}?
}?
1)?The?following?is?displayed:?
r:Hi?
s:Hi?
2)?Compiler?error?at?the?line?"SuperEx?b?=?new?NewSuper("Hi","Bart");"?
3)?The?following?is?displayed:?
r:Hi?
r:Hi?s:Bart?
4)?The?following?is?displayed?
r:Hi?s:Tom?
r:Hi?s:Bart?
Q186?You?have?a?class?with?a?certain?variable?and?you?don't?want?that?variable?to?be?accessible?to?ANY?other?class?but?your?own.?Your?class?must?be?sub-classable.?
Which?keyword?do?you?add?to?the?variable.?
1)?private?
2)?public?
3)?transient?
4)?final?
5)?abstract?
Q187?You?get?this?description?of?a?class?:?
Employee?is?a?person.?For?every?employee,?we?keep?a?vector?with?the?working?hours,?an?integer?for?the?salary?and?a?variable?that?can?be?true?or?false?whether?or?not?the?employee?has?a?company?car.?
Indicate?which?of?the?following?would?be?used?to?define?the?class?members.?
1)?Vector?
2)?Employee?
3)?Object?
4)?boolean?
5)?int?
Q188?Which?line?of?code?can?be?inserted?in?place?of?the?comments,?to?perform?the?initialisation?described?by?the?comments:?
public?class?T?{?
int?r;?
int?s;?
T(int?x,?int?y)?{?
r?=?x;?
s?=?y;?
}?
}?
class?S?extends?T?{?
int?t;?
public?S(int?x,?int?y,?int?z){?
//?insert?here?the?code?
//?that?would?do?the?correct?initialisation?
//?r=?x?and?s=?y?
t=z;?
}?
}?
1)?T(x,?y);?
2)?this(x,?y);?
3)?super(x,?y);?
4)?super(x,?y,?z);?
5)?None?
Q189?Suppose?a?MyException?should?be?thrown?if?Condition()?is?true,?which?statements?do?you?have?to?insert???
1:?public?aMethod?{?
2:?
3:?if?(Condition)?{?
4:?
5:?}?
6:?
7:?}?
1)?throw?new?Exception()?at?line?4?
2)?throw?new?MyException()?at?line?4?
3)?throw?new?MyException()?at?line?6?
4)?throws?new?Exception()?at?line?2?
5)?throws?MyException?at?line?1?
Q190?Suppose?a?NullPointerException?is?thrown?by?test().?Which?message?is?displayed??
void?Method(){?
try?{?
test();?
System.out.println("Message1");?
}?
catch?(ArrayOutOfBoundsException?e)?{?
System.out.println("Message2");?
}?
finally?{?
System.out.println("Message3");?
}?
System.out.println("Message4");?
}?
1)?Message1?
2)?Message2?
3)?Message3?
4)?Message4?
5)?None?of?the?above.?
Q191?Choose?the?class?that?can?hold?multiple?equal?objects?in?an?ordered?way.?
1)?Map?
2)?Collection?
3)?List?
4)?Set?
5)?Vector?
Q192?Consider?the?following?variables?definitions.?
Float?f1?=?new?Float("10F");?
Float?f2?=?new?Float("10F");?
Double?d1?=?new?Double("10D");?
Which?of?the?following?yields?a?boolean?value?of?true.?
1)?f1?==?f2?
2)?f1.equals(f2)?
3)?f2.equals(d1)?
4)?f2.equals(new?Float("10"))?
Q193?What?does?the?getID()?method?of?AWTEvent?tell?us.?
1)?Tells?us?the?x?and?y?coords?of?the?mouse?at?the?event?time.?
2)?Tells?us?which?Object?the?event?originated?from.?
3)?Tells?us?which?special?keys?were?pressed?at?the?event?time.?
4)?Tells?us?the?event?type.?
5)?Tells?us?the?how?many?pixels?were?between?the?mouse?pointer?and?text?on?a?Canvas.?
Q194?What?is?the?return?type?of?an?Eventlistener???
1)?int?
2)?NULL?
3)?void?
4)?boolean?
5)?Object?
Q195?You?create?a?Long?object?using?the?following:?
Long?val?=?new?Long("11");?
Which?of?the?following?will?return?the?value?of?the?object?as?a?byte?value??
1)?byte?b?=?(byte)val;?
2)?byte?b?=?val.getByte();?
3)?byte?b?=?(byte)val.getValue();?
4)?byte?b?=?val.byteValue();?
5)?None?of?the?above.?
Q196?Consider?the?following.?
String?s1?=?"abc";?
String?s2?=?"def";?
String?s3?=?new?String(s2);?
s2?=?s1;?
What?is?the?value?of?s3?after?the?final?line?of?code?is?executed??
1)?"abc"?
2)?"def"?
3)?null?
4)?An?exception?is?thrown?when?"s2?=?s1"?is?executed.?
Q197?What?tags?are?mandatory?when?creating?HTML?to?display?an?applet?
1)?name,?width,?height?
2)?code,?name?
3)?codebase,?height,?width?
4)?code,?width,?height?
5)?None?of?the?above?
Q198?What?is?displayed?when?the?following?code?is?executed:?
String?s1?=?"?hello?world?";?
String?s2?=?s1.trim();?
System.out.println(s2);?
1)?"?hello?world"?
2)?"hello?world?"?
3)?"hello?world"?
4)?"?hello?world?"?
5)?"helloworld"?
Q199?Which?of?the?following?are?methods?within?the?String?class.?
1)?substring()?
2)?startsWith()?
3)?toString()?
4)?toUpperCase()?
5)?indexOf()?
Q200?True?or?False.?
APPLET?tags?must?appear?between?BODY?and?/BODY?tags.?
1)?True?
2)?False?
ANSWER:?
1.?1,2?
Answers?3,?4?and?5?are?incorrect?because?these?operations?requires?that?an?int?(c)?be?converted?to?a?boolean,?or?the?boolean?be?converted?to?an?int.?Both?of?these?conversions?are?illegal.?
2.?5?
A?constructor?cannot?be?abstract,?final,?native,?static?or?synchronized.?Refer?to?the?Java?Language?Specification?(section?8.6.3,?version?1.0).?
3.?4?
In?general,?all?components?are?resized?and?only?retain?their?preferred?height?in?the?NORTH?region.?However,?the?CheckBox?is?not?deformable,?so?it?retains?it's?preferred?size.?
4.?1,3,4?
5.?1?
6.?3?
When?a?File?class?is?constructed,?it?simply?creates?a?handle?to?a?File?object.?No?files?are?created?on?the?local?harddisk.?
As?the?JDK?API?documentation?points?out,?the?File?class?is?"an?abstract?representation?of?file?and?directory?pathnames".?
The?File?class?also?contains?directory?separator?attributes,?which?are?platform?specific.?Therefore,?the?directory?separator?used?is?irrelevant.?
Also,?since?the?File?class?simply?creates?a?reference?to?a?file?object,?no?exception?is?thrown?if?the?file?already?exists?on?the?disk.?
7.?1,4,5?
Answer?1?is?correct,?because?in?read?mode,?the?file?must?exist?if?any?other?operations?are?to?be?performed?on?it.?
The?RandomAccessFile?is?not?compatible?with?the?Stream?or?reader/writer?classes,?so?Answer?3?is?incorrect.?
8.?3?
Strings?are?immutable,?and?so?they?cannot?be?modified.?However,?as?the?JDK?API?documentation?will?show,?the?String?class?has?a?replace()?method,?so?answer?1?is?incorrect.?
If?line?2?read?as?"s?=?s.replace('d',?'q')"?then?a?new?object?would?be?created?and?assigned?to?s.?The?value?of?this?new?String?object?would?be?"abcqefgh".?However,?as?line?2?is?presented,?no?new?object?is?created,?and?so?'s'?remains?unchanged.?
9.?1,5?
10.?2?
I?came?across?the?statement?during?my?study?for?the?exam,?and?simply?noted?it?as?fact.?I?never?really?looked?too?deeply?into?it?-?so?please?don't?email?me?for?an?explanation?:-)?
11.?1,4,5?
Therefore,?Answer?1?is?correct,?because?class?B?attempts?to?override?method()?to?be?less?public?(ie,?protected?to?"friendly").?
Answer?2?is?incorrect,?because?a?protected?variable?or?method?is?always?available?to?child?classes?(this?is?the?purpose?of?the?protected?keyword).?
Answer?3?is?incorrect,?because?all?the?information?needed?to?verify?this?code?is?available?at?compile?time.?
Answers?4?and?5?are?correct?because?adding?either?"public"?or?"protected"?to?line?7?actually?moves?it?higher?up?the?access?hierarchy?(ie,?more?public?than?friendly).?
12.?1?
13.?2?
14.?1?
15.?3?
16.?2?
The?rule?for?accessing?methods?and?variables?in?a?class?hierarchy?is?as?follows:?
-the?object?reference?is?used?when?accessing?variables?(so?the?value?of?b.x?is?therefore?2).?
-the?underlying?object?is?used?when?accessing?methods?(so?the?method?called?is?actually?the?method?defined?in?Subclass,?and?in?Subclass,?x?=3).?
17.?1?
18.?2?
19.?2?
20.?1,2,3?
1.?3?
22.?1?
23.?1?
24.?1?
25.?4?
26.?1,4,5?
Answer?1?is?correct,?because?x?is?declared?as?private?to?class?A?and?is?therefore?not?available?to?any?other?class?(even?subclasses).?
Answer?3?is?totally?meaningless,?but?sounds?vaguely?plausible!?
Answer?4?is?correct,?because?the?only?problem?with?the?code?is?the?attempt?to?reference?the?variable?x.?
Answer?5?is?correct?(see?answer?4).?
27.?3?
28.?2,3,4,5?
29.?1?
Answer?2?is?incorrect,?since?the?{}?defines?an?empty?method?(but?still?a?method)?so?it?is?not?abstract.?
Abstract?methods?cannot?be?static,?so?answer?3?is?incorrect.?
Abstract?and?final?are?almost?opposite?in?meaning?and?therefore?do?not?form?a?valid?keyword?combination?(final?means?a?method?can't?be?overridden,?abstract?means?a?method?must?be?overridden),?so?answer?4?is?incorrect.?
30.?2?
31.?4?
Interfaces?cannot?have?constructors,?only?classes?have?constructors.?
Answer?2?is?a?valid?statement?when?dealing?with?classes,?but?not?in?the?context?of?the?code?in?the?question.?
Answer?5?is?totally?untrue,?but?potentially?confusing?:-)?
32.?1?
33.?1,2,4?
34.?1?
Answer?2?is?incorrect,?because?booleans?can't?have?integer?values?(in?this?case,?"1").?
Answer?3?is?an?meaningless?statement.?
Answer?5?is?incorrect,?attempting?to?confuse?C/C++?and?Java?ways?of?defining?true?and?false?boolean?values.?
35.?2,4?
36.?2?
37.?2?
38.?1,2?
39.?3?
40.?1?
41.?2?
42.?3?
43.?1,3?
44.?1,2,3?
45.?2?
46.?1,2,4,5?
47.?1?
48.?2?
49.?1.4?
50.?3,4?
Answer?1?is?incorrect,?because?a?class?can?have?final?methods?and?variables?without?the?need?for?the?entire?class?to?be?final.?
Answer?2?is?incorrect,?because?the?type?of?error?in?this?code?is?detectable?at?compile?time.?
Answer?5?is?invalid.?Final?can?be?applied?to?primitives.?
51.?4?
52.?1?
53.?1,2,3,4,5?
54.?2?
55.?2.3?
56.?3?
57.?1,3,4?
58.?3,5?
59.?1,3,4,5?
60.?5?
61.?3?
62.?4?
63.?1,4?
64.?4?
65.?2,3?
66.?1,3,4,5?
67.?5?
68.?2?
69.?4?
70.?5?
71.?4?
72.?2?
73.?3?
74.?2?
75.?1?
76.?1?
77.?4?
78.?3?
79.?2?
80.?3?
81.?3?
82.?3?
83.?1,2,5?
84.?5?
85.?4?
86.?2,3?
There?are?several?things?wrong?with?this?code:?
-?class?A?must?be?declared?as?abstract,?since?method()?is?declared?as?abstract?
-?if?class?A?is?declared?as?abstract,?then?the?code?will?compile?correctly?
-?if?the?abstract?declaration?of?method()?in?class?A?is?removed,?the?code?will?compile?(however,?the?entire?line?2?must?now?read?as?follows:?
int?method(){}?
In?other?words,?a?method?body?must?now?be?supplied?since?the?method?is?no?longer?abstract.?
87.?3?
88.?2,5?
89.?3?
90.?2?
91.?1?
92.?3,4,5?
93.?2,3,5?
94.?1,5?
95.?2,3?
96.?3.?
97.?1,2?
98.?2?
The?instanceof?operator?can?be?used?as?follows:?
-?on?classes?to?see?if?a?particular?class?is?derived?from?another?(ie,?is?an?instance?of)?
-?on?interfaces?to?see?if?a?class?implements?a?particular?interface?
99.?1,3,4?
100.?1,2,3,4,5?
101.?1,2,3,4,5?
102.?2,3,4?
103.?2?
104.?1,2,5?
105.?4?
106.?3,4,5?
107.?4,5?
108.?3?
109.?1,3,5?
110.?3?
111.?1?
112.?4?
113.?1?
114.?4?
115.?2?
1?will?not?compile,?because?123?defaults?to?type?int,?and?there?is?no?constructor?of?the?Byte?class?which?takes?type?int?as?a?parameter.?
2?compiles?correctly,?because?a?parseable?string?is?a?valid?parameter?for?the?Byte?constructor.?
3?fails?to?compile,?because?there?is?no?no-args?constructor?for?the?Byte?class.?
4?fails?to?compile.?While?the?cast?to?an?int?is?valid,?the?same?reasons?as?Answer?1?apply.?
5?fails?to?compile,?because?the?value?0x123?is?a?hex?value,?and?equates?to?a?decimal?value?of?291.?This?is?not?within?the?valid?range?for?the?Byte?value.?
116.?2?
117.?2,4?
118.?1,5?
119.?2?
120.?2,3?
121.?1,2?
122.?1?
123.?2?
124.?2,4?
125.?3,4,5?
126.?1,2,3?
127.?1?
Thanks?to?Prasad?for?rightly?pointing?out?that?Answer?2?above?also?works?for?a?container?which?uses?the?Flow?Layout?manager?(even?though?it?doesn't?have?a?"Center"?area").?
This?can?be?explained?by?the?fact?that?a?container?such?as?a?Panel?inherits?from?java.awt.Container,?which?has?a?method?with?a?signature?as?follows:?
add(String,?Component)?
However,?while?this?is?symantically?correct?(ie,?it?will?compile?and?function?correctly),?it?can't?be?considered?as?a?valid?answer?since?Flow?layout?doesn't?have?the?concept?of?a?"Center"?area?-?at?least,?that's?my?opinion?:-)?
However,?this?raises?an?interesting?point?-?where?possible,?you?should?use?static?class?variables,?where?a?choice?is?available?-?eg,?use?BorderLayout.NORTH?instead?of?"NORTH"?when?adding?components?to?a?container.?This?will?ensure?that?any?errors?are?trapped?at?compile?time,?rather?than?at?run-time?:-)?
128.?2?
129.?3?
130.?3?
131.?5?
132.?1?
133.?3?
134.?3?
135.?1,2,4,5?
136.?4,5?
137.?1?
138.?1?
139.?1?
140.?1?
141.?3?
142.?1,2?
143.?3?
144.?5?
145.?1,2,3,4?
146.?1,2,3?
147.?4?
148.?1?
149.?2?
150.?1?
151.?3?
152.?1,2,3,4,5?
153.?2?
154.?2?
155.?1?
156.?2?
157.?1,2,3,4?
158.?1?
159.?1,3?
160.?1?
161.?1?
162.?2?
163.?2?
164.?1,2,5?
165.?1,2,4?
166.?2?
167.?1?
168.?1?
169.?1?
170.?1,2,3?
171.?1?
172.?1?
173.?1?
174.?3?
175.?2?
176.?1?
177.?4?
178.?3?
179.?1,2,4,5?
180.?2,3,5?
181.?3,4?
182.?1,3,4?
183.?2,4,5?
184.?1,2,3?
185.?3?
186.?1?
187.?1?
188.?3?
189.?2,5?
190.?3?
191.?5?
192.?2,4?
193.?4?
194.?3?
195.?4?
196.?2?
197.?4?
198.?3?
199.?1,2,3,4,5?
200.?1
SCJP?模擬考試題,?筆試常考
http://beansoft.java-cn.org/download/scjp_emulator.zip?700KB?Java?1.4?版本
?
是我很早以前買的一本英文?SCJP?輔導書里面所附帶的代碼.
下載后解壓縮得到幾個?JAR?文件?下載后?Windows?下可以雙擊運行,?點擊最大化后,?然后點擊?Mark?按鈕就可以看到正確答案和解釋了.
Linux/Windows?下都通過命令行鍵入
java?-jar?Final.jar?這樣的命令即可運行.?
現在的?Java?筆試題?的基礎部分(core?java)很多都是從類似這樣的英文題里面抽取出來的,?基本上熟悉之后筆試題會答的很漂亮.
界面截圖:?
再轉載:??閱讀完此貼你才可以大膽的高薪工作!http://bbs.tarena.com.cn/topic.cgi?forum=1&topic=10848&show=0
?大家找工作就要面試,有面試就有對付面試的辦法。以下一些題目來自我朋友痛苦的面試經歷,他給我總結了一下,我拿來和大家分享!提這些問題的公司包括IBM,?E*Trade,?Siebel,?Motorola,?SUN,?以及其它大小公司。?
???面試是沒什么道理可講的,它的題目有的不合情理、脫離實際。有在紙上寫的,有當面考你的,也有在電話里問的,給你IDE的估計很少(否則你趕快去買彩票,?說不定中)。所以如果你看完此文后,請不要抱怨說這些問題都能用IDE來解決。你必須在任何情況下準確回答這些問題,在面試中如果出現一兩題回答不準確很有可能你就被拒之門外了。? 當然這些都是Java的基本題,那些面試的人大多數不會問你Hibernate有多先進,Eclipse的三個組成部分,或command?design?pattern,他們都是老一輩了,最喜歡問的就是基礎知識。別小看了這些基礎,我朋友水平挺可以的,結果就栽在一道基礎知識的問題上,和高薪無緣。???
???希望這些知識點對大家有所幫助,愿大家從達內出來后都能找到高薪的工作!
第一,談談final,?finally,?finalize的區別。? final?用于聲明屬性,方法和類,分別表示屬性不可變,方法不可覆蓋,類不可繼承。finally是異常處理語句結構的一部分,表示總是執行。finalize是Object類的一個方法,在垃圾收集器執行的時候會調用被回收對象的此方法,可以覆蓋此方法提供垃圾收集時的其他資源回收,例如關閉文件等。
第二,Anonymous?Inner?Class?(匿名內部類)?是否可以extends(繼承)其它類,是否可以implements(實現)interface(接口)??可以繼承其他類或完成其他接口,在swing編程中常用此方式。
第三,Static?Nested?Class?和?Inner?Class的不同,說得越多越好(面試題有的很籠統)。?Static?Nested?Class是被聲明為靜態(static)的內部類,它可以不依賴于外部類實例被實例化。而通常的內部類需要在外部類實例化后才能實例化。
第四,&和&&的區別。?&是位運算符,表示按位與運算,&&是邏輯運算符,表示邏輯與(and).
第五,HashMap和Hashtable的區別。?HashMap是Hashtable的輕量級實現(非線程安全的實現),他們都完成了Map接口,主要區別在于HashMap允許空(null)鍵值(key),由于非線程安全,效率上可能高于Hashtable.
第六,Collection?和?Collections的區別。? Collection是集合類的上級接口,繼承與他的接口主要有Set?和List.Collections是針對集合類的一個幫助類,他提供一系列靜態方法實現對各種集合的搜索、排序、線程安全化等操作。
第七,什么時候用assert。?1.4新增關鍵字(語法),用于測試boolean表達式狀態,可用于調試程序。使用方法?assert?<boolean表達式>,表示如果表達式為真(true),則下面的語句執行,否則拋出AssertionError。另外的使用方式assert?<?boolean表達式>:<other表達式>,表示如果表達式為真,后面的表達式忽略,否則后面表達式的值用于AssertionError的構建參數。注意編譯時要增加-source?1.4?參數,否則報錯。]運行時要增加?-ea參數,否則assert行被忽略
第八,GC是什么??為什么要有GC?? GC是垃圾收集的意思(Gabage?Collection),內存處理是編程人員容易出現問題的地方,忘記或者錯誤的內存回收會導致程序或系統的不穩定甚至崩潰,Java提供的GC功能可以自動監測對象是否超過作用域從而達到自動回收內存的目的,Java語言沒有提供釋放已分配內存的顯示操作方法。?
第九,String?s?=?new?String("xyz");創建了幾個String?Object??兩個
第十,Math.round(11.5)等於多少??Math.round(-11.5)等於多少??Math.round(11.5)==12Math.round(-11.5)==-11round方法返回與參數最接近的長整數,參數加1/2后求其floor.
第十一,short?s1?=?1;?s1?=?s1???1;有什么錯??short?s1?=?1;?s1??=?1;有什么錯??short?s1?=?1;?s1?=?s1???1;?(s1?1運算結果是int型,需要強制轉換類型)short?s1?=?1;?s1??=?1;(可以正確編譯)
第十二,sleep()?和?wait()?有什么區別??sleep是線程類(Thread)的方法,導致此線程暫停執行指定時間,給執行機會給其他線程,但是監控狀態依然保持,到時后會自動恢復。調用sleep不會釋放對象鎖。wait是Object類的方法,對此對象調用wait方法導致本線程放棄對象鎖,進入等待此對象的等待鎖定池,只有針對此對象發出notify方法(或notifyAll)后本線程才進入對象鎖定池準備獲得對象鎖進入運行狀態。
第十三,Java有沒有goto??沒有 很十三的問題,如果哪個面試的問到這個問題,我勸你還是別進這家公司。(完)(job.sohu.com)
第十四,數組有沒有length()這個方法??String有沒有length()這個方法?數組沒有length()這個方法,有length的屬性。String有有length()這個方法。
第十五,Overload和Override的區別。Overloaded的方法是否可以改變返回值的類型?方法的重寫Overriding和重載Overloading是Java多態性的不同表現。重寫Overriding是父類與子類之間多態性的一種表現,重載Overloading是一個類中多態性的一種表現。如果在子類中定義某方法與其父類有相同的名稱和參數,我們說該方法被重寫?(Overriding)。子類的對象使用這個方法時,將調用子類中的定義,對它而言,父類中的定義如同被"屏蔽"了。如果在一個類中定義了多個同名的方法,它們或有不同的參數個數或有不同的參數類型,則稱為方法的重載(Overloading)。Overloaded的方法是可以改變返回值的類型。
第十六,Set里的元素是不能重復的,那么用什么方法來區分重復與否呢??是用==還是equals()??它們有何區別?Set里的元素是不能重復的,那么用iterator()方法來區分重復與否。equals()是判讀兩個Set是否相等。equals()和==方法決定引用值是否指向同一對象equals()在類中被覆蓋,為的是當兩個分離的對象的內容和類型相配的話,返回真值。
第十七,給我一個你最常見到的runtime?exception。ArithmeticException,?ArrayStoreException,?BufferOverflowException,?BufferUnderflowException,?CannotRedoException,?CannotUndoException,?ClassCastException,?CMMException,?ConcurrentModificationException,?DOMException,?EmptyStackException,?IllegalArgumentException,?IllegalMonitorStateException,?IllegalPathStateException,?IllegalStateException,?ImagingOpException,?IndexOutOfBoundsException,?MissingResourceException,?NegativeArraySizeException,?NoSuchElementException,?NullPointerException,?ProfileDataException,?ProviderException,?RasterformatException,?SecurityException,?SystemException,?UndeclaredThrowableException,?UnmodifiableSetException,?UnsupportedOperationException
第十八,error和exception有什么區別?error?表示恢復不是不可能但很困難的情況下的一種嚴重問題。比如說內存溢出。不可能指望程序能處理這樣的情況。exception?表示一種設計或實現問題。也就是說,它表示如果程序運行正常,從不會發生的情況。
第十九,List,?Set,?Map是否繼承自Collection接口?List,Set是Map不是
第二十,abstract?class和interface有什么區別?聲明方法的存在而不去實現它的類被叫做抽象類(abstract?class),它用于要創建一個體現某些基本行為的類,并為該類聲明方法,但不能在該類中實現該類的情況。不能創建abstract?類的實例。然而可以創建一個變量,其類型是一個抽象類,并讓它指向具體子類的一個實例。不能有抽象構造函數或抽象靜態方法。Abstract?類的子類為它們父類中的所有抽象方法提供實現,否則它們也是抽象類為。取而代之,在子類中實現該方法。知道其行為的其它類可以在類中實現這些方法。接口(interface)是抽象類的變體。在接口中,所有方法都是抽象的。多繼承性可通過實現這樣的接口而獲得。接口中的所有方法都是抽象的,沒有一個有程序體。接口只可以定義static?final成員變量。接口的實現與子類相似,除了該實現類不能從接口定義中繼承行為。當類實現特殊接口時,它定義(即將程序體給予)所有這種接口的方法。然后,它可以在實現了該接口的類的任何對象上調用接口的方法。由于有抽象類,它允許使用接口名作為引用變量的類型。通常的動態聯編將生效。引用可以轉換到接口類型或從接口類型轉換,instanceof?運算符可以用來決定某對象的類是否實現了接口。
第二十一,abstract的method是否可同時是static,是否可同時是native,是否可同時是synchronized?都不能
第二十二,接口是否可繼承接口??抽象類是否可實現(implements)接口??抽象類是否可繼承實體類(concrete?class)?接口可以繼承接口。抽象類可以實現(implements)接口,抽象類是否可繼承實體類,但前提是實體類必須有明確的構造函數。
第二十三,啟動一個線程是用run()還是start()?啟動一個線程是調用start()方法,使線程所代表的虛擬處理機處于可運行狀態,這意味著它可以由JVM調度并執行。這并不意味著線程就會立即運行。run()方法可以產生必須退出的標志來停止一個線程。
第二十四,構造器Constructor是否可被override?構造器Constructor不能被繼承,因此不能重寫Overriding,但可以被重載Overloading。
第二十五,是否可以繼承String類?String類是final類故不可以繼承。
第二十六,當一個線程進入一個對象的一個synchronized方法后,其它線程是否可進入此對象的其它方法?不能,一個對象的一個synchronized方法只能由一個線程訪問。
第二十七,try?{}里有一個return語句,那么緊跟在這個try后的finally?{}里的code會不會被執行,什么時候被執行,在return前還是后?會執行,在return前執行。
第二十八,編程題:?用最有效率的方法算出2乘以8等於幾?有C背景的程序員特別喜歡問這種問題。2?<<?3
第二十九,兩個對象值相同(x.equals(y)?==?true),但卻可有不同的hash?code,這句話對不對?不對,有相同的hash?code。
第三十,當一個對象被當作參數傳遞到一個方法后,此方法可改變這個對象的屬性,并可返回變化后的結果,那么這里到底是值傳遞還是引用傳遞??是值傳遞。Java?編程語言只由值傳遞參數。當一個對象實例作為一個參數被傳遞到方法中時,參數的值就是對該對象的引用。對象的內容可以在被調用的方法中改變,但對象的引用是永遠不會改變的。
第三十一,swtich是否能作用在byte上,是否能作用在long上,是否能作用在String上?switch(expr1)中,expr1是一個整數表達式。因此傳遞給?switch?和?case?語句的參數應該是?int、?short、?char?或者?byte。long,string?都不能作用于swtich。
第三十二,編程題:?寫一個Singleton出來。Singleton模式主要作用是保證在Java應用程序中,一個類Class只有一個實例存在。一般Singleton模式通常有幾種種形式:第一種形式:?定義一個類,它的構造函數為private的,它有一個static的private的該類變量,在類初始化時實例話,通過一個public的getInstance方法獲取對它的引用,繼而調用其中的方法。public?class?Singleton?{ private?Singleton(){} //在自己內部定義自己一個實例,是不是很奇怪? //注意這是private?只供內部調用 private?static?Singleton?instance?=?new?Singleton(); //這里提供了一個供外部訪問本class的靜態方法,可以直接訪問 public?static?Singleton?getInstance()?{ return?instance;? ?}?}?第二種形式:?public?class?Singleton?{? private?static?Singleton?instance?=?null; public?static?synchronized?Singleton?getInstance()?{ //這個方法比上面有所改進,不用每次都進行生成對象,只是第一次 ? //使用時生成實例,提高了效率! if?(instance==null) instance=new?Singleton();return?instance;? }?}?其他形式:定義一個類,它的構造函數為private的,所有方法為static的。
一般認為第一種形式要更加安全些