Java Serializable£¨ÐòÁл¯£©µÄÀí½âºÍ×ܽá
1¡¢ÐòÁл¯ÊǸÉʲôµÄ£¿
¼òµ¥Ëµ¾ÍÊÇΪÁ˱£´æÔÚÄÚ´æÖеĸ÷ÖÖ¶ÔÏóµÄ״̬£¨Ò²¾ÍÊÇʵÀý±äÁ¿£¬²»ÊÇ·½·¨£©£¬²¢ÇÒ¿ÉÒ԰ѱ£´æµÄ¶ÔÏó״̬ÔÙ¶Á³öÀ´¡£ËäÈ»Äã¿ÉÒÔÓÃÄã×Ô¼ºµÄ¸÷ÖÖ¸÷ÑùµÄ·½·¨À´±£´æobject states£¬µ«ÊÇJava¸øÄãÌṩһÖÖÓ¦¸Ã±ÈÄã×Ô¼ººÃµÄ±£´æ¶ÔÏó״̬µÄ»úÖÆ£¬ÄǾÍÊÇÐòÁл¯¡£
2¡¢Ê²Ã´Çé¿öÏÂÐèÒªÐòÁл¯
a£©µ±ÄãÏë°ÑµÄÄÚ´æÖеĶÔÏó״̬±£´æµ½Ò»¸öÎļþÖлòÕßÊý¾Ý¿âÖÐʱºò£»
b£©µ±ÄãÏëÓÃÌ×½Ó×ÖÔÚÍøÂçÉÏ´«ËͶÔÏóµÄʱºò£»
c£©µ±ÄãÏëͨ¹ýRMI´«Êä¶ÔÏóµÄʱºò£»
3¡¢µ±¶ÔÒ»¸ö¶ÔÏóʵÏÖÐòÁл¯Ê±£¬¾¿¾¹·¢ÉúÁËʲô£¿
ÔÚûÓÐÐòÁл¯Ç°£¬Ã¿¸ö±£´æÔÚ¶Ñ£¨Heap£©ÖеĶÔÏó¶¼ÓÐÏàÓ¦µÄ״̬£¨state£©£¬¼´ÊµÀý±äÁ¿£¨instance ariable£©±ÈÈ磺
java ´úÂë
Foo myFoo = new Foo();
myFoo .setWidth(37);
myFoo.setHeight(70);
µ± ͨ¹ýÏÂÃæµÄ´úÂëÐòÁл¯Ö®ºó£¬MyFoo¶ÔÏóÖеÄwidthºÍHeightʵÀý±äÁ¿µÄÖµ£¨37£¬70£©¶¼±»±£´æµ½foo.serÎļþÖУ¬ÕâÑùÒÔºóÓÖ¿ÉÒÔ°ÑËü ´ÓÎļþÖжÁ³öÀ´£¬ÖØÐÂÔÚ¶ÑÖд´½¨ÔÀ´µÄ¶ÔÏó¡£µ±È»±£´æÊ±ºò²»½ö½öÊDZ£´æ¶ÔÏóµÄʵÀý±äÁ¿µÄÖµ£¬JVM»¹Òª±£´æÒ»Ð©Ð¡Á¿ÐÅÏ¢£¬±ÈÈçÀàµÄÀàÐ͵ÈÒÔ±ã»Ö¸´ÔÀ´µÄ¶Ô Ïó¡£
java ´úÂë
FileOutputStream fs = new FileOutputStream("foo.ser");
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(myFoo);
4¡¢ÊµÏÖÐòÁл¯£¨±£´æµ½Ò»¸öÎļþ£©µÄ²½Öè
a£©Make a FileOutputStream
java ´úÂë
FileOutputStream fs = new FileOutputStream("foo.ser");
b£©Make a ObjectOutputStream
java ´úÂë
ObjectOutputStream os = new ObjectOutputStream(fs);
c£©write the object
java ´úÂë
os.writeObject
Ïà¹ØÎĵµ£º
13.2.1 ÍøÂç±à³Ì²½Öè
°´ÕÕÇ°ÃæµÄ»ù´¡ÖªÊ¶½éÉÜ£¬ÎÞÂÛʹÓÃTCP·½Ê½»¹ÊÇUDP·½Ê½½øÐÐÍøÂçͨѶ£¬ÍøÂç±à³Ì¶¼ÊÇÓɿͻ§¶ËºÍ·þÎñÆ÷¶Ë×é³É¡£µ±È»£¬B/S½á¹¹µÄ±à³ÌÖÐÖ»ÐèҪʵÏÖ·þÎñÆ÷¶Ë¼´¿É¡£ËùÒÔ£¬ÏÂÃæ½éÉÜÍøÂç±à³ÌµÄ²½Öèʱ£¬¾ùÒÔC/S½á¹¹Îª»ù´¡½øÐнéÉÜ¡£
......
µÚÒ»£¬Ì¸Ì¸final, finally, finalizeµÄÇø±ð¡£
¡¡¡¡µÚ¶þ£¬Anonymous Inner Class (ÄäÃûÄÚ²¿Àà) ÊÇ·ñ¿ÉÒÔextends(¼Ì³Ð)ÆäËüÀ࣬ÊÇ·ñ¿ÉÒÔimplements(ʵÏÖ)interface(½Ó¿Ú)?
¡¡¡¡µÚÈý£¬Static Nested Class ºÍ Inner ClassµÄ²»Í¬£¬ËµµÃÔ½¶àÔ½ºÃ(ÃæÊÔÌâÓеĺÜÁýͳ)¡£
¡¡¡¡µÚËÄ£ ......
½ñÌìͬѧÎÊÎÒÒ»¸öJavaÎÊÌ⣬´úÂë½á¹¹ÈçÏ£º
Scanner scan = new Scanner(System.in);
scan.next();
scan.close();
scan = new Scanner(System.in);
scan.next();
µ±³ÌÐòÔËÐе½µÚÎåÐÐÊÇ»áÅ׳öjava.util.NoSuchElementException
at&nb ......
Õâ²»ÊÇʲô½Ì²Ä£¬±ÊÕßÓÐʱ»áÔÚÂÛ̳ÉÏÇÆÇÆ£¬¿´µ½²»ÉÙ³õѧÕßÎʵ½ºÜ¶àÎÊÌ⣬ÕâЩÎÊÌâÊÇjava³ÌÐòÔ±Ó¦¸Ã¶®µÃµÄ£¬¶øÒ»°ãÊéÉϲ»»á½²µ½»òÕßÒ»±Ê´ø¹ýµÄ֪ʶ¡£Òò´Ë¶·µ¨Í¿Ñ»Ò»ÆªÎÄÕ£¬°ÑÏë˵µÄÔÚÕâÀïÒ»¿ÚÆøËµÍê¡£ÕâÒ²ÊDZ¾È˵ÚÒ»´Îд¼¼ÊõÐÔµÄÎÄÕ£¬Îıʲ»³©Ö®Í⣬»¹Çë¸÷λ¼ûÁ¡£
Ê×ÏȽ²Çå³þÀàºÍ¶ÔÏóµÄÇø±ð¡£
ÀàÊǹ㷺µÄ¸ÅÄ±íʾһ¸ö ......
1.±à³Ì½ç×îÖøÃûµÄÒ»¾ä»°“Hello world!”,ÈκÎÒ»¸ö³ÌÐòÔ±Æð²½Ê±±ØÓöµÄÓï¾ä
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("Hello World!");
......