Click here to load reader

SCJP ch16

Embed Size (px)

Citation preview

  • 1. 16 80%

2. Java 3. , "import java.io.*" Java I/O ( ) , BufferedReader readLine() , System.out.println() java.io , , (binary file), ZIP , java.io 4. 16-1 I/O , / ( ), (stream) , , 5. java. io , , , 1. ( ) 2. 3. , (input stream) (output stream) 6. ( ) (URL) , , Java , , 7. 16-2 Java java.io , 4 , 4 byte , (Byte Streams) char , (Character Streams) 8. 16-2-1 8 byte , InputStream ( ) OutputStream ( ) , System.out, java.io.PrintStream , FilterOutputStream , FilterOutputStream OutputStream , 9. 10. 11. , ByteArrayInputStream FileOutputStream ObjectIntputStream ObjectOutputStream, , 164 12. / , "throws IOException", , try/catch , "throws IOException" , 13. 16-2-2 16 char , Reader Writer, InputStream OutputStream , 16 Unicode , 8 ASCII Unicode , 14. , , Reader Writer 15. 16. 17. java.io , , Java 6.0 console ( ) , I/O , File , Stream , Reader Writer 18. 16-3 16-3-1 16-3-2 16-3-3 16-3-4 16-3-5 (Console) 16-3-6 19. 16-3-1 , , , , 20. System , PrintStream out , , , , "dir > test" , dir "test" ( Unix/Linux , "ls > test") 21. err , , err out , out , err , "dir ABC > test" , ABC , dir " " , test 22. PrintStream Java print() println() ( ), , Java , PrintStream write() , , "A" , ASCII 65, "write(65);" 23. write() , PrintStream Java 5.0 , printf() format() , , 16-3-4 , PrintWriter 24. PrintStream , IOException 25. 26. 1. 8 12 print() write() a[] print() , write() , , ASCII , ASCII 27. a[0] , ASCII 10 , ASCII 20 , a[1] a[4] 160 127 ( a ), Big-5 , , "chcp 437" , a 28. 2. 14 err write() b ASCII 7 BEL , , , ASCII 32 , , 29. System.out System.err , , 30. , , System.in , BufferedReader , 31. System.in InputStream , , , , ( Unicode , ) , , System.in , InputStream read() 32. , IOException , System.in 33. 34. 35. 36. 1. 9 18 read() 2. 10 Character.toString() ( 17 ) 3. 13 22 Math.pow() ( 17 ) 2 N 37. , 1 read() 1 , 2 InputStream read() [Enter] 1 , 2 , read() "2" ASCII , 50, , 38. 2 , , 2 [Enter] (Carriage Return) (Line Feed) ( 13 10), 2 , read() , , 19 39. 2 , 1 , 2 read() '5', 2 5 [Enter] , , , System.in, 40. System.in , System.in , (wrap) System.in , , , System.in 41. System.in , System.in InputStreamReader , BufferedReader , readLine() 42. System.in , InputStreamReader , , InputStreamReader , InputStreamReader [Enter] , , BufferedReader 43. System.in BufferedReader , , , , [Enter] BufferedReader Reader , System.in InputStreamReader , BufferedReader , 44. System.in BufferedReader readLine() , , , [Enter] 45. System.in 46. System.in 47. System.in 1. 09 InputStreamReader System.in 2. 14 while , ( 10) 3. 18 19 for 4. 24 BufferedReader 09 InputStreamReader 48. System.in BufferedReader read() 49. 16-3-2 System.in System.out , , , , , 50. , FileReader/FileWriter , , , , , FileReader FileReader InputStreamReader , read() FileReader 51. 52. 53. 54. 1. 13 ( ) , 14 FileReader fr 2. 18 19 while fr.read() , , read() -1, 3. 21 close() FileWriter OutputStreamWriter , , , , 55. File Reader , OutputStreamWriter write() 56. 3 write() , , FileReader , , , 57. 58. 59. 60. 61. 1. 14 , , FileWrite ( false), new FileWrite (filename, true) 2. 18 23 28 write() 62. 3. 19 24 write() , [Enter] 3 , , 4. 30 flush() , 31 close() 5. 33 37 FileReader , , 63. , FileReader/FileWriter , write() , (binary file, ), , System.in , , 64. , BufferedReader FileReader , readLine() , BufferedWriter FileWriter , BufferedWriter FileWriter , newLine() 65. , , , , ( ), , 66. BufferedWriter , flush() , 67. 68. 69. 70. 71. 1. 14 15 FileWriter , BufferedWriter , , , 2. 22 28 BufferedWriter write() 72. 3. 33 / "Y", , 4. 35 36 , 5. 43 47 BufferedReader , 45 46 while BufferedReader readLine() , null , 73. BufferedReader readLine() , , Reader read() BufferedReader BufferedWriter FileReader Fi leWriter SCJP , 74. 16-3-3 , (binary file) Java , 4 Java , "123456", Java , , , , , 75. "123456" , , 4 "00 01 E2 40" , , ( ) , , 76. , , , FileInputStream FileOutputStream , , DataInputStream DataOutputStream , , java.io DataInput DataOutput 77. DataOutputStream DataOutput , DataOutputStream , Java , DataOutputStream 78. DataOutputStream 79. DataOutputStream 80. DataOutputStream 81. DataOutputStream 82. DataOutputStream1. 1 4 1 7 , DataOutputStream 2. 30 DataOutputStream size() , "dir" 3. 31 32 83. DataOutputStream , , , , , , "1Aj? 0Agg?" 84. DataInputStream , DataInputStream DataInputStream DataInput , , DataInputStream , , writeXXX() readXXX() , 85. DataInputStream 86. DataInputStream DataInputStream 87. DataInputStream 88. DataInputStream 89. DataInputStream 1. 14 17 , DataIuput Stream 2. 21 29 try 3. 22 25 while() , 23 24 DataInputStream readInt() readDouble() 90. DataInputStream 4. 27 DataInputStream skipBytes() 12 , , 5. 30 catch EOFException , 31 EOFException IOException , (End Of File, EOF) 91. Java , C/C++ (unsigned) 16 short , "unsigned short" , 0 65535 , Java short , -32768 32767 92. Java C/C++ , DataInputStream DataOutputStream , 93. 16-3-4 , , , Java SE 5.0 PrintStream , , printf() 1 , , , PrintWriter 94. ( ) , , , print() Format Specifier ( ), printf() format() , Format Specifier, Format Specifier , 95. , " %d %.1f " , "%d" "%.1f" Format Specifier, printf() , Format Specifier , 96. "%d" , " %d " 1 1 , " 1 " Format Specifier % , , , 97. 98. 1$ 2$.. . , printf("%3$d,%2$d",1,2,3) "3,2" ( 3 , 2 ) 99. , , , 100. 101. 1. 23 25 printf() format() , , 2. 23 "%9.0f" 9 , 9 , 9 , 102. 3. 25 "%15.12f" 15 12 , , , 2 (152-1) 4. , printf() format() , 25 , 'n' String format() , , String 103. 16-3-5 (Console ) (Console) java.io.Console java 6 , , System.in , Console , (catch throws) IOException 104. (Console ) 105. (Console ) , readLine() readPassword() , readPassword() , , [Enter] ( ), ( ), 106. (Console ) , , new , System.console() , , System.console() null, 107. (Console ) 108. (Console ) 109. 16-3-6 java.io File , / , File 110. 111. File , a.txt , my , a.txt myb.txt ( ), , 112. 113. 1. 7 16 ( ) File , ( ) 18 File , 114. 2. 12 22 , File PirntWriter BufferedReader, 3. 19 rename , File , Fil e , ( ) 115. , , 116. 117. 118. 119. 120. 1. 5 go() , , , 38 2. 22 dir, name ( ) File , switch 121. 3. 23~55 switch , , go() , 4. File ( 38 f), toString() 122. 16-4 (Serialization) Java , , , Java ObjectOutputStream ObjectInputStream , readObject() writeObject() ( ) , , (Serialization) , , 123. Serializable , java.io Serializable , ObjectXXX , Serializable , "implements Serializable" , 124. Serializable , ObjectOutputStream , ObjectInputStream , , , , , ClassNotFoundException ( ) 125. Account , "implements Serializable" 126. 127. Serializable , ObjectOutputStream , Account , ObjectOutputStream , Account 128. 129. 130. 1. 16 17 FileOutputStream ObjectOutputStream , AccountFile 2. 19 ObjectOutputStream writeObject() 3. 20 21 131. "Account File", , ObjectOutputStream , , ObjectInputStream ObjectOutputStream writeObject() , DataInputStream writeXXX() , 132. , ObjectInputStream readObject() , readObject() IOException ClassNotFoundException Checked , readObject() , 133. 134. 135. 1. 6 main() ClassNotFoundException 2. 9 10 FileInputStream ObjectInputStream 136. 2. 11 ObjectInputStream readObject() , try/catch readObject() , , , try readObject() , catch EOFException 3. 12 4. 17 38 137. , , , , , (Deserialize) , 138. , , Serializable , , java.io.NotSerializableException , transient , 139. transient , , , 3 bk , null, java.io.NullPointerException , private 140. 141. catch throws 142. , defaultxxxObject() , transient , defaultxxxObject(), , transient 143. , Serializable , , , ( ), , , , Object 144. 16-A 16-B 145. 1. Place the codes into the empty box in order to write "Java!" to the end of a.txt rather than the beginning. 146. 2. Which statements concerning Serialization are true? (Choose all that apply.) A. The field with static modifier will not serialized. B. The field with volatile modifier will not serialized. C. The field with transient modifier will not serialized. D. An serialized object can be deserialized on a different JVM. E. An serializable object can be serialized even if it's superclass doesn't implements java.io.Serializable. F. An object array can not be serialized. 147. , getName() setName() "T" , main() "main" Thread.currentThread() 148. 3. Given: 149. What is the result? A. Only an instance of Box object is serialized. B. An instance of Box and An instance of Book are serialized. C. Compilation fails. D. An java.io.NotSerializableException: Box is thrown. E. An java.io.IOException: Box is thrown. 150. 4. Given: 151. What is the result? A. Deser:288 B. Deser:388 C. Deser:888 D. Compilation fails. E. An exception is throws at runtime. 152. 5. Which method exists only in one of the BufferedWriter and FileWriter classes. A. open(); B. close(); C. write(); D. toString(); E. newLine(); F. flush(); 153. 6. Which Place the correct Words into the following empty boxes: 154. 7. Please drag and drop the appropriate codes into the empty boxes : 155. 8. Given: 156. Which code, inserted at line 10, will allow Point to serialized and deserialized correctly. A. is.defaultReadObject(); B. x = is.readInt(); y = is.readInt(); C. y = is.readInt(); x = is.readInt(); D. is.defaultReadObject(); x = is.readInt(); y = is.readInt(); E. y = is.readInt(); x = is.readInt(); is.defaultReadObject(); 157. 9. Given: