JAVAé¢è¯é¢é
åºç¡ç¥è¯ï¼
1.C++æJavaä¸çå¼å¸¸å¤çæºå¶çç®ååçååºç¨ã
å½JAVAç¨åºè¿åäºJAVAçè¯ä¹è§åæ¶ï¼JAVAèææºå°±ä¼å°åççé误表示为ä¸ä¸ªå¼å¸¸ãè¿åè¯ä¹è§åå
æ¬
2ç§æ
åµãä¸ç§æ¯JAVAç±»åºå
ç½®çè¯ä¹æ£æ¥ãä¾å¦æ°ç»ä¸æ è¶ç,ä¼å¼åIndexOutOfBoundsException;访é®
nullç对象æ¶ä¼å¼åNullPointerExceptionãå¦ä¸ç§æ
åµå°±æ¯JAVAå
许ç¨åºåæ©å±è¿ç§è¯ä¹æ£æ¥ï¼ç¨åºå
å¯ä»¥å建èªå·±çå¼å¸¸ï¼å¹¶èªç±éæ©å¨ä½æ¶ç¨throwå
³é®åå¼åå¼å¸¸ãææçå¼å¸¸é½æ¯java.lang.Thowable
çåç±»ã
2. Javaçæ¥å£åC++çèç±»çç¸ååä¸åå¤ã
ç±äºJavaä¸æ¯æå¤ç»§æ¿ï¼èæå¯è½æ个类æ对象è¦ä½¿ç¨åå«å¨å 个类æ对象éé¢çæ¹æ³æå±æ§ï¼ç°æçå
继æ¿æºå¶å°±ä¸è½æ»¡è¶³è¦æ±ãä¸ç»§æ¿ç¸æ¯ï¼æ¥å£ææ´é«ççµæ´»æ§ï¼å 为æ¥å£ä¸æ²¡æä»»ä½å®ç°ä»£ç ãå½ä¸ä¸ªç±»
å®ç°äºæ¥å£ä»¥åï¼è¯¥ç±»è¦å®ç°æ¥å£éé¢ææçæ¹æ³åå±æ§ï¼å¹¶ä¸æ¥å£éé¢çå±æ§å¨é»è®¤ç¶æä¸é¢é½æ¯
public static,æææ¹æ³é»è®¤æ
åµä¸æ¯public.ä¸ä¸ªç±»å¯ä»¥å®ç°å¤ä¸ªæ¥å£ã
3. åå¾åæ¶çä¼ç¹ååçã并èè2ç§åæ¶æºå¶ã
Javaè¯è¨ä¸ä¸ä¸ªæ¾èçç¹ç¹å°±æ¯å¼å
¥äºåå¾åæ¶æºå¶ï¼ä½¿c++ç¨åºåæ头ç¼çå
å管ççé®é¢è¿åè解ï¼
å®ä½¿å¾Javaç¨åºåå¨ç¼åç¨åºçæ¶åä¸åéè¦èèå
å管çãç±äºæ个åå¾åæ¶æºå¶ï¼Javaä¸ç对象ä¸å
æâä½ç¨åâçæ¦å¿µï¼åªæ对象çå¼ç¨ææâä½ç¨åâãåå¾åæ¶å¯ä»¥ææçé²æ¢å
åæ³é²ï¼ææç使ç¨
å¯ä»¥ä½¿ç¨çå
åãåå¾åæ¶å¨é常æ¯ä½ä¸ºä¸ä¸ªåç¬çä½çº§å«ç线ç¨è¿è¡ï¼ä¸å¯é¢ç¥çæ
åµä¸å¯¹å
åå ä¸å·²
ç»æ»äº¡çæè
é¿æ¶é´æ²¡æ使ç¨ç对象è¿è¡æ¸
æ¥ååæ¶ï¼ç¨åºåä¸è½å®æ¶çè°ç¨åå¾åæ¶å¨å¯¹æ个对象ææ
æ对象è¿è¡åå¾åæ¶ãåæ¶æºå¶æå代å¤å¶åå¾åæ¶åæ è®°åå¾åæ¶ï¼å¢éåå¾åæ¶ã
4. 请说åºä½ æç¥éç线ç¨åæ¥çæ¹æ³ã
wait():使ä¸ä¸ªçº¿ç¨å¤äºçå¾
ç¶æï¼å¹¶ä¸éæ¾æææç对象çlockã
sleep():使ä¸ä¸ªæ£å¨è¿è¡ç线ç¨å¤äºç¡ç ç¶æï¼æ¯ä¸ä¸ªéææ¹æ³ï¼è°ç¨æ¤æ¹æ³è¦ææ
InterruptedExceptionå¼å¸¸ã
notify():å¤éä¸ä¸ªå¤äºçå¾
ç¶æç线ç¨ï¼æ³¨æçæ¯å¨è°ç¨æ¤æ¹æ³çæ¶åï¼å¹¶ä¸è½ç¡®åçå¤éæä¸ä¸ªçå¾
ç¶æç线ç¨ï¼èæ¯ç±JVMç¡®å®å¤éåªä¸ªçº¿ç¨ï¼èä¸ä¸æ¯æä¼å
级ã
Allnotity():å¤éææå¤å
¥çå¾
ç¶æç线ç¨ï¼æ³¨æ并ä¸æ¯ç»ææå¤é线ç¨ä¸ä¸ªå¯¹è±¡çéï¼èæ¯è®©å®ä»¬ç«äº
ã
5. 请讲ä¸è®²ææå½æ°åèå½æ°çç¨æ³åä½ç¨ã
6. Errorä¸Exceptionæä»ä¹åºå«ï¼
Error表示系ç»çº§çé误åç¨åºä¸å¿
å¤ççå¼å¸¸ï¼
Exception表示éè¦æææè
éè¦ç¨åºè¿è¡å¤ççå¼å¸¸ã
7. å¨javaä¸ä¸ä¸ªç±»è¢«å£°æ为finalç±»åï¼è¡¨ç¤ºäºä»ä¹ææï¼
表示该类ä¸è½è¢«ç»§æ¿ï¼æ¯é¡¶çº§ç±»ã
8. æè¿°ä¸ä¸ä½ æ常ç¨çç¼ç¨é£æ ¼ã
9. heapåstackæä»ä¹åºå«ã
æ æ¯ä¸ç§çº¿å½¢éåï¼å
¶æ·»å åå é¤å
ç´ çæä½åºå¨åä¸æ®µå®æãæ æç
§åè¿å
åºçæ¹å¼è¿è¡å¤çã
å æ¯æ çä¸ä¸ªç»æå
ç´
10. å¦æç³»ç»è¦ä½¿ç¨è¶
大æ´æ°ï¼è¶
è¿longé¿åº¦èå´ï¼ï¼è¯·ä½ 设计ä¸ä¸ªæ°æ®ç»ææ¥åå¨è¿ç§è¶
大åæ°å以å
设计ä¸ç§ç®æ³æ¥å®ç°è¶
大æ´æ°å æ³è¿ç®ï¼ã
public class BigInt()
{
int[] ArrOne = new ArrOne[1000];
String intString="";
public int[] Arr(String s)
{
intString = s;
for(int i=0;i
{
11. å¦æè¦è®¾è®¡ä¸ä¸ªå¾å½¢ç³»ç»ï¼è¯·ä½ 设计åºæ¬çå¾å½¢å
件(Point,Line,Rectangle,Triangle)çç®åå®ç°
12ï¼è°è°final, finally, finalizeçåºå«ã
final?修饰符ï¼å
³é®åï¼å¦æä¸ä¸ªç±»è¢«å£°æ为finalï¼æå³çå®ä¸è½åæ´¾çåºæ°çåç±»ï¼ä¸è½ä½ä¸ºç¶
类被继æ¿ãå æ¤ä¸ä¸ªç±»ä¸è½æ¢è¢«å£°æ为 abstractçï¼å被声æ为finalçãå°åéææ¹æ³å£°æ为finalï¼
å¯ä»¥ä¿è¯å®ä»¬å¨ä½¿ç¨ä¸ä¸è¢«æ¹åã被声æ为finalçåéå¿
é¡»å¨å£°ææ¶ç»å®åå¼ï¼èå¨ä»¥åçå¼ç¨ä¸åªè½
读åï¼ä¸å¯ä¿®æ¹ã被声æ为finalçæ¹æ³ä¹åæ ·åªè½ä½¿ç¨ï¼ä¸è½éè½½ã
finally?åå¼å¸¸å¤çæ¶æä¾ finally åæ¥æ§è¡ä»»ä½æ¸
é¤æä½ãå¦ææåºä¸ä¸ªå¼å¸¸ï¼é£ä¹ç¸å¹é
ç
catch åå¥å°±ä¼æ§è¡ï¼ç¶åæ§å¶å°±ä¼è¿å
¥ finally åï¼å¦ææçè¯ï¼ã
finalize?æ¹æ³åãJava ææ¯å
è®¸ä½¿ç¨ finalize() æ¹æ³å¨åå¾æ¶éå¨å°å¯¹è±¡ä»å
åä¸æ¸
é¤åºå»ä¹å
åå¿
è¦çæ¸
çå·¥ä½ãè¿ä¸ªæ¹æ³æ¯ç±åå¾æ¶éå¨å¨ç¡®å®è¿ä¸ªå¯¹è±¡æ²¡æ被å¼ç¨æ¶å¯¹è¿ä¸ªå¯¹è±¡è°ç¨çãå®æ¯å¨
Object ç±»ä¸å®ä¹çï¼å æ¤ææçç±»é½ç»§æ¿äºå®ãåç±»è¦ç finalize() æ¹æ³ä»¥æ´çç³»ç»èµæºæè
æ§è¡å
¶
ä»æ¸
çå·¥ä½ãfinalize() æ¹æ³æ¯å¨åå¾æ¶éå¨å é¤å¯¹è±¡ä¹å对è¿ä¸ªå¯¹è±¡è°ç¨çã
13ï¼Anonymous Inner Class (å¿åå
é¨ç±») æ¯å¦å¯ä»¥extends(继æ¿)å
¶å®ç±»ï¼æ¯å¦å¯ä»¥implements(å®
ç°)interface(æ¥å£)?
å¿åçå
é¨ç±»æ¯æ²¡æååçå
é¨ç±»ãä¸è½extends(继æ¿) å
¶å®ç±»ï¼ä½ä¸ä¸ªå
é¨ç±»å¯ä»¥ä½ä¸ºä¸ä¸ªæ¥å£ï¼
ç±å¦ä¸ä¸ªå
é¨ç±»å®ç°ã
14ï¼Static Nested Class å Inner Classçä¸åï¼è¯´å¾è¶å¤è¶å¥½(é¢è¯é¢æçå¾ç¬¼ç»)ã
Nested Class ï¼ä¸è¬æ¯C++ç说æ³ï¼ï¼Inner Class (ä¸è¬æ¯JAVAç说æ³)ãJavaå
é¨ç±»ä¸C++åµå¥ç±»
æ大çä¸åå°±å¨äºæ¯å¦ææåå¤é¨çå¼ç¨ä¸ãå
·ä½å¯è§http:
//
www.frontfree.net/articles/services/view.asp?id=704&page=1 æ³¨ï¼ éæå
é¨ç±»ï¼Inner Classï¼æå³ç1å建ä¸ä¸ªstaticå
é¨ç±»ç对象ï¼ä¸éè¦ä¸ä¸ªå¤é¨ç±»å¯¹è±¡ï¼2
ä¸è½ä»ä¸ä¸ªstaticå
é¨ç±»çä¸ä¸ªå¯¹è±¡è®¿é®ä¸ä¸ªå¤é¨ç±»å¯¹è±¡
第åï¼&å&&çåºå«ã
&æ¯ä½è¿ç®ç¬¦ã&&æ¯å¸å°é»è¾è¿ç®ç¬¦ã
15ï¼HashMapåHashtableçåºå«ã
é½å±äºMapæ¥å£çç±»ï¼å®ç°äºå°æä¸é®æ å°å°ç¹å®çå¼ä¸ã
HashMap 类没æåç±»æè
æåºãå®å
许ä¸ä¸ª null é®åå¤ä¸ª null å¼ã
Hashtable ç±»ä¼¼äº HashMapï¼ä½æ¯ä¸å
许 null é®å null å¼ãå®ä¹æ¯ HashMap æ
¢ï¼å 为å®æ¯åæ¥
çã
16ï¼Collection å Collectionsçåºå«ã
Collectionsæ¯ä¸ªjava.utilä¸çç±»ï¼å®å
å«æåç§æå
³éåæä½çéææ¹æ³ã
Collectionæ¯ä¸ªjava.utilä¸çæ¥å£ï¼å®æ¯åç§éåç»æçç¶æ¥å£ã
17ï¼ä»ä¹æ¶åç¨assertã
æè¨æ¯ä¸ä¸ªå
å«å¸å°è¡¨è¾¾å¼çè¯å¥ï¼å¨æ§è¡è¿ä¸ªè¯å¥æ¶åå®è¯¥è¡¨è¾¾å¼ä¸º trueãå¦æ表达å¼è®¡ç®ä¸º
falseï¼é£ä¹ç³»ç»ä¼æ¥åä¸ä¸ª Assertionerrorãå®ç¨äºè°è¯ç®çï¼
assert(a > 0); // throws an Assertionerror if a <= 0
æè¨å¯ä»¥æ两ç§å½¢å¼ï¼
assert Expression1 ;
assert Expression1 : Expression2 ;
Expression1 åºè¯¥æ»æ¯äº§çä¸ä¸ªå¸å°å¼ã
Expression2 å¯ä»¥æ¯å¾åºä¸ä¸ªå¼çä»»æ表达å¼ãè¿ä¸ªå¼ç¨äºçææ¾ç¤ºæ´å¤è°è¯ä¿¡æ¯ç String æ¶æ¯ã
æè¨å¨é»è®¤æ
åµä¸æ¯ç¦ç¨çãè¦å¨ç¼è¯æ¶å¯ç¨æè¨ï¼éè¦ä½¿ç¨ source 1.4 æ è®°ï¼
javac -source 1.4 Test.java
è¦å¨è¿è¡æ¶å¯ç¨æè¨ï¼å¯ä½¿ç¨ -enableassertions æè
-ea æ è®°ã
è¦å¨è¿è¡æ¶éæ©ç¦ç¨æè¨ï¼å¯ä½¿ç¨ -da æè
-disableassertions æ è®°ã
è¦ç³»ç»ç±»ä¸å¯ç¨æè¨ï¼å¯ä½¿ç¨ -esa æè
-dsa æ è®°ãè¿å¯ä»¥å¨å
çåºç¡ä¸å¯ç¨æè
ç¦ç¨æè¨ã
å¯ä»¥å¨é¢è®¡æ£å¸¸æ
åµä¸ä¸ä¼å°è¾¾çä»»ä½ä½ç½®ä¸æ¾ç½®æè¨ãæè¨å¯ä»¥ç¨äºéªè¯ä¼ éç»ç§ææ¹æ³çåæ°ã
ä¸è¿ï¼æè¨ä¸åºè¯¥ç¨äºéªè¯ä¼ éç»å
¬ææ¹æ³çåæ°ï¼å 为ä¸ç®¡æ¯å¦å¯ç¨äºæè¨ï¼å
¬ææ¹æ³é½å¿
é¡»æ£æ¥å
¶å
æ°ãä¸è¿ï¼æ¢å¯ä»¥å¨å
¬ææ¹æ³ä¸ï¼ä¹å¯ä»¥å¨éå
¬ææ¹æ³ä¸å©ç¨æè¨æµè¯åç½®æ¡ä»¶ãå¦å¤ï¼æè¨ä¸åºè¯¥ä»¥ä»»
ä½æ¹å¼æ¹åç¨åºçç¶æã
18ï¼GCæ¯ä»ä¹? 为ä»ä¹è¦æGC? (åºç¡)ã
GCæ¯åå¾æ¶éå¨ãJava ç¨åºåä¸ç¨æ
å¿å
å管çï¼å 为åå¾æ¶éå¨ä¼èªå¨è¿è¡ç®¡çãè¦è¯·æ±åå¾æ¶
éï¼å¯ä»¥è°ç¨ä¸é¢çæ¹æ³ä¹ä¸ï¼
System.gc()
Runtime.getRuntime().gc()
19ï¼String s = new String("xyz");å建äºå 个String Object?
两个对象ï¼ä¸ä¸ªæ¯âxyxâ,ä¸ä¸ªæ¯æåâxyxâçå¼ç¨å¯¹è±¡sã
20ï¼Math.round(11.5)çæ¼å¤å°? Math.round(-11.5)çæ¼å¤å°?
Math.round(11.5)è¿åï¼longï¼12ï¼Math.round(-11.5)è¿åï¼longï¼-11;
21ï¼short s1 = 1; s1 = s1 + 1;æä»ä¹é? short s1 = 1; s1 += 1;æä»ä¹é?
short s1 = 1; s1 = s1 + 1;æéï¼s1æ¯shortåï¼s1+1æ¯intå,ä¸è½æ¾å¼è½¬å为shortåãå¯ä¿®æ¹ä¸º
s1 =(short)(s1 + 1) ãshort s1 = 1; s1 += 1æ£ç¡®ã
22ï¼sleep() å wait() æä»ä¹åºå«? æ线ç¨çæç±
sleep()æ¹æ³æ¯ä½¿çº¿ç¨åæ¢ä¸æ®µæ¶é´çæ¹æ³ãå¨sleep æ¶é´é´éæ满åï¼çº¿ç¨ä¸ä¸å®ç«å³æ¢å¤æ§è¡ã
è¿æ¯å 为å¨é£ä¸ªæ¶å»ï¼å
¶å®çº¿ç¨å¯è½æ£å¨è¿è¡èä¸æ²¡æ被è°åº¦ä¸ºæ¾å¼æ§è¡ï¼é¤é(a)âéæ¥âç线ç¨å
·æ
æ´é«çä¼å
级 (b)æ£å¨è¿è¡ç线ç¨å 为å
¶å®åå èé»å¡ã
wait()æ¯çº¿ç¨äº¤äºæ¶ï¼å¦æ线ç¨å¯¹ä¸ä¸ªåæ¥å¯¹è±¡x ååºä¸ä¸ªwait()è°ç¨ï¼è¯¥çº¿ç¨ä¼æåæ§è¡ï¼è¢«è°å¯¹
象è¿å
¥çå¾
ç¶æï¼ç´å°è¢«å¤éæçå¾
æ¶é´å°ã
23ï¼Javaæ没ægoto?
Goto?javaä¸çä¿çåï¼ç°å¨æ²¡æå¨javaä¸ä½¿ç¨ã
24ï¼æ°ç»æ没ælength()è¿ä¸ªæ¹æ³? Stringæ没ælength()è¿ä¸ªæ¹æ³ï¼
æ°ç»æ²¡ælength()è¿ä¸ªæ¹æ³ï¼ælengthçå±æ§ã
Stringæælength()è¿ä¸ªæ¹æ³ã
25ï¼OverloadåOverrideçåºå«ãOverloadedçæ¹æ³æ¯å¦å¯ä»¥æ¹åè¿åå¼çç±»å?
æ¹æ³çéåOverridingåéè½½Overloadingæ¯Javaå¤ææ§çä¸å表ç°ãéåOverridingæ¯ç¶ç±»ä¸åç±»
ä¹é´å¤ææ§çä¸ç§è¡¨ç°ï¼éè½½Overloadingæ¯ä¸ä¸ªç±»ä¸å¤ææ§çä¸ç§è¡¨ç°ãå¦æå¨åç±»ä¸å®ä¹ææ¹æ³ä¸å
¶
ç¶ç±»æç¸åçå称ååæ°ï¼æ们说该æ¹æ³è¢«éå (Overriding)ãåç±»ç对象使ç¨è¿ä¸ªæ¹æ³æ¶ï¼å°è°ç¨å
ç±»ä¸çå®ä¹ï¼å¯¹å®èè¨ï¼ç¶ç±»ä¸çå®ä¹å¦å被âå±è½âäºãå¦æå¨ä¸ä¸ªç±»ä¸å®ä¹äºå¤ä¸ªååçæ¹æ³ï¼å®ä»¬
ææä¸åçåæ°ä¸ªæ°ææä¸åçåæ°ç±»åï¼å称为æ¹æ³çéè½½(Overloading)ãOverloadedçæ¹æ³æ¯å¯ä»¥
æ¹åè¿åå¼çç±»åã
26ï¼Setéçå
ç´ æ¯ä¸è½éå¤çï¼é£ä¹ç¨ä»ä¹æ¹æ³æ¥åºåéå¤ä¸å¦å¢? æ¯ç¨==è¿æ¯equals()? å®ä»¬æä½åº
å«?
Setéçå
ç´ æ¯ä¸è½éå¤çï¼é£ä¹ç¨iterator()æ¹æ³æ¥åºåéå¤ä¸å¦ãequals()æ¯å¤è¯»ä¸¤ä¸ªSetæ¯å¦ç¸
çã
equals()å==æ¹æ³å³å®å¼ç¨å¼æ¯å¦æååä¸å¯¹è±¡equals()å¨ç±»ä¸è¢«è¦çï¼ä¸ºçæ¯å½ä¸¤ä¸ªå离ç对象ç
å
容åç±»åç¸é
çè¯ï¼è¿åçå¼ã
27ï¼ç»æä¸ä¸ªä½ æ常è§å°ç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
28ï¼erroråexceptionæä»ä¹åºå«?
error 表示æ¢å¤ä¸æ¯ä¸å¯è½ä½å¾å°é¾çæ
åµä¸çä¸ç§ä¸¥éé®é¢ãæ¯å¦è¯´å
å溢åºãä¸å¯è½ææç¨åºè½
å¤çè¿æ ·çæ
åµã
exception 表示ä¸ç§è®¾è®¡æå®ç°é®é¢ãä¹å°±æ¯è¯´ï¼å®è¡¨ç¤ºå¦æç¨åºè¿è¡æ£å¸¸ï¼ä»ä¸ä¼åççæ
åµã
29ï¼List, Set, Mapæ¯å¦ç»§æ¿èªCollectionæ¥å£?
Listï¼Setæ¯
Mapä¸æ¯
30ï¼abstract classåinterfaceæä»ä¹åºå«?
声ææ¹æ³çåå¨èä¸å»å®ç°å®ç类被å«åæ½è±¡ç±»ï¼abstract classï¼ï¼å®ç¨äºè¦å建ä¸ä¸ªä½ç°æäºåº
æ¬è¡ä¸ºçç±»ï¼å¹¶ä¸ºè¯¥ç±»å£°ææ¹æ³ï¼ä½ä¸è½å¨è¯¥ç±»ä¸å®ç°è¯¥ç±»çæ
åµãä¸è½å建abstract ç±»çå®ä¾ãç¶è
å¯ä»¥å建ä¸ä¸ªåéï¼å
¶ç±»åæ¯ä¸ä¸ªæ½è±¡ç±»ï¼å¹¶è®©å®æåå
·ä½åç±»çä¸ä¸ªå®ä¾ãä¸è½ææ½è±¡æé å½æ°ææ½è±¡
éææ¹æ³ãAbstract ç±»çå类为å®ä»¬ç¶ç±»ä¸çæææ½è±¡æ¹æ³æä¾å®ç°ï¼å¦åå®ä»¬ä¹æ¯æ½è±¡ç±»ä¸ºãåè代
ä¹ï¼å¨åç±»ä¸å®ç°è¯¥æ¹æ³ãç¥éå
¶è¡ä¸ºçå
¶å®ç±»å¯ä»¥å¨ç±»ä¸å®ç°è¿äºæ¹æ³ã
æ¥å£ï¼interfaceï¼æ¯æ½è±¡ç±»çåä½ãå¨æ¥å£ä¸ï¼æææ¹æ³é½æ¯æ½è±¡çãå¤ç»§æ¿æ§å¯éè¿å®ç°è¿æ ·ç
æ¥å£èè·å¾ãæ¥å£ä¸çæææ¹æ³é½æ¯æ½è±¡çï¼æ²¡æä¸ä¸ªæç¨åºä½ãæ¥å£åªå¯ä»¥å®ä¹static finalæååé
ãæ¥å£çå®ç°ä¸åç±»ç¸ä¼¼ï¼é¤äºè¯¥å®ç°ç±»ä¸è½ä»æ¥å£å®ä¹ä¸ç»§æ¿è¡ä¸ºãå½ç±»å®ç°ç¹æ®æ¥å£æ¶ï¼å®å®ä¹ï¼å³
å°ç¨åºä½ç»äºï¼ææè¿ç§æ¥å£çæ¹æ³ãç¶åï¼å®å¯ä»¥å¨å®ç°äºè¯¥æ¥å£çç±»çä»»ä½å¯¹è±¡ä¸è°ç¨æ¥å£çæ¹æ³ã
ç±äºææ½è±¡ç±»ï¼å®å
许使ç¨æ¥å£åä½ä¸ºå¼ç¨åéçç±»åãé常çå¨æèç¼å°çæãå¼ç¨å¯ä»¥è½¬æ¢å°æ¥å£ç±»
åæä»æ¥å£ç±»å转æ¢ï¼instanceof è¿ç®ç¬¦å¯ä»¥ç¨æ¥å³å®æ对象çç±»æ¯å¦å®ç°äºæ¥å£ã
31ï¼abstractçmethodæ¯å¦å¯åæ¶æ¯static,æ¯å¦å¯åæ¶æ¯nativeï¼æ¯å¦å¯åæ¶æ¯synchronized?
é½ä¸è½
32ï¼æ¥å£æ¯å¦å¯ç»§æ¿æ¥å£? æ½è±¡ç±»æ¯å¦å¯å®ç°(implements)æ¥å£? æ½è±¡ç±»æ¯å¦å¯ç»§æ¿å®ä½ç±»(concrete
class)?
æ¥å£å¯ä»¥ç»§æ¿æ¥å£ãæ½è±¡ç±»å¯ä»¥å®ç°(implements)æ¥å£ï¼æ½è±¡ç±»æ¯å¦å¯ç»§æ¿å®ä½ç±»ï¼ä½åææ¯å®ä½ç±»
å¿
é¡»ææç¡®çæé å½æ°ã
33ï¼å¯å¨ä¸ä¸ªçº¿ç¨æ¯ç¨run()è¿æ¯start()?
å¯å¨ä¸ä¸ªçº¿ç¨æ¯è°ç¨start()æ¹æ³ï¼ä½¿çº¿ç¨æ代表çèæå¤çæºå¤äºå¯è¿è¡ç¶æï¼è¿æå³çå®å¯ä»¥ç±
JVMè°åº¦å¹¶æ§è¡ãè¿å¹¶ä¸æå³ç线ç¨å°±ä¼ç«å³è¿è¡ãrun()æ¹æ³å¯ä»¥äº§çå¿
é¡»éåºçæ å¿æ¥åæ¢ä¸ä¸ªçº¿ç¨ã
34ï¼æé å¨Constructoræ¯å¦å¯è¢«override?
æé å¨Constructorä¸è½è¢«ç»§æ¿ï¼å æ¤ä¸è½éåOverridingï¼ä½å¯ä»¥è¢«éè½½Overloadingã
35ï¼æ¯å¦å¯ä»¥ç»§æ¿Stringç±»?
Stringç±»æ¯finalç±»æ
ä¸å¯ä»¥ç»§æ¿ã
36ï¼å½ä¸ä¸ªçº¿ç¨è¿å
¥ä¸ä¸ªå¯¹è±¡çä¸ä¸ªsynchronizedæ¹æ³åï¼å
¶å®çº¿ç¨æ¯å¦å¯è¿å
¥æ¤å¯¹è±¡çå
¶å®æ¹æ³?
ä¸è½ï¼ä¸ä¸ªå¯¹è±¡çä¸ä¸ªsynchronizedæ¹æ³åªè½ç±ä¸ä¸ªçº¿ç¨è®¿é®ã
37ï¼try {}éæä¸ä¸ªreturnè¯å¥ï¼é£ä¹ç´§è·å¨è¿ä¸ªtryåçfinally {}éçcodeä¼ä¸ä¼è¢«æ§è¡ï¼ä»ä¹æ¶å
被æ§è¡ï¼å¨returnåè¿æ¯å?
ä¼æ§è¡ï¼å¨returnåæ§è¡ã
38ï¼ç¼ç¨é¢: ç¨æææççæ¹æ³ç®åº2ä¹ä»¥8çæ¼å ?
æCèæ¯çç¨åºåç¹å«å欢é®è¿ç§é®é¢ã
2 << 3
39ï¼ä¸¤ä¸ªå¯¹è±¡å¼ç¸å(x.equals(y) == true)ï¼ä½å´å¯æä¸åçhash codeï¼è¿å¥è¯å¯¹ä¸å¯¹?
ä¸å¯¹ï¼æç¸åçhash codeã
40ï¼å½ä¸ä¸ªå¯¹è±¡è¢«å½ä½åæ°ä¼ éå°ä¸ä¸ªæ¹æ³åï¼æ¤æ¹æ³å¯æ¹åè¿ä¸ªå¯¹è±¡çå±æ§ï¼å¹¶å¯è¿ååååçç»æï¼
é£ä¹è¿éå°åºæ¯å¼ä¼ éè¿æ¯å¼ç¨ä¼ é?
æ¯å¼ä¼ éãJava ç¼ç¨è¯è¨åªç±å¼ä¼ éåæ°ãå½ä¸ä¸ªå¯¹è±¡å®ä¾ä½ä¸ºä¸ä¸ªåæ°è¢«ä¼ éå°æ¹æ³ä¸æ¶ï¼åæ°
çå¼å°±æ¯å¯¹è¯¥å¯¹è±¡çå¼ç¨ã对象çå
容å¯ä»¥å¨è¢«è°ç¨çæ¹æ³ä¸æ¹åï¼ä½å¯¹è±¡çå¼ç¨æ¯æ°¸è¿ä¸ä¼æ¹åçã
41ï¼swtichæ¯å¦è½ä½ç¨å¨byteä¸ï¼æ¯å¦è½ä½ç¨å¨longä¸ï¼æ¯å¦è½ä½ç¨å¨Stringä¸?
switchï¼expr1ï¼ä¸ï¼expr1æ¯ä¸ä¸ªæ´æ°è¡¨è¾¾å¼ãå æ¤ä¼ éç» switch å case è¯å¥çåæ°åºè¯¥æ¯ int
ã shortã char æè
byteãlong,string é½ä¸è½ä½ç¨äºswtichã
42ï¼ç¼ç¨é¢: åä¸ä¸ª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çã
ä¸è¬è®¤ä¸ºç¬¬ä¸ç§å½¢å¼è¦æ´å å®å
¨äº
HashtableåHashMap
Hashtable继æ¿èªDictionaryç±»ï¼èHashMapæ¯Java1.2å¼è¿çMap interfaceçä¸ä¸ªå®ç°
HashMapå
许å°nullä½ä¸ºä¸ä¸ªentryçkeyæè
valueï¼èHashtableä¸å
许
è¿æå°±æ¯ï¼HashMapæHashtableçcontainsæ¹æ³å»æäºï¼æ¹æcontainsvalueåcontainsKeyãå 为
containsæ¹æ³å®¹æ让人å¼èµ·è¯¯è§£ã
æ大çä¸åæ¯ï¼Hashtableçæ¹æ³æ¯Synchronizeçï¼èHashMapä¸æ¯ï¼å¨
å¤ä¸ªçº¿ç¨è®¿é®Hashtableæ¶ï¼ä¸éè¦èªå·±ä¸ºå®çæ¹æ³å®ç°åæ¥ï¼èHashMap
å°±å¿
须为ä¹æä¾å¤åæ¥ã
HashtableåHashMapéç¨çhash/rehashç®æ³é½å¤§æ¦ä¸æ ·ï¼æ以æ§è½ä¸ä¼æå¾å¤§çå·®å¼ã
43.æè¿°ä¸ä¸JVMå è½½classæ件çåçæºå¶?
44.è¯ä¸¾ä¾è¯´æä¸ä¸ªå
¸åçåå¾åæ¶ç®æ³ï¼
45.请ç¨javaåäºåæ ç®æ³ï¼å®ç°æ·»å æ°æ®å½¢æäºåæ åè½ï¼å¹¶ä»¥å
åºçæ¹å¼æå°åºæ¥.
46.请åä¸ä¸ªjavaç¨åºå®ç°çº¿ç¨è¿æ¥æ± åè½ï¼
47.ç»å®ä¸ä¸ªCè¯è¨å½æ°ï¼è¦æ±å®ç°å¨javaç±»ä¸è¿è¡è°ç¨ã
48ãç¼ä¸æ®µä»£ç ï¼å®ç°å¨æ§å¶å°è¾å
¥ä¸ç»æ°ååï¼æåºåå¨æ§å¶å°è¾åºï¼
49ãååºææ件夹ä¸çæææ件ï¼
50ãè°ç¨ç³»ç»å½ä»¤å®ç°å é¤æ件çæä½ï¼
51ãå®ç°ä»æ件ä¸ä¸æ¬¡è¯»åºä¸ä¸ªå符çæä½ï¼
52ãååºä¸äºæ§å¶æµç¨çæ¹æ³ï¼
53ãå¤çº¿ç¨æåªäºç¶æï¼
54ãç¼åäºä¸ä¸ªæå¡å¨ç«¯çç¨åºå®ç°å¨å®¢æ·ç«¯è¾å
¥å符ç¶åå¨æ§å¶å°ä¸æ¾ç¤ºï¼ç´å°è¾å
¥"END"为æ¢ï¼è®©ä½
ååºå®¢æ·ç«¯çç¨åºï¼
55ãä½ç¨åpublic,private,protected,以åä¸åæ¶çåºå«
çï¼åºå«å¦ä¸ï¼
ä½ç¨å å½åç±» åä¸package ååç±» å
¶ä»package
public â â â â
protected â â â Ã
friendly â â Ã Ã
private â Ã Ã Ã
ä¸åæ¶é»è®¤ä¸ºfriendly
56ãArrayListåVectorçåºå«,HashMapåHashtableçåºå«
çï¼å°±ArrayListä¸Vector主è¦ä»äºæ¹é¢æ¥è¯´.
ä¸.åæ¥æ§:Vectoræ¯çº¿ç¨å®å
¨çï¼ä¹å°±æ¯è¯´æ¯åæ¥çï¼èArrayListæ¯çº¿ç¨åºä¸å®å
¨çï¼ä¸æ¯åæ¥ç
äº.æ°æ®å¢é¿:å½éè¦å¢é¿æ¶,Vectoré»è®¤å¢é¿ä¸ºåæ¥ä¸å¹ï¼èArrayListå´æ¯åæ¥çä¸å
å°±HashMapä¸HashTable主è¦ä»ä¸æ¹é¢æ¥è¯´ã
ä¸.åå²åå :Hashtableæ¯åºäºéæ§çDictionaryç±»çï¼HashMapæ¯Java 1.2å¼è¿çMapæ¥å£çä¸ä¸ªå®ç°
äº.åæ¥æ§:Hashtableæ¯çº¿ç¨å®å
¨çï¼ä¹å°±æ¯è¯´æ¯åæ¥çï¼èHashMapæ¯çº¿ç¨åºä¸å®å
¨çï¼ä¸æ¯åæ¥ç
ä¸.å¼ï¼åªæHashMapå¯ä»¥è®©ä½ å°ç©ºå¼ä½ä¸ºä¸ä¸ªè¡¨çæ¡ç®çkeyævalue
57ãcharååéä¸è½ä¸è½åè´®ä¸ä¸ªä¸ææ±å?为ä»ä¹?
çï¼æ¯è½å¤å®ä¹æ为ä¸ä¸ªä¸æçï¼å 为javaä¸ä»¥unicodeç¼ç ï¼ä¸ä¸ªcharå 16个åèï¼æ以æ¾ä¸ä¸ªä¸ææ¯
没é®é¢ç
58ãå¤çº¿ç¨æå ç§å®ç°æ¹æ³,é½æ¯ä»ä¹?åæ¥æå ç§å®ç°æ¹æ³,é½æ¯ä»ä¹?
çï¼å¤çº¿ç¨æ两ç§å®ç°æ¹æ³ï¼åå«æ¯ç»§æ¿Threadç±»ä¸å®ç°Runnableæ¥å£
åæ¥çå®ç°æ¹é¢æ两ç§ï¼åå«æ¯synchronized,waitä¸notify
59ãåå¾åæ¶æºå¶,å¦ä½ä¼åç¨åº?
å¸æ大家补ä¸ï¼è°¢è°¢
60ãfloatåfloat f=3.4æ¯å¦æ£ç¡®?
ç:ä¸æ£ç¡®ã精度ä¸åç¡®,åºè¯¥ç¨å¼ºå¶ç±»å转æ¢ï¼å¦ä¸æ示ï¼float f=(float)3.4
61ãä»ç»JAVAä¸çCollection FrameWork(å
æ¬å¦ä½åèªå·±çæ°æ®ç»æ)?
çï¼Collection FrameWorkå¦ä¸ï¼
Collection
âList
ââLinkedList
ââArrayList
ââVector
â âStack
âSet
Map
âHashtable
âHashMap
âWeakHashMap
Collectionæ¯æåºæ¬çéåæ¥å£ï¼ä¸ä¸ªCollection代表ä¸ç»Objectï¼å³Collectionçå
ç´ ï¼Elementsï¼
Mapæä¾keyå°valueçæ å°
62ãJavaä¸å¼å¸¸å¤çæºå¶ï¼äºä»¶æºå¶ï¼
11ãJAVAä¸çå¤å½¢ä¸ç»§æ¿ï¼
å¸æ大家补ä¸ï¼è°¢è°¢
63ãæ½è±¡ç±»ä¸æ¥å£ï¼
çï¼æ½è±¡ç±»ä¸æ¥å£é½ç¨äºæ½è±¡ï¼ä½æ¯æ½è±¡ç±»(JAVAä¸)å¯ä»¥æèªå·±çé¨åå®ç°ï¼èæ¥å£åå®å
¨æ¯ä¸ä¸ªæ è¯(
åæ¶æå¤é继æ¿çåè½)ã
ç¼ç¨é¢ï¼
1ï¼ç°å¨è¾å
¥n个æ°åï¼ä»¥éå·ï¼åå¼ï¼
ç¶åå¯éæ©åæè
éåºæåºï¼
ææ交é®å°±å¨å¦ä¸é¡µé¢æ¾ç¤º
æä»ä¹ æåºï¼ç»æä¸ºï¼ ï¼
æä¾reset
çæ¡ï¼1ï¼ public static String[] splitStringByComma(String source){
if(source==null||source.trim().equals(""))
return null;
StringTokenizer commaToker = new StringTokenizer(source,",");
String[] result = new String[commaToker.countTokens()];
int i=0;
while(commaToker.hasMoreTokens()){
result[i] = commaToker.nextToken();
i++;
}
return result;
}
循ç¯éåStringæ°ç»
Integer.parseInt(String s)åæintç±»å
ç»æintæ°ç»
Arrays.sort(int[] a),
aæ°ç»ååº
éåºå¯ä»¥ä»å°¾é¨å¼å§è¾åº
2ï¼éé¢è½¬æ¢ï¼é¿æ伯æ°åçéé¢è½¬æ¢æä¸å½ä¼ ç»çå½¢å¼å¦ï¼
ï¼ï¿¥1011ï¼ï¼>ï¼ä¸åé¶ä¸æ¾ä¸å
æ´ï¼è¾åºã
3ã继æ¿æ¶åç±»çæ§è¡é¡ºåºé®é¢,ä¸è¬é½æ¯éæ©é¢,é®ä½ å°ä¼æå°åºä»ä¹?
ç:ç¶ç±»ï¼
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
4ãå
é¨ç±»çå®ç°æ¹å¼?
çï¼ç¤ºä¾ä»£ç å¦ä¸ï¼
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
5ã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 Remo