接å£Interface)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.接å£çš„æ‰€æœ‰æ–¹æ³•默认都是public,abstractå’Œnon-staticçš?br />
2.接å£çš„æ‰€æœ‰å˜é‡é»˜è®¤éƒ½æ˜¯public,static,finalçš?所ä»?接å£çš„å˜é‡ä¸èƒ½æ”¹å€?在它的实现类é‡?
3.接å£çš„实现类实现的方法必™åÕd’ŒæŽ¥å£çš„æ–¹æ³•æŠ›å‡ºåŒæ ïLš„异常,ä¸è®¸æ˜¯å¾c?˜q™å’Œoverrideä¸ä¸€æ ?åŒæ ·,å¦‚æžœæŽ¥å£æ–ÒŽ³•没有æŠ?实现æ–ÒŽ³•也ä¸èƒ½æŠ›.
4.实现¾cÕd®žçŽ°çš„æ–ÒŽ³•必须昑ּ的声明æˆpublic,什么都ä¸å†™éƒ½ä¸è¡?å•?!!
5.接å£ä¸èƒ½å£°æ˜Žæˆfinal,è¦ä¸å®ƒæ€Žä¹ˆè¢«å®žçް呢(˜q™å¥½åƒåˆæ˜¯åºŸè¯å•Š
6.一个类实现两个接å£,å¦‚æžœä¸¤ä¸ªæŽ¥å£æœ‰ç›¸åŒçš„æ–ÒŽ³•,实现¾cÕd°±å®žçް˜q™ä¸ªæ–ÒŽ³•,没问题的.
内嵌¾c»Inner Class)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.内嵌¾cÕd¯ä»¥è®¿é—®outer¾cÈš„ä»ÖM½•å˜é‡,包括¿U有çš?
2.陿€inner¾c?åªèƒ½è®‰K—®outer¾cÈš„ä»ÖM½•staticå˜é‡
2.1内嵌¾cÕd¯ä»¥æ˜¯final,abstractçš?br />
3.我é ,æ–ÒŽ³•内的内嵌¾cÖM¸èƒ½äØ“static: void test(){ static class A{}} XXXXX!!!!
4.我é ,æ–ÒŽ³•内的内嵌¾cÖM¹Ÿä¸èƒ½å¸¦ä“Q何modifier,void test(){ public class A{}} XXXXX!!!!
5.我é ,æ–ÒŽ³•内的内嵌¾cÕdªèƒ½è®¿é—®æ–¹æ³•内的finalå˜é‡,但是,å¯ä»¥è®‰K—®outer¾cÈš„ä»ÖM½•å˜é‡.
6.匿å¾cÖM¸èƒ½æœ‰æž„é€ å™¨,ä½†å£°æ˜Žæ—¶å€™å¸¦å‚æ•°,ç›¸å½“äºŽæž„é€ å™¨çš„å‚æ•îC¼ é€?
class ABC{}
class ABCD{private ABCD(int i){}}
ABC test3(){return new ABC(){};}
ABCD test4(){return new ABCD(3){};}
interface iii{}
iii test5(){return new iii(){};}
//class BCD extends ABCD{} compile error,å› äØ“,
看上é¢å°±çŸ¥é“,new iii(){};实际上匿å类实现了iii接å£;new ABC(){};实际上是匿å¾cÈ‘ô承了ABC.
8.
class A {private A(){System.out.println("a!");}}
class B extends A{}
我é ,没错!B实例的时候会ä¸ÕdŠ¨è°ƒç”¨çˆ¶ç±»A的构é€?å³ä‹É是privateçš?看æ¥ä¹Ÿæ²¡é—®é¢˜!!!
9.内部¾cÕd¯ä»¥æœ‰synchronizedæ–ÒŽ³•,é‚£ä¹ˆé”æ˜¯˜q™ä¸ªå†…部¾c?跟外部类没一点关¾p?内外分别çš?在é”的问题上.
10.外部¾cÖM¸èƒ½é€šè¿‡this被访é—?this˜q™æ—¶å€™åº”该指的是内部¾c?享用外部¾cÈš„æˆå‘˜ž®Þq›´æŽ¥ç”¨,ä¸ç”¨åŠ ä“Q何é™å®šè¯
11.如何用this呢请�
class Outer{ int i;
class Inner{
class InnerInner{
void Test(){
Outer.this.i=1;
}
}
}
}
看è§äº†å§,¾cÕd.this.å˜é‡å?å¯ä»¥å¼•用到i,½W¬ä¸€‹Æ¡çœ‹åˆ°å§,嘿嘿,å¤é™‹å¯¡é—».
12.注愘q™ä¸¤¿U写法都å¯ä»¥
Class Outer.Inner i = new Outer().new Inner();
或� Class o= new Outer(); Class Outer.Inner i=o.new Inner();
¾U¿ç¨‹Thread)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
åŽÈœ‹Threadçš„API!!!!
1.¾U¿ç¨‹å¯åŠ¨å¿…é¡»é€šè¿‡start函数.
2.run函数ä¸è®¸ä¹Ÿåªèƒ½æ˜¯publicçš?
3.¾U¿ç¨‹æœ‰ä¼˜å…ˆçñ”ä»?åˆ?0,通过Thread.setPriority(int);æ¥æ”¹å?ä¸èƒ½‘…过10,å¦åˆ™ä¼šå‡ºçްè¿è¡Œå¼‚å¸?br />
4.¾U¿ç¨‹ä¼˜å…ˆ¾U§é»˜è®¤æ˜¯5,å³NORM_PRIORITY.NORM_PRIORITY是Threadçš„é™æ€å˜é‡å—
5.Thread.yeild();æ˜¯é™æ€æ–¹æ³?所ä»?ä½¿ç”¨æ ¼å¼æ˜¯Thread.yield();她强˜q«å½“å‰çš„˜q›ç¨‹æ”‘Ö¼ƒCUP.
6.sleep(1000),是说¾U¿ç¨‹ç¡è§‰1¿U?ç„¶åŽ,˜q›å…¥Ready状æ€?注æ„,䏿˜¯˜q行状æ€?它还è¦ç‰OSæ¥è°ƒåº¦æ¥èŽ·å¾—CUP.
java.lang.*;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.数组的科� int ia[][]={{1,2},null}; int ib[][]=(int[][])ia.clone();
2.什么是NaNç„¶åŽçœ‹ceil(NaN),floor(NaN),...
3.Math.floor(-1.1f);//-2.0
Math.ceil(-1.1f);//-1.0
Math.round(-1.6d)//-2
4.0=<1
5.Math,Interger,Boolean...½{‰ç±»åž‹åŒ…装类都是finalçš?ä¸å¯¾l§æ‰¿
6.int round(float); long round(double);å”?round永远˜q”回ä¸äº†ž®æ•°ç‚?br />
7.static double ceil(double)
8.static double floor(double)注æ„åQŒceil,floorçš„åªæœ‰è¿™ä¸ªdouble版本,什么都转æˆdouble!
9.static double sin(double 弧度); ˜q˜æœ‰cos,tan
10. new String; å¯ä»¥æ˜¯byte[];char[];String;StringBuffer
11. String的一些函� int length(); char charAt(int); String toUpperCase(); String toLowerCase();
12. String("Abc").equals(String("abc"))ä¸ç›¸½{‰çš„,ä¸ç„¶ž®×ƒ¸ä¼šæœ‰boolean equalsIgnoreCase(String)函数
13."012345678"是一个串的顺åºå·ç ?indexOf('1'),indexOf("1")都返å›?,subString(1,5)æ˜?345,嘿嘿:æ˜?[)"的感è§?br />
14, trim()˜qžtab都退æ¯?"\t\n java ",trim()一下就åªå‰©ä¸?java"äº?br />
15. 关于对象的科éš?åŽÕd–³å–³API
16. "abcd".trim(),"abcd" + new String("ef")都是åˆç†çš„写æ³?br />
17. StringBufferçš?ä¸ªæž„é€ å™¨: ()åˆå§‹åŒ–容é‡äØ“16,(int åˆå§‹åŒ–容é‡?,(String),åˆå§‹åŒ–容é‡äØ“ä¸²é•¿åŠ ä¸Š16
18. StringBuffer的一些函� String toString(); append();reverse();insert();delete(int start,int end);deleteCharAt(int);setLength(int newLength);
19. String s=""; StringBuffer sb=new StringBuffer(); if (s==sb){}¾~–译é”?å› äØ“,s,sb¾cÕdž‹ä¸ä¸€æ ?ä¸èƒ½æ¯”较
集åˆ:
1.儿ޥå£å’Œ¾cÈš„关系,åªæœ‰æœ€åŽä¸€ä¸ªæ˜¯¾c?br />
Collection:List:vector,ArrayList,LinkedList
Map:SortedMap:TreeMap
Collection:Set:SortedSet:TreeSet
Map:HashTable
Collection:Set:HashSet
基础Base)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.java applicationçš„mainå¯ä»¥ä¸æ˜¯publicçš?但必™åÀL˜¯staticçš?br />
2.一个文件åªèƒ½æœ‰ä¸€ä¸ªpublic¾c?而且˜q˜å¾—跟文件å一æ ?包括大å°å†?br />
3.å˜é‡åªèƒ½æ˜¯å—æ¯?$,_å¼€å¤?接下æ¥çš„½W¬äºŒä¸ªå¯ä»¥æ˜¯,æ•°å—
4.ch\u0061r='a'; char \u0063='b'; char c='\u0063';éƒ½æ˜¯åˆæ³•çš?br />
5.1e-5d,åˆæ³•.e-5dä¸åˆæ³?必须有å‰é¢çš„¾pÀL•°
6.int[] i[]={null{1,2}}æ£ç¡®! int i[]={1,2,3,} æ£ç¡®!","和没有的效果一æ ?br />
7.局部array,è·Ÿå˜é‡ä¸€æ ?使用å‰è¦åˆå§‹åŒ?br />
8.mainæ–ÒŽ³•å¯ä»¥ä¸ºfinal
æ“作½W¦å’Œåˆ†é…½W?Operator and Assignment)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.System.out.printl(1+2+"3");//33 System.out.printl("1"+2+3);//123
2.int i=0; i=i++;i=i++;i=i++; ¾l“æžœ,i=0!
3.int i[]; index=0; i[index]=index=5; ¾l“æžœæ˜?i[0]=5;!!!
4.byte b=10;å¯ä»¥,å› äØ“,10å¯ä»¥è¢«è‡ªåŠ¨ä»Žint转æˆbyte
5.接下æ?byte b=b+10;ä¸å¯ä»?!å› äØ“,10+båŽçš„intæ— æ³•è¢«è‡ªåŠ¨ä»Žint转æˆbyte,问我,我也ä¸çŸ¥é“䨓什ä¹?é?
6.byte b1 = 4; byte b2 = 6; b1 = b1 + b2;é”?¾~–译é”?b1 + b2å?必须强制转æˆbyte,b1x1+b2);
7.XOR 一æ ïLš„ä¸?åQŒä¸ä¸€æ ·äØ“1 1,1=0;0,0=0;1,0/0,1=1
8. x == Float.NaN¾~–译错,应该是Float.IsNaN
9. x == Double.POSITIVE_INFINITY¾~–译å¯ä»¥
10.-1æ˜?111.... 1111,<<永远匙¡¥é›Óž¼Œ>>æ£è¡¥é›Óž¼Œè´Ÿè¡¥ä¸€åQ?gt;>>æ’è¡¥é›?br />
10.1 -1>>多少ä½éƒ½æ˜?1 ; 1<<31å˜æˆäº†æœ€ž®è´Ÿæ•?1000....0000
11.æœ€å¤§æ£æ•°æ˜¯01111....1111
12.最ž®è´Ÿæ•°æ˜¯1000....0000(-2147483648)
13. a instanceof b,b必须是类/接å£åQŒä¸èƒ½æ˜¯å®žä¾‹
--------补充------------------------------
1. byte,short,char 都å˜åœ?var = -var;¾~–译错误,å› äØ“,˜q™æ—¶å€™çš„-varå·²ç»è‡ªåŠ¨è½¬æˆä¸ªint¾cÕdž‹äº?br />
2. int/0会扔出ArithmeticException
double,float/0得INF或�INF
0/0å¾—NaN
3. int a-b-c;是丽W¦åˆå‘½å规则的å˜é‡å¾~–译会出é”?
4. char a='\u0001';å¯? char b=\u0001;¾~–译é”?
5. boolean b1,b2,b3,b4,b5;
b1 = b2==b3;
b1 = b2<=b3 && b4==b5;
b1 = b2==b3==true
都是对的!é?å˜æ€?
b1 = b2==b3==b4 XXXXXXX¾~–译é”?
6. 1>>1 �
7. %= <<= =>> =>>>éƒ½æ˜¯åˆæ³•½W¦å·
8. --1-10*4 ˜q™ç§å†™æ³•没错,ž®±æ˜¯ (--1)-10*4
9. k=1;++k + k++ + +k ;¾l“æžœæ˜?,相当äº?(++2)+(2++)+(+3)
10.æ ‡å·ä¸èƒ½æ ‡ç¤ºå£°æ˜Ž.
hi:
if {
break hi;
//break hi1;ä¸è¡Œ,ä¸èƒ½å‘åŽè°ƒè{
}
//hi1:ä¸è¡Œ,ä¸èƒ½æ”‘Öœ¨å£°æ˜Žå‰?br />
int i;
hi1:
i=1;
11.public static void main(String s[]) throws Exception{}å¯ä»¥å™?mainå¯ä»¥æ‰”出异常
12. hi:
if(b==true){break hi;}
break æ ‡å·åQŒå¯ä»¥ç”¨åœ¨if里é¢.别的ä»ÖM½•都ä¸è¡?包括break,continue æ ‡å·.
13.int x = i*-j; 我é ,没问题的!!!¾~–译没错! int x = i*j++ + +i++; ˜q™ä¸ªä¹Ÿæ²¡é—®é¢˜,
å˜é‡ä¿®é¥°½W?Modifier)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.最外é¢ä¸€å±‚çš„¾cÖM¸èƒ½å£°æ˜Žæˆprotectå’Œpraviteçš?br />
2.åŒä¸€ä¸ªç±»çš„两个实例之间å¯ä»¥è®¿é—®å½¼æ¤çš„¿U有æ–ÒŽ³•å’Œç§æœ‰å˜é‡?é…?br />
3.protectå’Œæ— ä¿®é¥°½W¦çš„具体区别关于外包å¯ä»¥è®‰K—®è¢«å¾c»è®¿é—®çš„æ˜¯å“ªä¸?br />
4.æˆå‘˜å˜é‡è¢«ä¿®é¥°æˆfinalå?必须声明时候就赋åˆå€¼æˆ–è€…åœ¨æž„é€ å™¨é‡Œé¢èµ‹åˆå€?别指望她å¯ä»¥å¾—到defaultå€?
5.抽象æ–ÒŽ³•ä¸èƒ½æ˜¯staticçš?!!
6.陿€æ–¹æ³•å°†éšç€¾cÈš„å˜åŒ–而å˜åŒ?看例å?
class Parent{
static void test(){System.out.println("hi,parent")};
}
class Child extends Parent{
static void test(){System.out.println("hi,child")};
}
Parent p = new Child();
p.test(); //打出æ¥çš„æ˜¯hi,parent!
7.陿€æ–¹æ³•å¯ä»¥é€šè¿‡¾cÈš„实例调用.
new Child().test(); �Child.test(); 都OK!
8.transientåªèƒ½ç”¨åœ¨¾cÈš„æˆå‘˜å˜é‡ä¸?ä¸èƒ½ç”¨åœ¨æ–ÒŽ³•é‡?
9.transientå˜é‡ä¸èƒ½æ˜¯finalå’Œstaticçš?br />
10.nativeæ–ÒŽ³•å¯ä»¥æ˜¯private,abstractdçš?/p>
‹¹ç¨‹æŽ§åˆ¶
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1。ä¸å¯åˆ°è¾„¡š„è¯å¥å£°æ˜Žä¸ºé”™åQšwhile(false){} ;for(;false{};if(false){}éƒ½æ— æ³•ç¼–è¯?br />
2。for(½W¬ä¸€éƒ¨åˆ†;的第一部分å¯ä»¥ç”¨æ¥å£°æ˜Žæˆ–者赋å€û|¼Œä½†ä¸èƒ½ä¸¤è€…都
3。byte b; switch
转型和上�Converting and Casting)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Binary operators convert the smaller(less precise) operand to the type of the larger(more precise) operand.
All operators will convert things smaller than ints to ints or larger. This includes char 's!
1.byte,char,short默认转æˆint
2.byte->short->int->long->float->double
char^
˜q™æ˜¯é»˜è®¤å¯ä»¥è½¬åž‹çš„æ–¹å?åäº†å¿…é¡»è¦æ˜¾å¼cast! 特别注æ„:long->float是默认的,别看long64,float32,嘿嘿
˜q˜æœ‰ž®±æ˜¯çœ‹å¾—出æ¥,charå’?byte,shortä¹‹é—´æ— æ³•äº’ç›¸é»˜è®¤è½¬æ¢
3.float f=1/3; OK!float f=1.0/3.0;¾~–译出错,å› äØ“1.0/3.0¾l“果是doubleçš?噢噢~,错喽!!
4.int i=1; byte b=i;é”?éœ€è¦æ˜¾å¼cast.
final i=1; byte b=i;ž®±ok! 我也ä¸çŸ¥é“䨓什ä¹?finalž®±å¯ä»?而且,æ®æˆ‘å®žéªŒåªæœ‰intå’Œbyte的关¾p»è¿™æ ?å…¶ä»–ä¸è¡Œ.
5.int i[]; Object[] obj=i;é”? Object obj=i;å¯? 数组åªèƒ½è½¬æˆObject,而ä¸èƒ½æ˜¯Object[]
6.int i[]; Object[] obj;i=(int[])obj; å¯? 对象å¯ä»¥é€šè¿‡æ˜‘Ö¼æ¥è{æˆä¸€ä¸ªæ•°¾l?
I/O
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.File¾cÈš„一些é‡è¦æ–¹æ³?isFile();isDirectory();String[] list();exists();getAbsolutePath();getParent();
2.通过delete();mkdir();rename(File newname);å¯ä»¥æ“纵文äšg,ä½†æ˜¯å´æ”¹å˜ä¸äº†æ–‡ä»¶çš„内容
2.1 File¾cÀL— 法改å˜å½“å‰ç›®å½?除éžé‡æ–°åˆ›å¾ä¸€ä¸ªFile对象.
3.InputStreamReader(InputStream in,String encodingName);
OutputStreamReader(OutputStream in,String encodingName);
Encoding: 8859_1是Latin-1,包å«ASCII
4.å…³é—close一个æµ,ž®Þp‡ªåŠ¨è°ƒç”¨äº†flush.
5.System.in,System.out,System.err,ç”±JVM自动创å¾
6.RandomAccessFile(File file,String mode);mode�r,rw
1:Set
public interface Set extends Collection
A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by its name, this interface models the mathematical set abstraction.
2:SortedSet
public interface SortedSet extends Set.
A set that further guarantees that its iterator will traverse the set in ascending element order, sorted according to the natural ordering of its elements (see Comparable), or by a Comparator provided at sorted set creation time.
3:HashSet
public class HashSet extends AbstractSet implements Set, Cloneable, Serializable
This class implements the Set interface, backed by a hash table (actually a HashMap instance). It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time. This class permits the null element.
4:TreeSet
public class TreeSet extends AbstractSet implements SortedSet, Cloneable, Serializable
This class implements the Set interface, backed by a TreeMap instance. This class guarantees that the sorted set will be in ascending element order, sorted according to the natural order of the elements (see Comparable), or by the comparator provided at set creation time, depending on which constructor is used.
5:LinkedHashSet:
public class LinkedHashSet extends HashSet implements Set, Cloneable, Serializable
Hash table and linked list implementation of the Set interface, with predictable iteration order. This implementation differs from HashSet in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is the order in which elements were inserted into the set (insertion-order). Note that insertion order is not affected if an element is re-inserted into the set. (An element e is reinserted into a set s if s.add(e) is invoked when s.contains(e) would return true immediately prior to the invocation.)
5:Map
public interface Map
An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.
6:SortedMap
public interface SortedMap extends Map
A map that further guarantees that it will be in ascending key order, sorted according to the natural ordering of its keys (see the Comparable interface), or by a comparator provided at sorted map creation time. (This interface is the map analogue of the SortedSet interface.)
7:HashMap(å…许keyå’Œvalue为NULL)
public class HashMap extends AbstractMap implements Map, Cloneable, Serializable
Hash table based implementation of the Map interface. This implementation provides all of the optional map operations, and permits null values and the null key. (The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.) This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time
8:TreeMap
public class TreeMap extends AbstractMap implements SortedMap, Cloneable, Serializable
Red-Black tree based implementation of the SortedMap interface. This class guarantees that the map will be in ascending key order, sorted according to the natural order for the key's class (see Comparable), or by the comparator provided at creation time, depending on which constructor is used.
9:HashTable(ä¸å…许keyå’Œvalue为NULL)
public class Hashtable extends Dictionary implements Map, Cloneable, Serializable.
This class implements a hashtable, which maps keys to values. Any non-null object can be used as a key or as a value.
9:LinkedHashMap
public class LinkedHashMap extends HashMap
Hash table and linked list implementation of the Map interface, with predictable iteration order. This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map (insertion-order). Note that insertion order is not affected if a key is re-inserted into the map. (A key k is reinserted into a map m if m.put(k, v) is invoked when m.containsKey(k) would return true immediately prior to the invocation.)
9:IdentityHashMap
public class IdentityHashMap extends AbstractMap implements Map, Serializable, Cloneable
This class implements the Map interface with a hash table, using reference-equality in place of object-equality when comparing keys (and values). In other words, in an IdentityHashMap, two keys k1 and k2 are considered equal if and only if (k1==k2). (In normal Map implementations (like HashMap) two keys k1 and k2 are considered equal if and only if (k1==null ? k2==null : k1.equals(k2)).)
This class is not a general-purpose Map implementation! While this class implements the Map interface, it intentionally violates Map's general contract, which mandates the use of the equals method when comparing objects. This class is designed for use only in the rare cases wherein reference-equality semantics are required.
10:List
public interface List extends Collection
An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.
Unlike sets, lists typically allow duplicate elements. More formally, lists typically allow pairs of elements e1 and e2 such that e1.equals(e2), and they typically allow multiple null elements if they allow null elements at all.
11:ArrayList
public class ArrayList extends AbstractList implements List, Cloneable, Serializable
Resizable-array implementation of the List interface. Implements all optional list operations, and permits all elements, including null. In addition to implementing the List interface, this class provides methods to manipulate the size of the array that is used internally to store the list. (This class is roughly equivalent to Vector, except that it is unsynchronized.)
12:LinkedList
public class LinkedList extends AbstractSequentialList implements List, Cloneable, Serializable
Linked list implementation of the List interface. Implements all optional list operations, and permits all elements (including null). In addition to implementing the List interface, the LinkedList class provides uniformly named methods to get, remove and insert an element at the beginning and end of the list. These operations allow linked lists to be used as a stack, queue, or double-ended queue (deque).
13:Vector
public class Vector extends AbstractList implements List, Cloneable, Serializable
The Vector class implements a growable array of objects. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created.
14:Collection
public interface Collection
The root interface in the collection hierarchy. A collection represents a group of objects, known as its elements. Some collections allow duplicate elements and others do not. Some are ordered and others unordered. The SDK does not provide any direct implementations of this interface: it provides implementations of more specific subinterfaces like Set and List. This interface is typically used to pass collections around and manipulate them where maximum generality is desired.
15:Collections
public class Collections extends Object
This class consists exclusively of static methods that operate on or return collections. It contains polymorphic algorithms that operate on collections, "wrappers", which return a new collection backed by a specified collection, and a few other odds and ends.
1. What will happen when you attempt to compile and run the following code?
public class Static
{
static
{
int x = 5;
}
static int x,y;
public static void main(String args[])
{
}
public static void myMethod()
{
y = x++ + ++x;
}
}
Choices:
a. Compiletime error
b. prints : 1
c. prints : 2
d. prints : 3
e. prints : 7
f. prints : 8
―――――――――――――――――――�/p>
1) D is the correct choice. The above code will not give any compilation error. Note that "Static" is a valid class name. Thus choice A is incorrect. In the above code, on execution, first the static variables (x and y) will be initialized to 0. Then static block will be called and finally main() method will be called. The execution of static block will have no effect on the output as it declares a new variable (int x). The first statement inside main (x--) will result in x to be -1. After that myMethod() will be executed. The statement "y = x++ + ++x;" will be evaluated to y = -1 + 1 and x will become 1. In case the statement be "y =++x + ++x", it would be evaluated to y = 0 + 1 and x would become 1. Finally when System.out is executed "x + y + ++x" will be evaluated to "1 + 0 + 2" which result in 3 as the output. Thus choice D is correct.
Considering the following code, Which variables may be referenced correctly at line 12?
1.public class Outer
2.{
3.public int a = 1;
4.private int b = 2;
5.public void method(final int c)
6.{
7.int d = 3;
8.class Inner
9.{
10.private void iMethod(int e)
11. {
12.
13.}
14.}
15.}
16.}
Choices:
a. a
b. b
c. c
d. d
e. e
A, B, C and E are correct. Since Inner is not a static inner class, it has a reference to an enclosing object, and all the variables of that object are accessible. Therefore A and B are correct, even if b is private. Variables in the enclosing method are only accessible when they are marked as final hence c is accessible but not d. E is obviously correct as it is a parameter to the method containing line 12 itself.
What will be the result of executing the following code?
// Filename; SuperclassX.java
package packageX;
public class SuperclassX
{
protected void superclassMethodX()
{
}
int superclassVarX;
}
// Filename SubclassY.java
1.package packageX.packageY;
2.
3.public class SubclassY extends SuperclassX
4.{
5.SuperclassX objX = new SubclassY();
6.SubclassY objY = new SubclassY();
7.void subclassMethodY()
8.{
9.objY.superclassMethodX();
10.int i;
11.i = objY.superclassVarX;
12.}
13.}
Choices:
a.Compilation error at line 5
b. Compilation error at line 9
c. Runtime exception at line 11
d. None of these
―――――――�/p>
D is correct. When no access modifier is specified for a member, it is only accessible by another class in the package where its class is defined. Even if its class is visible in another package, the member is not accessible there. In the question above the variable superclassVarX has no access modifier specified and hence it cannot be accessed in the packageY even though the class SuperclassX is visible and the protected method superclassMethodX() can be accessed. Thus the compiler will raise an error at line 11.
class FourWheeler implements DrivingUtilities
class Car extends FourWheeler
class Truck extends FourWheeler
class Bus extends FourWheeler
class Crane extends FourWheeler
----------------------------------------------------------------------
Consider the following code below:
1.DrivingUtilities du;
2.FourWheeler fw;
3.Truck myTruck = new Truck();
4.du = (DrivingUtilities)myTruck;
5.fw = new Crane();
6.fw = du;
Which of the statements below are true?
Choices:
a. Line 4 will not compile because an interface cannot refer to an object.
b. The code will compile and run.
c. The code will not compile without an explicit cast at line 6, because going
down the hierarchy without casting is not allowed.
d.The code at line 4 will compile even without the explicit cast.
e.The code will compile if we put an explicit cast at line 6 but will throw an exception at runtime.
――――――――――�/p>
C and D are correct. A and B are obviously wrong because there is nothing wrong in an interface referring to an object. C is correct because an explicit cast is needed to go down the hierarchy. D is correct because no explicit cast is needed at line 4, because we are going up the hierarchy. E is incorrect because if we put an explicit cast at line 6, the code will compile and run perfectly fine, no exception will be thrown because the runtime class of du (that is Truck) can be converted to type FourWheeler without any problem.
What will be printed when you execute the following code?
class X
{
Y b = new Y();
{
System.out.print("X");
}
}
class Y
{
{
System.out.print("Y");
}
}
public class Z extends X
{
{
System.out.print("Z");
}
{
}
Choices:
a. Z
b. YZ
c. XYZ
d. YXYZ
――――――――�/p>
D is correct. A difficult but a fundamental question, please observe carefully. Before any object is constructed the object of the parent class is constructed(as there is a default call to the parent's constructor from the constructor of the child class via the super() statement). Also note that when an object is constructed the variables are initialized first and then the constructor is executed. So when new Z() is executed , the object of class X will be constructed, which means Y b = new Y() will be executed and "Y" will be printed as a result. After that constructor of X will be called which implies "X" will be printed. Now the object of Z will be constructed and thus Y y = new Y() will be executed and Y will be printed and finally the constructor Z() will be called and thus "Z" will be printed. Thus YXYZ will be printed.
What will happen when you attempt to compile and run the following code?
class Base
{
int i = 99;
public void amethod()
{
{
}
public class Derived extends Base
{
int i = -1;
public static void main(String argv[])
{
{
}
Choices:
a. Derived.amethod()
-1
Derived.amethod()
b. Derived.amethod()
99
c.Derived.amethod()
99
d. Derived.amethod()
e.Compile time error
―――――――�/p>
B is correct. The reason is that this code creates an instance of the Derived class but assigns it to a reference of a the Base class. In this situation a reference to any of the fields such as i will refer to the value in the Base class, but a call to a method will refer to the method in the class type rather than its reference handle. But note that if the amethod() was not present in the base class then compilation error would be reported as at compile time, when compiler sees the statement like b.amethod(), it checks if the method is present in the base class or not. Only at the run time it decides to call the method from the derived class.
Given the following code fragment:
  1) public void create() {
  2) Vector myVect;
  3) myVect = new Vector();
  4) }
  Which of the following statements are true?
  A. The declaration on line 2 does not allocate memory space for the
variable myVect.
  B. The declaration on line 2 allocates memory space for a reference to a
Vector object.
  C. The statement on line 2 creates an object of class Vector.
  D. The statement on line 3 creates an object of class Vector.
  E. The statement on line 3 allocates memory space for an object of class
Vector
  ¾˜»è¯‘
  ¾l™å‡ºä¸‹é¢çš„代ç 片æ–。。。下é¢çš„哪些陈述为true(çœ??
  A. ½W¬äºŒè¡Œçš„声明ä¸ä¼šä¸ºå˜é‡myVect分é…内嘽Iºé—´ã€?/p>
  B. ½W¬äºŒè¡Œçš„声明分é…一个到Vector对象的引用的内嘽Iºé—´ã€?/p>
  C. ½W¬äºŒè¡Œè¯å¥åˆ›å»ÞZ¸€ä¸ªVector¾cÕd¯¹è±¡ã€?/p>
  D. ½W¬ä¸‰è¡Œè¯å¥åˆ›å»ÞZ¸€ä¸ªVector¾cÕd¯¹è±¡ã€?/p>
  E. ½W¬ä¸‰è¡Œè¯å¥äؓ一个Vector¾cÕd¯¹è±¡åˆ†é…内å˜ç©ºé—´ã€?/p>
  ½{”案 A,D,E
  解æž
  SL-275䏿Œ‡å‡ºï¼šè¦äؓ一个新对象分酽Iºé—´å¿…须执行new
Xxx()调用åQŒnew调用执行以下的æ“作:
  1åQŽäؓ新对象分é…ç©ºé—´åÆˆž®†å…¶æˆå‘˜åˆå§‹åŒ–䨓0或者nullã€?/p>
 
åQŒæ‰§è¡Œåˆ°½W¬äºŒæ¥åŽa=10åQ?/p>
  3åQŽæ‰§è¡Œæž„é€ å‡½æ•°ã€?/p>
  4åQŽå˜é‡è¢«åˆ†é…ä¸ÞZ¸€ä¸ªåˆ°å†…å˜å †ä¸çš„æ–°å¯¹è±¡çš„引用ã€?/p>
Which of the following statements about variables and their scopes
are true?
  A. Instance variables are member variables of a class.
  B. Instance variables are declared with the static keyword.
  C. Local variables defined inside a method are created when the method
is executed.
  D. Local variables must be initialized before they are used.
  (acd)
  题目åQšä¸‹é¢å…³äºŽå˜é‡åŠå…¶èŒƒå›´çš„陈述哪些是对的ã€?/p>
  A. 实例å˜é‡æ˜¯ç±»çš„æˆå‘˜å˜é‡ã€?/p>
  B. 实例å˜é‡ç”¨å…³é”®å—static声明ã€?/p>
  C. 在方法ä¸å®šä¹‰çš„局部å˜é‡åœ¨è¯¥æ–¹æ³•被执行时创å»?/p>
  D. 局部å˜é‡åœ¨ä½¿ç”¨å‰å¿…™å»è¢«åˆå§‹åŒ–ã€?/p>
  ¾cÖM¸æœ‰å‡ ¿Uå˜é‡ï¼Œåˆ†åˆ«æ˜¯ï¼šå±€éƒ¨å˜é‡ï¼ˆè‹±æ–‡å¯ä»¥ä¸ºï¼šlocal\automatic\temporary\stac
k
variableåQ‰æ˜¯å®šä¹‰åœ¨æ–¹æ³•里的å˜é‡ï¼›å®žä¾‹å˜é‡åQˆè‹±æ–‡äØ“åQšinstance
variableåQ‰æ˜¯åœ¨æ–¹æ³•外而在¾cÕd£°æ˜Žå†…定义的å˜é‡ï¼Œæœ‰æ—¶ä¹Ÿå«æˆå‘˜å˜é‡åQ›ç±»å˜é‡åQˆè‹±æ–‡äØ“åQšcl
ass
variableåQ‰æ˜¯ç”¨å…³é”®å—static声明的实例å˜é‡ï¼Œä»–ä»¬çš„ç”Ÿå˜æœŸåˆ†åˆ«æ˜¯ï¼šå±€éƒ¨å˜é‡åœ¨å®šä¹‰è¯¥å˜
é‡çš„æ–ÒŽ³•被调用时被创建,而在该方法退出åŽè¢«æ’¤é”€åQ›å®žä¾‹å˜é‡åœ¨ä½¿ç”¨new
Xxxx()创å¾è¯¥ç±»çš„å®žä¾‹æ—¶è¢«åˆ›å»ºï¼Œè€Œå…¶ç”Ÿå˜æœŸå’Œè¯¥ç±»çš„å®žä¾‹å¯¹è±¡çš„ç”Ÿå˜æœŸç›¸åŒï¼›¾cÕd˜é‡åœ¨è¯?/p>
¾c»è¢«åŠ è²æ—¶è¢«åˆ›å¾åQŒä¸ä¸€å®šè¦ç”¨new
Xxxx()创å¾åQŒæ‰€æœ‰è¯¥¾cÈš„实例对象å…׃ín该类å˜é‡åQŒå…¶ç”Ÿå˜æœŸæ˜¯¾cÈš„ç”Ÿå˜æœŸã€‚ä“Q何å˜é‡åœ¨ä½¿ç”¨
å‰éƒ½å¿…é¡»åˆå§‹åŒ?ä½†æ˜¯éœ€è¦æŒ‡å‡ºçš„æ˜¯å±€éƒ¨å˜é‡å¿…™åÀL˜¾å¼åˆå§‹åŒ–åQŒè€Œå®žä¾‹å˜é‡ä¸å¿…,原始¾cÕdž‹çš?/p>
实例å˜é‡åœ¨è¯¥¾cÈš„æž„é€ æ–¹æ³•è¢«è°ƒç”¨æ—¶äØ“å®ƒåˆ†é…çš„¾~ºçœçš„å€û|¼Œæ•´åž‹æ˜?åQŒå¸ƒž®”型是falseåQŒè€ŒæÕQç‚?/p>
型是0.0fåQŒå¼•用类型(¾cȱ»åž‹ï¼‰çš„实例å˜é‡çš„¾~ºçœå€¼æ˜¯nullåQˆæ²¡æœ‰è¿›è¡Œå®žé™…çš„åˆå§‹åŒ–,对它çš?/p>
使用ž®†å¼•èµ·NullPointExceptionåQ‰ï¼Œ¾cÕd˜é‡çš„规则和实例å˜é‡ä¸€æ øP¼Œä¸åŒçš„æ˜¯¾cÕd˜é‡çš„åˆå§‹åŒ?/p>
是在¾c»è¢«åŠ è²æ—¶ã€?/p>
  public class Parent {
  int change() {…}
  }
  class Child extends Parent {
  }
  Which methods can be added into class Child?
  A. public int change(){}
  B. int chang(int i){}
  C. private int change(){}
  D. abstract int chang(){}
  (ab)
  题目åQšå“ªäº›æ–¹æ³•å¯è¢«åŠ å…¥ç±»Childã€?/p>
ã€€ã€€éœ€è¦æ³¨æ„çš„æ˜¯ç”æ¡ˆD的内容,åç±»å¯ä»¥é‡å†™çˆ¶ç±»çš„æ–¹æ³•åÆˆž®†ä¹‹å£°æ˜Žä¸ºæŠ½è±¡æ–¹æ³•,但是˜q™å¼•å‘的问题是类必须声明为抽象类åQŒå¦åˆ™ç¼–译ä¸èƒ½é€šè¿‡åQŒè€Œä¸”抽象æ–ÒŽ³•ä¸èƒ½æœ‰æ–¹æ³•体åQŒä¹Ÿž®±æ˜¯æ–ÒŽ³•声明åŽé¢ä¸èƒ½å¸¦ä¸Šé‚£ä¸¤ä¸ªå¤§æ‹¬å·åQˆ{}åQ‰ï¼Œ˜q™äº›D都ä¸èƒ½æ»¡‘Ÿë€?/p>
In the following pieces of code, A and D will compile without any error. True/False?
A: StringBuffer sb1 = "abcd";
B: Boolean b = new Boolean("abcd");
C: byte b = 255;
D: int x = 0x1234;
E: float fl = 1.2;
Choices:
A. True
B. False
――――――――――――――――――――――――――――――�/p>
½{”案 B. The code segments B and D will compile without any error. A is not a valid way to construct a StringBuffer, you need to creat a StringBuffer object using "new". B is a valid construction of a Boolean (any string other than "true" or "false" to the Boolean constructor will result in a Boolean with a value of "false"). C will fail to compile because the valid range for a byte is -128 to +127 (ie, 8 bits,signed). D is correct, 0x1234 is the hexadecimal representation in java. E fails to compile because the compiler interprets 1.2 as a double being assigned to a float (down-casting), which is not valid. You either need an explicit cast (as in "(float)1.2") or "1.2f", to indicate a float.
What will be the result of executing the following code?
Given that Test1 is a class.
1. Test1[] t1 = new Test1[10];
2. Test1[][] t2 = new Test1[5][];
3. if (t1[0] == null)
4. {
5.t2[0] = new Test1[10]
6.t2[1] = new Test1[10]
7.t2[2] = new Test1[10]
8.t2[3] = new Test1[10]
9.t2[4] = new Test1[10]
10. }
11. System.out.println(t1[0]);
12. System.out.println(t2[1][0]);
Choices:
a. The code will not compile because the array t2 is not initialized in an unconditional statement before use.
b. The code will compile but a runtime exception will be thrown at line 12.
c. The code will compile but a runtime exception will be thrown at line 11.
d. None of these.
――――――――――――――――――――�/p>
D is correct. Though we cannot use local variables without initializing them (compilation error), there is an exception to it. In case of arrays initialization is supposed to be complete when we specify the leftmost dimension of the array. The problem occurs at runtime if we try to access an element of the array which has not been initialized (specification of size). In the question above the array t2 is initialized before use, therefore there will be no problem at runtime also and the lines 11 and 12 will both print null.
Which declarations of identifiers are legal?
 A. $persons
  B. TwoUsers
  C. *point
  D. this
  
  ½{”案 A,B,E
  
  解æžã€€Javaçš„æ ‡è¯†ç¬¦å¯ä»¥ä»¥ä¸€ä¸ªUnicodeå—符åQŒä¸‹æ»‘线åQˆ_åQ‰ï¼Œ¾ŸŽå…ƒ½W¦ï¼ˆ$åQ‰å¼€å§‹ï¼ŒåŽç®‹å?/p>
½W¦å¯ä»¥æ˜¯å‰é¢çš„符å·å’Œæ•°å—åQŒæ²¡æœ‰é•¿åº¦é™åˆÓž¼Œå¤§å°å†™æ•感,ä¸èƒ½æ˜¯ä¿ç•™å—ã€?/p>
Which of the following answer is correct to express the value 8 in octal number?
  A. 010
  B. 0x10
  C. 08
  D. 0x8
  ¾˜»è¯‘
  下é¢çš„å“ªäº›ç”æ¡ˆå¯ä»¥ç”¨ä»¥è¡¨½Cºå…«˜q›åˆ¶å€?ã€?/p>
  ½{”案 A
  解æžã€€ã€€å…«è¿›åˆ¶å€ég»¥0å¼€å¤ß_¼Œä»?x开头的为åå…进制å€û|¼Œå…«è¿›åˆ¶ä¸ä¸èƒ½å‡ºçŽ°æ•°å—8åQŒæœ€å¤§åªæœ?ã€?/p>
Which are not Java keywords?
  A. TRUE
  B. sizeof
  C. const
  D. super
  E. void
  ¾˜»è¯‘
ã€€ã€€å“ªäº›ä¸æ˜¯Java关键å—ã€?/p>
  ½{”案 A,B
  解æž
 
 BåQšä¸æ˜¯ï¼ŒJavaä¸ä¸éœ€è¦è¿™ä¸ªæ“作符åQŒæ‰€æœ‰çš„¾cÕdž‹åQˆåŽŸå§‹ç±»åž‹ï¼‰çš„å¤§ž®éƒ½æ˜¯å›ºå®šçš„ã€?/p>
 Cã€Dã€E都是åQŒéœ€è¦è¯´æ˜Žçš„æ˜¯const是java䏿œªè¢«ä‹É用的关键å—ã€?/p>
Which statements about Java code security are true?
  A. The bytecode verifier loads all classes needed for the execution of a program.
  B. Executing code is performed by the runtime interpreter.
  C. At runtime the bytecodes are loaded, checked and run in an interpreter.
  D. The class loader adds security by separating the namespaces for the
classes of the local file system from those imported from network sources.
―――――――――――――�/p>
½{”案 BCD
  题目åQšä¸‹é¢æœ‰å…³java代ç 安全性的å™è¿°å“ªäº›æ˜¯å¯¹çš„ã€?/p>
  A. å—èŠ‚ç æ ¡éªŒå™¨åŠ è²æŸ¥è¯¢æ‰§è¡Œéœ€è¦çš„æ‰€æœ‰ç±»ã€?/p>
  B. ˜q行时解释器执行代ç ã€?/p>
  C. 在è¿è¡Œæ—¶åQŒå—节ç è¢«åŠ è½½ï¼ŒéªŒè¯ç„¶åŽåœ¨è§£é‡Šå™¨é‡Œé¢˜q行ã€?/p>
  D. ¾cÕdŠ è½½å™¨é€šè¿‡åˆ†ç¦»æœ¬æœºæ–‡äšg¾pÈ»Ÿçš„类和从¾|‘ç»œå¯¼å…¥çš„ç±»å¢žåŠ å®‰å…¨æ€§ã€?/p>
  SL275䏿˜q°çš„Java½E‹åº˜q行的过½E‹æ˜¯˜q™æ ·çš„:¾cÕdŠ è½½å™¨åQˆclass loaderåQ‰åŠ è½½ç¨‹åºè¿è¡Œæ‰€éœ€è¦çš„æ‰€æœ‰ç±»åQŒå®ƒé€šè¿‡åŒºåˆ†æœ¬æœºæ–‡äšg¾pÈ»Ÿçš„类和网¾lœç³»¾lŸå¯¼å…¥çš„¾cÕd¢žåŠ å®‰å…¨æ€§ï¼Œ˜q™å¯ä»¥é™åˆ¶ä“Q何的ç‰ÒŽ´›ä¼Šæœ¨é©¬ç¨‹åºï¼Œå› äØ“æœ¬æœº¾cÀL€ÀL˜¯å…ˆè¢«åŠ è²åQŒä¸€æ—¦æ‰€æœ‰çš„¾c»è¢«åŠ è²å®Œï¼Œæ‰§è¡Œæ–‡äšg的内å˜åˆ’分就固定了,在这个时候特定的内å˜åœ°å€è¢«åˆ†é…给对应的符å·å¼•用,查找表(lookuo tableåQ‰ä¹Ÿè¢«å¾ç«‹ï¼Œç”׃ºŽå†…å˜åˆ’分å‘生在è¿è¡Œæ—¶åQŒè§£é‡Šå™¨åœ¨å—é™åˆ¶çš„代ç åŒºå¢žåŠ ä¿æŠ¤é˜²æ¢æœªæŽˆæƒçš„讉K—®åQ›ç„¶åŽå—èŠ‚ç æ ¡éªŒå™¨ï¼ˆbyte code verifieråQ‰è¿›è¡Œæ ¡éªŒï¼Œä¸»è¦æ‰§è¡Œä¸‹é¢çš„æ£€æŸ¥ï¼š¾cȬ¦åˆJVM规范的类文äšgæ ¼å¼åQŒæ²¡æœ‰è¿å访问é™åˆÓž¼Œä»£ç æ²¡æœ‰é€ æˆå †æ ˆçš„上溢或者下溢,所有æ“作代ç çš„å‚æ•°¾cÕdž‹éƒ½æ˜¯æ£ç¡®çš„ï¼Œæ²¡æœ‰éžæ³•的数æ®ç±»åž‹è{æ¢ï¼ˆä¾‹å¦‚ž®†æ•´åž‹æ•°è½¬æ¢æˆå¯¹è±¡ç±»åž‹ï¼‰å‘生åQ›æ ¡éªŒé€šè¿‡çš„å—节ç 被解释器åQˆinterpreteråQ‰æ‰§è¡Œï¼Œè§£é‡Šå™¨åœ¨å¿…è¦æ—‰™€šè¿‡˜q行时系¾lŸæ‰§è¡Œå¯¹åº•层¼‹¬äšgçš„åˆé€‚调用。åŽä¸‰ä¸ª½{”案是SL275ä¸çš„原è¯ã€?/p>
Which fragments are correct in Java source file?
  A. package testpackage;
  public class Test{//do something...}
  B. import java.io.*;
  package testpackage;
  public class Test{// do something...}
  C. import java.io.*;
  class Person{// do something...}
  public class Test{// do something...}
  D. import java.io.*;
  import java.awt.*;
  public class Test{// do something...}
------------------------
½{”案 ACD
 
Which of the following statements are legal?
  A. long l = 4990;
  B. int i = 4L;
  C. float f = 1.1;
  D. double d = 34.4;
  E. double t = 0.9F.
----------------------------
½{”案 ADE