You are on page 1of 14

-1-

ก
 JAVA  : 2549-10-30
http://www.thaiall.com/class http://www.thaiall.com/jsp http://www.thaiabc.com
(Java)  ก  !"# $% $"&'()%&* (Sun Microsystems Inc.) ':;&<=!'> :?ก%=@A %>
BกC&!&Dก'> :?ก%'E"A(D (OOP : Object-Oriented Programming) #>@E' :?ก%(MA N ก&OA P class :?ก%'=BMก'> ก
M method =  behavior  :ก("'> ก?(MB class M object  ?(MB object %>S("ก%%ก% :?ก%#>@&%!C*'ก"ก=B object = =B
class %%ก  ?(MB class %> method =  behavior ?(ก(MAก:
? J2SE : Java 2 Platform, Standard Edition (Core/Desktop)
? J2EE : Java 2 Platform, Enterprise Edition (Enterprise/Server)
? J2ME : Java 2 Platform, Micro Edition (Mobile/Wireless)
ก_A OOP (Object Oriented Programming)  B ' *(Alan Kay) ':; bO!Dก '!" ก? % " ก'> :?ก%'E"A(D =@ A ?B%> &M 
   Small talk O'&กc 5 O A OOP OA> 1. #D ก&"@ A':;  (D (Everything is an object) 2. :?ก% กBDM %A(D #>@ &MAM&!กก  ?Bก  P=O
#< A (A program is a bunch(A) of objects telling each other what to do by sending messages) 3. ?(MB(D(OA%> =M  %< ?B:ก!O 
(D @ (Each object has its own memory made up of other objects) 4. (D(OA MP:'#P:'#=@A (Every object has a type) 5. (D:'#
'> ก M%O!M&'=% ก (All objects of a particular type can receive the same messages)
ก'> :?ก%'E"A(D (Object-Oriented Programming : OOP)  ก'> :?ก%#>@:ก!O กBDM%A(D(Objects) ?(MB(D
':;กBDM%P:A Class $@A?(MB Class %> DC&%!(" ก:ก:hA (Encapsulation) ก& !# (Inheritance) กOA: (Polymorphism) =  ก'> ก
'ก"ก<BA (Overloading)   M Class  (O?!!A(D
-./ก0.12 OOP 1. ก:ก:hA (Encapsulation) ก:ก:hAO%B (Object combine data and operations) = %ก"ก% ?B B'> 
OP#>@ N O!ก:ก:hA'> ก 2. ก& !# (Inheritance) : &%& !&กDBO (Class can inherit properties from other classes) &%PEO DC&%!("#>@
!!DD&OAO 3. กOA: (Polymorphism) %กก>ก =% A many shapes : 'B ก:_"!("?(ก(MAO %&%'"%A&กDB'"%O &กDB
P=%M (Object can determine appropriate operation at execution time) : 'EM  &กD B point %> ก"  ก% show, clear '% @  &O  A&กD B circle ก) & %PEO ก"  ก%
show, clear A point O>ก 4. ก'> ก'ก"ก<BA (Overloading) : :?ก%'> ก#<AO?(ก(MAกP&กDB'> ก = '% @&MA M parameter #>@?(ก(MA
ก ก<=ก"ก%P=%MP:?ก%E @'"%O
ก:?ก%?!!%> A&OA =  ก:?ก% A&OA (Structure Programming) 
b%(! MA& N M#Dก(OA%>=Bกก 3  MA>  ก#<A?!!(%B<!(Sequence) ก'B กก#<(%'A @(Decision) ?B ก
#<$<(Loop) ?%O(<=B N 'BM%!กM decision ? ก':; if ก! case =  loop  A? ก':; while ?B until $@A?(ก(MAก ?(Mb%ก) A!Mก'> 
:?ก% ?!!%> A&OA %AP=Oก? M 3  MAก)?BO ?B=B #M'> Ab%M!A%M<':;(OAPEO Structure Programming ?(M'#M#>@b%lก
% A%M%>P 'B"กPEO=Bกก#A 3 > MA&"'E"A 'EM MS Access #>@=B !กMAM $@Aก)AM "A Olก' @&@AP=O#<A(% wizard = 
(%#>@'ก?!!%P=OPEO ?(MO<%PEOA"A (% %(OAกAbOPEO?BO (OAPEO:&!กC*Pก'>  Structure Programming ' @&OA Module
&<=! ! D% Object #A=%P=O#<A:&ก 1. ก#<A?!!(%B<!(Sequence) : :?!!ก'> :?ก%#>@AM #>@&D  '> P=O#<Aก!BA
BMA '>  <&@A':;!# ?B#<#>B!#ก!#!&DBA:A!#BMA&D &%%("P=O%>ก#<A 3 ก!ก  MO%B <C ?B"%* 
'> ':;bAA(Flowchart) P?!!(%B<!O(% 2. ก'B กก#<(%'A @(Decision) : ก(&"P = 'B ก'A @  '> :?ก%' @< M
:'B กก#<  :ก("%>'=(DกC*P=O#< 2 ก!ก 'A @':;"Aก#<ก!ก=@A ?B':;'#)ก#<>กก!ก=@A ?(MO$!$O
%ก (OAPEO'A @=B E 'EMก('กกlก ':;(O ( MAbAA> ?&AbBก'B ก MAAM ' @ก#<ก!ก'> Aก!ก'> 
3. ก#<$<(Repeation or Loop) : ก#<ก!ก=@A=B A  %>'A @Pก ! D% =% Aก#<$<':;=Bกก#>@#< %'OPO กกM 2 :
?!!?ก 'ก'> :?ก%?(MB %M?&A MAE''=% ก'> bAA(Flowchart) bO'> :?ก%(OA"(ก A:?!!ก
#<A ?BPEO <&@A ! D%O ('A ( MAbAA#>@<%?&A>':;ก?&A <&@A#<$<(do while) $@A=% Aก#<$<PC#>@':;"A ?B'B"กก#<$<
'% @'A @':;'#)
'"@%(O'> :?ก%#< MA (ก=A&   p')!%&'(*!##>@ 17)
1. 'B ก &<=!ก'>  กlกAM #>@'B ก ' *  E>?
2. =?=BMAO%BOA"Aก=OA&%D O#M%M%> MP% 'B Aก A&OA%Mก':;?M
3. =(?:B #Dก(OA%>(?:B %>=B #>@ก&OA':; Free compiler (OA=
4. '> :?ก%(?ก#>@AM 'EM "%*'B 5 ':;(O
5. lกก#<$< ?Bก'B ก(%'A @ 'EM"%*&( C = "%* 1 A 10 ':;(O
6. ("(M?th%O%B ' @M%?&AbB = :!:DAO%BO
7. '> '% ' @'B กก#<:?ก%(%('B ก
8. #< Aกก'E @%?th%=B ?th%  ก<=O=B ('B ก
9. '> :?ก%'"@%O%B 'EM $   %  = :?ก%BA#'!> กlก?(MB '> ':;(O
10. &OA:?ก%%!!=@AP=O&%!C* ( %&%!C*ก) ก&A#Dก %(OAกAbOPEO)
-2-
=O O&! Sun Certified Programmer for the Java 2 Platform 1.4 (http://www.sun.com/training/certification/faq/)
1. Declarations and Access Control 2. Flow Control, Assertions and Exception Handling
3. Garbage Collection 4. Language Fundamentals
5. Operators and Assignments 6. Overloading, Overriding, Runtime Type and Object Orientation
7. Threads 8. Fundamental Classes in the java.lang package
9. The Collections Framework
49 JAVA Keywords : http://www.thaiall.com/class/indexsign.htm
abstract assert boolean break byte case catch char class const continue default do
double else extends final finally float for goto if implements import instanceof int
interface long native new package private protected public return short static strictfp
super switch synchronized this throw throws transient try void volatile while
BกC#>@ Object =@A N (OA%>
Object Model General, UML OOP Coding in Java
State Value of Attribute Value of Variable Value of Variable/Attribute
Behavior Behavior/Action Method Method
Identity Attribute Property Variable/Attribute
ก!%'ก>@ ก! Java P:'#l#
1. =Bก&( |JAVA Professional Developer} http://maxlearn.eng.ku.ac.th/online_training/java/
< 282 E@ %A:ก!O ' = 2 &M  ' ==BกA Java Programming ?B&MA Software Engineer ' @
ก:?ก%&%#<A':;#>%M%ก!ก"' =*?Bกก?!!O #A >#A Aก?!MA=Bก&(ก':; 2 EMA' @P=O
'=%ก!?(MB!AbO'> A> 1.1 ED"E JAVA web pro 35,000 !# 1.2 ED"E Advance Java 45,000 !#
2. Sun Java Programming Language (SL 275) http://www.sun.com/training/catalog/courses/SL-275.xml
'> #A=% 15 Module Duration: 5 Days Price: $2,000 (:%C 80,000 !#)
3.  Aก "* http://www.javapiwat.org/html/course.html
bO#>@'O!%?B&!bM Certified Java Programmer &%&% !'A"  15,000 !#ก SIPA 30 E@%A 15,000 !#
-3-
ก
method  
 1 : ก constructor $%& ' object *+,'
class hello1 {
public static void main(String args[]) {
TAirPlane abc = new TAirPlane();
}
}
 2 : กก'& ' $%ก'ก
กA'กกB CD,E$ก'F''G, 1
class hello2 {
public static void main(String args[]) {
TAirPlane abc;
abc = new TAirPlane();
}
}
 3 : ก constructor A'ก .class G object  directory KLAAMB
class hello3 {
public static void main(String args[]) {
new TAirPlane();
}
}
 4 : ก method O ก constructor ,'D  A%กPQ'% method R,ORD
:: , R,O* constructor กSR,O,KT L G' A%* ',RKF' method O'UVก 
class hello4 {
public static void main(String args[]) {
new TAirPlane().Fly();
}
}
 5 : ,& ' object *+,' กSก
method  CDR,O ก constructor
class hello5 {
public static void main(String args[]) {
TAirPlane abc = new TAirPlane();
abc.Fly();
abc.Land();
}
}
class hello51 {
public static void main(String args[]) {
TAirPlane abc = new TAirPlane();
String a[] = {}; // new String[0];
abc.main(a);
}
}
 6 : ก
method ]'  object DกB
class hello6 {
public static void main(String args[]) {
minihello();
}
public static void minihello() {
System.out.println("result of mini hello");
}
}
 7 : ก
method ]'  object DกB CD method &','UB $%&ORD
:: ก method  static B method UVกก Ka static D 
class hello7 {
public static void main(String args[]) {
System.out.println(oho(5));
}
public static int oho(int x) {
x = x * 2;
return x;
}
}
 8 :
extends Kaก'&D* ','
:: Constructor A%R,OUVกก,'F''
class hello8 extends TAirPlane {
public static void main(String args[]) {
Fly();
Land();
}
}
 9 : ก method R,O กF'GD Static
:: E$$BQgh 8
class hello9 {
int a;
public static void main(String args[]) {
hello9 xx = new hello9();
System.out.println(xx.oho(4));
}
int oho(int x) {
x = x * 2;
return x;
}
}
-4-
SOURCE CODE of thaiall.com/class 74. z = "1234.1";
1. // ::: CKก,$F'DB 1 (2549-10-17) 75. int m = Integer.parseInt(z.substring(0,3)) + 5; // 123 + 5
2. // 1. K%,$E$ 
O javac j0100.java 76. double n = Double.parseDouble(z) + 0.2; // 1234.3
3. // 2. K%,$E$ 
O java j0100 abc def 77. System.out.println(m + n); // 128 + 1234.3 = 1362.3
4. // 3. &','UB parameter ,'K%,$E$ CKก,RD 78. System.out.println(Integer.toString(m) + 5); // 1285
5. // 4. E$RD A%GS$* 2 Q'%B* ,V$* 'RK 2 hO' 79. }
6. // 5. http://www.yonok.ac.th/burin/langspec20/ 80. }
7. class j0100 { 81. // ::: CKก,$F'DB 4
8. public static void main(String args[]) { 82. // 1. &Dก'
hF'&B if
9. System.out.println(args.length); 83. // 2. h',กO'* print $% println
10. System.out.println(args[0]); // abc 84. // 3. ก'
{ } GR,O
O'กBO'R
11. } 85. class j0201 {
12. } 86. public static void main(String args[]) {
13. // ::: CKก,$F'DB 2 87. int x;
14. // 1. กF'GD Primitive data type 5  8 88. x = 6;
15. // 2. &DE$A'กhO'กF'GD*+,' 89. if (x > 5) System.out.println("more than 5:" + x);
16. class j0101 { 90. if (x > 10) {
17. public static void main(String args[]) { 91. System.out.print("more than 10:");
18. // 1. boolean true of false 92. System.out.println(x);
19. boolean b = true; 93. }
20. System.out.println("boolean = "+b); 94. }
21. // 2. character 95. }
22. char y; 96. // ::: CKก,$F'DB 5
23. y = 'a'; 97. // 1. &Dก'
hF'&B if .. else ..
24. System.out.println("character = "+y); 98. // 2. h',AF'Ka , {} GR,O,
25. // 3. byte -2^7 to 2^7-1 1byte 99. // 3. U 'hDK String  
.equal
26. byte c; 100. // 4. BKK%] Comparable ,* AF'กBD ก'
,'ก
27. c = 127; 101. import java.lang.*;
28. System.out.println("byte = "+c); 102. class j0202 {
29. // 4. short -2^15 to 2^15-1 2byte 103. public static void main(String args[]) {
30. short a; 104. int x;
31. a = 32767; 105. x = 6;
32. System.out.println("Short = "+a); 106. if (x > 5) {
33. // 5. integer -2^31 to 2^31-1 4byte 107. System.out.println("more than 5");
34. int x; 108. } else {
35. x = 2147483647; 109. System.out.println("less than or equal 5");
36. System.out.println("Integer = "+x); 110. }
37. } 111. // another method of else and if
38. } 112. if (x > 10)
39. // ::: CKก,$F'DB 3 113. System.out.println("more than 10");
40. // 1. กF'GD Primitive data type 3  8 114. else {
41. // 2. &DE$A'กhO'กF'GD*+ $%ก'
function 115. System.out.println("less than or equal 10");
42. // 3. K%ก't $%
'gg 116. }
43. class j0102 { 117. Comparable a[] = new Comparable[5];
44. public static void main(String args[]) { 118. a[0] = new Integer(3);
45. // 6. long -2^63 to 2^63-1 8byte 119. a[1] = new Integer(10);
46. long b; 120. a[2] = "abc";
47. b = 9223372036854775807L; 121. System.out.println(a[0] + " " + a[1] + " " + a[2]);
48. System.out.println("long = "+b); 122. if (a[0].compareTo(a[1]) < 0) { System.out.println("more"); }
49. // 7. float -3.4e38 to 3.4e38 4byte 123. }
50. float d; 124. }
51. d = 340000000000000000000000000000000000000f; 125. // ::: CKก,$F'DB 6
52. System.out.println("float = "+d); 126. // 1. &Dก'
hF'&B switch .. case ..
53. // 8. double -1.7e308 to 1.7e308 8byte 127. // 2. hF'&B&F'hBT default $% break
54. double e; 128. // 3. value of switch = char, byte, short or int
55. e = 17900000000000000000000000000000000000000d; 129. class j0203 {
56. System.out.println("double = "+e); 130. public static void main(String args[]) {
57. // String aa = Double.toString(Double.parseDouble("123") + 1); 131. int a;
58. // String aa = Integer.toString(Integer.parseInt("456") + 2); 132. a = 1;
59. // aa = aa.substring(0,3); 133. switch (a) {
60. // String : Abstact data type 134. case 1:
61. // G String z = new String("ThaiAll"); 135. System.out.println("one");
62. String z ="ThaiAll"; 136. break;
63. System.out.println("string = "+z); 137. case 2:
64. System.out.println(z.substring(0,4)); // Thai 138. System.out.println("two");
65. System.out.println(z.substring(2,5)); // aiA 139. break;
66. System.out.println(z.substring(4)); // All 140. default:
67. System.out.println(z.toUpperCase()); // THAIALL 141. System.out.println("not found");
68. System.out.println(z.toLowerCase()); // thaiall 142. break;
69. char ar[] = new char[128]; 143. }
70. ar = z.toCharArray(); 144. }
71. System.out.println((char)ar[0]); // T 145. }
72. System.out.println(ar[0]); // T 146. // ::: CKก,$F'DB 7
73. System.out.println(ar[2] + ar[4]); // 162 (97 + 65) 147. // 1. &Dก'
hF'&B for
-5-
148. // 2. ก'K%ก't int  for 222. import java.io.*;
149. import java.lang.*; 223. class j0302 {
150. class j0204 { 224. public static void main(String args[]) throws IOException {
151. public static void main(String args[]) { 225. char buf1,buf2;
152. System.out.println("ASCII character :: "); 226. buf1 = (char)System.in.read();
153. for (int i=0; i<255; i++) { 227. buf2 = (char)System.in.read();
154. System.out.print((char)i + " "); 228. System.out.println("Output is "+buf1+buf2);
155. } 229. }
156. // 230. }
157. System.out.println("============="); 231. // ::: CKก,$F'DB 12
158. String s = "thaiall"; 232. // 1. &Dก'BhO'A'กK|Q,Qg character
159. System.out.println(s + " Length=" + s.length()); 233. // 2. BOกBRK ~ ABBBก} 0 * 'RKA+GMD
160. } 234. import java.io.*;
161. } 235. class j0303 {
162. // ::: CKก,$F'DB 8 236. public static void main(String args[]) throws IOException {
163. // 1. &Dก'
hF'&B while 
ShกOF' 237. System.out.println("Get until receive 0 [hidden is 13, 10]");
164. // 2. กF'GDhO',  1 G 0 238. char buf;
165. class j0205 { 239. do {
166. public static void main(String args[]) { 240. buf = (char)System.in.read();
167. System.out.println("print 1 to 10 :: "); 241. System.out.println("Output is "+buf);
168. int i; 242. } while (buf != '0');
169. i = 1; 243. }
170. while (i <= 10) { 244. }
171. try { 245. // ::: CKก,$F'DB 13
172. System.out.println(i); 246. // 1. BB$* 2 AF'$ F','กกB Q&DE$
173. i++; 247. // 2.
BufferedReader ก'B* ,V$
174. } 248. import java.io.*;
175. catch (ArithmeticException e) { 249. class j0304 {
176. System.out.println("may divide by zero"); 250. public static void main(String args[]) throws IOException {
177. } 251. BufferedReader stdin = new BufferedReader(new
178. } InputStreamReader(System.in));
179. int k = 0; 252. String buf;
180. i = 0; 253. int i1,i2,i3;
181. while (i < 5) { 254. buf = stdin.readLine();
182. System.out.print(++k); 255. i1 = Integer.parseInt(buf);
183. k = k + (i++); 256. buf = stdin.readLine();
184. System.out.print(k--); 257. i2 = Integer.parseInt(buf);
185. } // 11122447711 258. i3 = i1 + i2;
186. } 259. System.out.println("Output is "+i1+" + "+i2+" = "+i3);
187. } 260. }
188. // ::: CKก,$F'DB 9 261. }
189. // 1. &Dก'
hF'&B do .. while 262. // ::: CKก,$F'DB 14
190. // 2. AR* F'กO
Sh 263. // 1. BB$*RK ~ RK&DE$ Aก%BB$* 0
191. // 3.
try catch ABKLTG' array 264. // 2.
BufferedReader ก'B* ,V$
192. class j0206 { 265. import java.io.*;
193. public static void main(String args[]) { 266. class j0305 {
194. System.out.println("print 1 to 10 :: "); 267. public static void main(String args[]) throws IOException {
195. int i; 268. BufferedReader stdin = new BufferedReader(new
196. i = 1; InputStreamReader(System.in));
197. try { 269. String buf;
198. do { 270. int i;
199. System.out.println(i); 271. System.out.println("Get until receive 0");
200. i++; 272. do {
201. } while (i <= 10); 273. buf = stdin.readLine();
202. } 274. i = Integer.parseInt(buf);
203. catch (ArrayIndexOutOfBoundsException e) { 275. System.out.println("Output is "+i);
204. System.out.println("over index of array"); 276. } while (i != 0);
205. } 277. }
206. } 278. }
207. } 279. // ::: CKก,$F'DB 15
208. // ::: CKก,$F'DB 10 280. // 1. ก'*CKก,O $%ก

209. // 1. &Dก'BhO'A'กK|Q,Qg character 281. // 2. CKก,, 2 method $%กR,O&OhO'
210. // 2. B* ,V$RD Q 1 BBก} $%&DE$ 282. class j0401 {
211. import java.io.*; 283. public static void main(String args[]) {
212. class j0301 { 284. System.out.println("Result of main");
213. public static void main(String args[]) throws IOException { 285. sub();
214. char buf; 286. }
215. buf = (char)System.in.read(); 287. static void sub() {
216. System.out.println("Output is "+buf); 288. System.out.println("Result of sub");
217. } 289. }
218. } 290. }
219. // ::: CKก,$F'DB 11 291. // ::: CKก,$F'DB 16
220. // 1. &Dก'BhO'A'กK|Q,Qg character 292. // 1. ก'* method QBhO'RKK%,$E$
221. // 2. B 2 BBก},'&DE$OกB 293. // 2. ก'G'E$,CD
method
OhF'
-6-
294. // 3. method B 3 hO' $%h 1 hO' 368. import java.io.*;
295. class j0402 { 369. class j0601 {
296. public static void main(String args[]) { 370. public static void main (String args[]) throws IOException {
297. int s = 0; 371. File f = new File("j0601.java");
298. s = sub(2,8,s); 372. System.out.println("getName: "+f.getName());
299. s = sub(7,3,s); 373. System.out.println("getPath: "+f.getPath());
300. s = sub(4,6,s); 374. System.out.println("getParent: "+f.getParent());
301. System.out.println("Sum = "+s); 375. System.out.println("getAbsolutePath: "+f.getAbsolutePath());
302. } 376. System.out.println("isAbsolute: "+f.isAbsolute());
303. public static int sub(int x, int y, int z) { 377. System.out.println("exists: "+f.exists());
304. return (y + x + z); 378. System.out.println("isFile: "+f.isFile());
305. } 379. System.out.println("isDirectory: "+f.isDirectory());
306. } 380. System.out.println("canWrite: "+f.canWrite());
307. // ::: CKก,$F'DB 17 381. System.out.println("canRead: "+f.canRead());
308. // 1. ก'
method G'hO' 2 O' 382. System.out.println("length: "+f.length());
309. // 2. K%ก't method R,O, public กSRD 383. }
310. class j0403 { 384. }
311. public static void main(String args[]) { 385. // ::: CKก,$F'DB 22
312. int j = 3; 386. // 1. K%,$E$ 
O java j0602 c:\class
313. System.out.println("Double of "+doubleofnumber(j)); 387. // 2. ก'&D'
  ‚|,A'ก Directory กF'GD
314. } 388. import java.io.*;
315. static int doubleofnumber(int i) { 389. class j0602 {
316. i = i * 2; 390. public static void main (String args[]) {
317. return (i); 391. File d = new File(args[0]);
318. } 392. String n[] = d.list();
319. } 393. for (int i = 0; i<n.length; i++) {
320. // ::: CKก,$F'DB 18 394. File f = new File(args[0] + '/' + n[i]);
321. // 1. ก'& ' class G,O$%ก method  class B 395. System.out.println(i+" : "+n[i]+" Size="+f.length());
322. // 2. R,O,KLTG'$F'DBกOG$B* class ก'* class 396. }
323. // 3. CKก,, 2 class ~ $% 1 method 397. System.out.println("directory: "+d.getPath());
324. class sub01 { 398. }
325. void subx() { 399. }
326. System.out.println("Result of subx"); 400. // ::: CKก,$F'DB 23
327. } 401. // 1. ก'O'* ,V$A'ก j0603.java $%BBก} ,'&DE$
328. } 402. // 2.
FileInputStream
329. class j0404 { 403. import java.io.*;
330. public static void main(String args[]) { 404. class j0603 {
331. sub01 x = new sub01(); 405. public static void main (String args[]) throws IOException {
332. System.out.println("Result of main"); 406. int n = 0;
333. x.subx(); 407. byte b[] = new byte[128];
334. } 408. FileInputStream fin = new FileInputStream("j0603.java");
335. } 409. while ((n = fin.read(b)) != -1) {
336. // ::: CKก,$F'DB 19 410. for(int i=0;i<n;i++) System.out.print((char)b[i]);
337. // 1. K%ก't'g $%&D* ,V$ 'gB G,D 411. }
338. class j0501 { 412. fin.close();
339. public static void main(String args[]) { 413. }
340. int x[] = {4,18,12}; 414. }
341. System.out.println("Amount of array = " + x.length); 415. // ::: CKก,$F'DB 24
342. for (int i = 0; i < x.length; i++) { 416. // 1. ** ,V$$RK ‚|, tmp.txt
343. System.out.println("element "+i+" = "+x[i]); 417. // 2. create or replace file 256 byte in ascii character
344. } 418. import java.io.*;
345. } 419. class j0604 {
346. } 420. public static void main (String args[]) throws IOException {
347. // ::: CKก,$F'DB 20 421. int n = 0;
348. // 1. K%ก't'g 2 , $%&D* ,V$ 'g 422. byte b[] = new byte[128];
349. // 2. ก'$ก, ก'RK&DE$ 423. FileOutputStream fout = new FileOutputStream("tmp.txt");
350. class j0502 { 424. for(int i=0;i<256;i++) {
351. public static void main(String args[]) { 425. fout.write(i);
352. String a[][] = new String[2][3]; 426. }
353. a[0][0] = "101"; 427. fout.close();
354. a[0][1] = "102"; 428. }
355. a[0][2] = "103"; 429. }
356. int i = 0; 430. // ::: CKก,$F'DB 25
357. a[1][i++] = "tom"; // 1,0 431. // 1. ** ,V$ 10 BD$RK ‚|, tmp.txt
358. a[1][i++] = "dang"; // 1,1 432. // 2.
FileOutputStream
359. a[1][i++] = "boy"; // 1,2 433. import java.io.*;
360. for (i = 0; i < a[0].length; i++) { 434. class j0605 {
361. System.out.println("element of 0,"+i+" = "+a[0][i]); 435. public static void main (String args[]) throws IOException {
362. } 436. int n = 0;
363. for (i = 0; i < a[1].length; i++) { 437. FileOutputStream fout = new FileOutputStream("tmp.txt");
364. System.out.println("element of 1,"+i+" = "+a[1][i]); 438. for(int i=1;i<=10;i++) {
365. }}} 439. fout.write(i+47);
366. // ::: CKก,$F'DB 21 440. fout.write(13);
367. // 1. ก'&D'$%D*‚|, f0601.java 441. fout.write(10);
-7-
442. } 514. fields = b.split(patternStr);
443. fout.close(); 515. System.out.println(i);
444. } 516. System.out.println("ID = " + fields[0]);
445. } 517. System.out.println("Name = " + fields[1]);
446. // ::: CKก,$F'DB 26 518. System.out.println("Salary = " + fields[2]);
447. // 1. O'* ,V$A'ก‚|, tmp.txt ,'&DE$ 519. System.out.println("Status = " + fields[3]);
448. // 2.
FileReader 520. i = i + 1;
449. // 3. O'* ,V$,'&DBD$% 1 BBก} 521. }
450. import java.io.*; 522. fin.close();
451. class j0606 { 523. }
452. public static void main (String args[]) throws IOException { 524. }
453. int i = 0, n = 0; 525. // ::: CKก,$F'DB 30 (060122)
454. char b[] = new char[1]; 526. // 1. O'* ,V$A'ก data.txt *$ data.htm
455. FileReader fin = new FileReader("tmp.txt"); 527. // 2. F'* ,V$UVกกD  , *$ table O'Ka%
456. while ((n = fin.read(b)) != -1) { 528. // 3. DOS>explorer data.htm
457. System.out.println(i+" : "+b[0]); 529. // 3. Q, <input type=radio onclick={alert("a");}>
458. i = i + 1; 530. import java.io.*;
459. } 531. import java.lang.*;
460. fin.close(); 532. class j0702 {
461. } 533. public static void main (String args[]) throws IOException {
462. } 534. int i = 1;
463. // ::: CKก,$F'DB 27 535. String b;
464. // 1. O'* ,V$A'ก‚|, tmp.txt ,'&DE$$%BBก} 536. String[] fields;
465. // 2. O'* ,V$กS$'g $%F'A'ก'g,'&DE$ 537. String patternStr = ",";
466. // 3. O'* ,V$,'&DBD$% 16 BBก} 538. FileReader fin = new FileReader("data.txt");
467. import java.io.*; 539. BufferedReader bin = new BufferedReader (fin);
468. class j0607 { 540. // in j0605.java will use char. This program use String
469. public static void main (String args[]) throws IOException { 541. FileOutputStream fout = new FileOutputStream("data.htm");
470. int i = 1, n = 0; 542. BufferedOutputStream bout = new BufferedOutputStream(fout);
471. char b[] = new char[16]; 543. PrintStream pout = new PrintStream(bout);
472. FileReader fin = new FileReader("tmp.txt"); 544. pout.println("<body bgcolor=yellow><table border=1
473. while ((n = fin.read(b)) != -1) { width=100%>");
474. System.out.print((i-1)*16+" - "+(i*16-1)); 545. while ((b = bin.readLine()) != null) {
475. System.out.print(":"+b[0]+b[1]+b[2]+b[3]+b[4]+b[5]+b[6]+b[7]); 546. fields = b.split(patternStr);
476. System.out.println(":"+b[8]+b[9]+b[10]+b[11]+b[12]+b[13]+b[14]+b[1 547. pout.println("<tr>");
5]); 548. pout.println("<td>"+i+"</td>");
477. i = i + 1; 549. pout.println("<td>"+"ID = " + fields[0]+"</td>");
478. } 550. pout.println("<td>"+"Name = " + fields[1]+"</td>");
479. fin.close(); 551. pout.println("<td>"+"Salary = " + fields[2]+"</td>");
480. } 552. pout.println("<td>"+"Status = " + fields[3]+"</td>");
481. } 553. pout.println("</tr>");
482. // ::: CKก,$F'DB 28 554. i = i + 1;
483. // 1. O'* ,V$A'ก‚|, data.txt ,'&DE$ 555. }
484. // 2.
ก'O'* ,V$ readlin $% String 556. pout.println("</table></body>");
485. import java.io.*; 557. System.out.println("DOS> explorer data.htm");
486. class j0608 { 558. fin.close();
487. public static void main (String args[]) throws IOException { 559. pout.close();
488. int i = 1; 560. }
489. String b; 561. }
490. FileReader fin = new FileReader("data.txt"); 562. // ::: CKก,$F'DB 31
491. BufferedReader bin = new BufferedReader (fin); 563. // 1. O'* ,V$กS$'g $ F'RK*$‚|, data.htm
492. while ((b = bin.readLine()) != null) { 564. // 2. Q,hO' G field DA'กD,ก 100 '
493. System.out.println(i + " : " +b); 565. import java.io.*;
494. i = i + 1; 566. class j0703 {
495. } 567. public static void main (String args[]) throws IOException {
496. fin.close(); 568. int i = 0,d;
497. } 569. String b;
498. } 570. String[] fields;
571. String[] recs = {"","",""};
499. // ::: CKก,$F'DB 29 (060122) 572. String patternStr = ",";
500. // 1. O'* ,V$A'ก‚|, data.txt  csv ,'&DE$ 573. //
501. // 
O 101,tom,2000,single 574. FileReader fin = new FileReader("data.txt");
502. // 
O 102,somchai,5000,married 575. BufferedReader bin = new BufferedReader (fin);
503. // 2. hF'&B split ก field D  patternStr 576. //
504. import java.io.*; 577. while ((b = bin.readLine()) != null) {
505. class j0701 { 578. recs[i] = b;
506. public static void main (String args[]) throws IOException { 579. i = i + 1;
507. int i = 1; 580. }
508. String b; 581. fin.close();
509. String[] fields; 582. //
510. String patternStr = ","; 583. FileOutputStream fout = new FileOutputStream("data.htm");
511. FileReader fin = new FileReader("data.txt"); 584. BufferedOutputStream bout = new BufferedOutputStream(fout);
512. BufferedReader bin = new BufferedReader (fin); 585. PrintStream pout = new PrintStream(bout);
513. while ((b = bin.readLine()) != null) { 586. for(int j=0;j<i;j++) {
-8-
587. fields = recs[j].split(patternStr); 661. if (found == 0) { System.out.println("Not found"); }
588. pout.print(fields[0]+","+fields[1]+","); 662. fin.close();
589. // pout.print(Double.valueOf(fields[2]).doubleValue()); 663. }
590. d = Integer.valueOf(fields[2]).intValue() + 100; 664. }
591. pout.print(d); 665. // ::: CKก,$F'DB 34
592. pout.println(","+fields[3]); 666. // 1. O'‚|, data.txt $% status array ,'
 ,กB
593. } 667. // 2. CD,‚|,* ,V$ $%‚|,&U'%]'Q
594. pout.close(); 668. // 2.1 data.txt : GB&,
,&กM$,&U']'Q
595. } 669. // 31001,tom,dang,A
596. } 670. // 31002,boy,spy,R
597. // ::: CKก,$F'DB 32 671. // 31003,big,chem,A
598. // 1. BhO'A'กK|Q,QgD  System.in.read 672. // 31004,burin,bio,R
599. // 2. F'RK$ก* ,V$ ‚|, data.txt $ &D% 673. // 31005,red,sex,R
600. // 3. h G'D  .equals() 674. // 2.2 status array : &U']'Q,hF''&U']'Q
601. import java.io.*; 675. // A,Active
602. class j0801 { 676. // R,Retire
603. public static void main (String args[]) throws IOException { 677. import java.io.*;
604. int found=0; 678. class j0901 {
605. char buf; 679. public static void main (String args[]) throws IOException {
606. String b,g = ""; 680. int i = 0,d,t1,t2;
607. String[] fields; 681. String b,status;
608. String patternStr = ","; 682. // same as String[] fields;
609. // 683. String fields[];
610. System.out.println("Wait id and end character with [x]"); 684. String[] recs1 = new String[10];
611. buf = (char)System.in.read(); 685. String[] recs2 = {"A,Active","R,Retire"};
612. do { 686. String patternStr = ",";
613. g = g + buf; 687. //
614. buf = (char)System.in.read(); 688. FileReader fin = new FileReader("data.txt");
615. } while (buf != 'x'); 689. BufferedReader bin = new BufferedReader (fin);
616. // gi = Integer.valueOf(g).intValue(); 690. while ((b = bin.readLine()) != null) {
617. // 691. recs1[i] = b;
618. FileReader fin = new FileReader("data.txt"); 692. i = i + 1;
619. BufferedReader bin = new BufferedReader (fin); 693. }
620. // 694. fin.close();
621. while ((b = bin.readLine()) != null) { 695. t1 = i;
622. fields = b.split(patternStr); 696. t2 = recs2.length;
623. if (fields[0].equals(g)) { 697. //
624. System.out.println(fields[1]); 698. for(int j=0;j<t1;j++) {
625. found = 1; 699. fields = recs1[j].split(patternStr);
626. } 700. System.out.print(fields[0] + fields[1] + fields[2]+fields[3]);
627. } 701. status = fields[3];
628. if (found == 0) { System.out.println("Not found"); } 702. for(int k=0;k<t2;k++) {
629. fin.close(); 703. fields = recs2[k].split(patternStr);
630. } 704. if (fields[0].equals(status)) {
631. } 705. System.out.println(fields[1]);
632. // ::: CKก,$F'DB 33 706. }
633. // 1. BhO'A'ก‚|,Q,Qg$ h G' ‚|, data.txt 707. }
634. // 2. h G'D  split U 'QE$* split A%RD ,'กกO' 1 708. }
635. import java.io.*; 709. }
636. class j0802 { 710. }
637. public static void main (String args[]) throws IOException { 711. // ::: CKก,$F'DB 35
638. int found=0; 712. // 1. O'‚|, data.txt $% datas.txt ,'
,กB
639. char buf; 713. // 2. CD,‚|,* ,V$ $%‚|,&U'%]'Q (AF'กBD 6 %)
640. String b,g = ""; 714. // 2.1 data.txt : GB&,
,&กM$,&U']'Q
641. String[] fields; 715. // 2.2 datas.txt : &U']'Q,hF''&U']'Q
642. // 716. import java.io.*;
643. System.out.println("Wait string and end character with [x]"); 717. class j0902 {
644. buf = (char)System.in.read(); 718. public static void main (String args[]) throws IOException {
645. do { 719. int i = 0,d,t1,t2;
646. g = g + buf; 720. String b,status;
647. buf = (char)System.in.read(); 721. String[] fields;
648. } while (buf != 'x'); 722. String[] recs1 = {"","","","","",""};
649. String patternStr = g,patternComma = ","; 723. String[] recs2 = {"","","","","",""};
650. FileReader fin = new FileReader("data.txt"); 724. // String[] recs2 = new String[10]; &','UBRD 10 %
651. BufferedReader bin = new BufferedReader (fin); 725. String patternStr = ",";
652. // 726. FileReader fin = new FileReader("data.txt");
653. while ((b = bin.readLine()) != null) { 727. BufferedReader bin = new BufferedReader (fin);
654. fields = b.split(patternStr); 728. while ((b = bin.readLine()) != null) {
655. if (fields.length > 1) { 729. recs1[i] = b;
656. fields = b.split(patternComma); 730. i = i + 1;
657. System.out.println(fields[0] + fields[1] + fields[2] + fields[3]); 731. }
658. found = 1; 732. fin.close();
659. } 733. t1 = i;
660. } 734. i = 0;
-9-
735. // 809. g.drawString("test",10,20);
736. FileReader fin2 = new FileReader("datas.txt"); 810. }
737. BufferedReader bin2 = new BufferedReader (fin2); 811. }
738. while ((b = bin2.readLine()) != null) { 812. // ::: CKก,$F'DB 39
739. recs2[i] = b; 813. // 1. Q,QghF'O' 1 - 10  Applet
740. i = i + 1; 814. // 2. MกBGO'ˆ ' 10 pixels
741. } 815. import java.lang.*;
742. fin2.close(); 816. import java.applet.*;
743. t2 = i; 817. import java.awt.Graphics;
744. // 818. public class j1102 extends java.applet.Applet {
745. for(int j=0;j<t1;j++) { 819. private int i,j;
746. fields = recs1[j].split(patternStr); 820. private String istr;
747. System.out.print(fields[0] + fields[1] + fields[2]+fields[3]); 821. public void paint(Graphics g) {
748. status = fields[3]; 822. i = 1;
749. for(int k=0;k<t2;k++) { 823. while (i <= 10) {
750. fields = recs2[k].split(patternStr); 824. j = 10 * i;
751. if (fields[0].equals(status)) { 825. istr= Integer.toString(i);
752. System.out.println(fields[1]); 826. g.drawString(istr,10,j); // 10 = column
753. } 827. i++;
754. } 828. }
755. } 829. }
756. } 830. }
757. } 831. // ::: CKก,$F'DB 40
758. // ::: CKก,$F'DB 36 832. // 1. Q,Qg &   Applet
759. // 1. F''g,'K $%ABD bubble sort 833. // 2. AMDกGO'ˆ ' 5 $%GO' 10
760. // 2. * ,V$ 'gKaB$* 834. import java.lang.*;
761. // 3. ก'&$BhO' 
O t = a; a = b; b = t; 835. import java.applet.*;
762. class j1001 { 836. import java.awt.*;
763. public static void main (String args[]) { 837. public class j1103 extends java.applet.Applet {
764. int tmp,x[] = {5,6,1,2,9,12,9,3}; 838. public void init() {
765. for(int i=1;i<x.length;i++) { 839. setBackground(Color.yellow);
766. for(int j=x.length-1;j>=i;j--) { 840. }
767. if(x[j-1] > x[j]) { 841. public void paint(Graphics g) {
768. tmp = x[j]; 842. g.setColor(Color.black);
769. x[j] = x[j-1]; 843. g.drawLine(5,10,30,40);
770. x[j-1] = tmp; 844. }
771. }}} 845. }
772. for(int i=0;i<x.length;i++) { 846. // ::: CKก,$F'DB 41
773. System.out.println(x[i]); 847. // 1. Q,QgVKG$'  Applet
774. }}} 848. // 2. Rect = &G$, Oval =  Arc = & 
775. // ::: CKก,$F'DB 37 849. // 3. Oval ก ' 20 &V 30
776. // 1. F''g,'K $%ABD bubble sort 850. // 4. Arc ,AMD 0 h*'%' RK 120 t'
777. // 2. * ,V$ 'gKa String 851. import java.lang.*;
778. // 3. & ' function
O ก'O'* ,V$A'ก'g,'Q,Qg 852. import java.applet.*;
779. import java.lang.*; 853. import java.awt.*;
780. class j1002 { 854. public class j1104 extends java.applet.Applet {
781. public static void main (String args[]) { 855. public void init() {
782. String tmp,x[] = {"ac","abc","adb","a","aa","acd","a a","a d"}; 856. setBackground(Color.green);
783. System.out.println("Before sorting"); 857. }
784. prtlist(x); 858. public void paint(Graphics g) {
785. for(int i=1;i<x.length;i++) { 859. g.setColor(Color.black);
786. for(int j=x.length-1;j>=i;j--) { 860. g.drawLine(5,10,30,40);
787. if(x[j-1].compareTo(x[j])>0) { 861. g.drawRect(50,50,80,80);
788. tmp = x[j]; 862. g.drawOval(50,50,20,30);
789. x[j] = x[j-1]; 863. g.drawArc(40,30,55,55,0,120);
790. x[j-1] = tmp; 864. int[] x={0,80,100,5,10};
791. }}} 865. int[] y={0,50,80,80,30};
792. System.out.println("After sorting"); 866. g.drawPolygon(x,y,5);
793. prtlist(x); 867. }
794. } 868. }
795. public static void prtlist(String[] x) { 869. // ::: CKก,$F'DB 42
796. for(int i=0;i<x.length;i++) { 870. // 1. & 'KM‰, $%hF'  Applet
797. System.out.println(x[i]); 871. // 2.
Button, Label $% TextField
798. }}} 872. // 3. advance กO' G KŠDSRˆg thaiall.com/class
799. // ::: CKก,$F'DB 38 873. import java.lang.*;
800. // 1. Q,QghF'O' test  Applet 874. import java.applet.*;
801. // 2. GO'ˆ ' 10 pixels GO'A'ก 20 pixels 875. import java.awt.*;
802. // 3. K%,$E$CD appletviewer j1101.java 876. import java.awt.event.*;
803. // <applet code=j1101.class width=200 height=50></applet> 877. public class j1105 extends Applet implements ActionListener {
804. import java.lang.*; 878. Button b1 = new Button("1");
805. import java.applet.*; 879. Label l1 = new Label("Hello");
806. import java.awt.Graphics; 880. TextField t1 = new TextField("1");
807. public class j1101 extends java.applet.Applet { 881. public void init() {
808. public void paint(Graphics g) { 882. setBackground(Color.red);
-10-
883. add(l1); 954. System.out.println("ok");
884. add(b1); 955. }
885. add(t1); 956. }
886. t1.addActionListener(this); 957. System.out.println("See you again");
887. b1.addActionListener(this); 958. }
888. } 959. }
889. public void actionPerformed(ActionEvent e) { 960. // ::: CKก,$F'DB 45
890. int intb1 = Integer.parseInt(e.getActionCommand()); 961. // 1. ,V $%ก'BB$ก stdin.readLine
891. intb1 = intb1 + 1; 962. // 2.
if $กก%F' ก method
892. String s = Integer.toString(intb1); 963. import java.io.*;
893. l1.setText(s); 964. class j1203 {
894. b1.setLabel(s); 965. public static void main(String args[]) throws IOException {
895. t1.setText(s); 966. BufferedReader stdin = new BufferedReader(new
896. } InputStreamReader(System.in));
897. } 967. String buf=" ";
898. // ::: CKก,$F'DB 43 968. while (buf.equals("3")) {
899. // 1. ,V $%ก'BB$ก System.in.read 969. System.out.println("What is your option?");
900. // 2.
switch $กก%F' &F'GB 48 h 0, 49 h 1 970. System.out.println("1. print 1 to 10");
901. import java.io.*; 971. System.out.println("2. print 'ok'");
902. class j1201 { 972. System.out.println("3. exit");
903. public static void main(String args[]) throws IOException { 973. buf = stdin.readLine();
904. int buf=49; 974. if (buf.equals("1")) { oho1(); }
905. while (buf != 51) { 975. if (buf.equals("2")) { oho2(); }
906. if (buf >= 49 && buf <= 51) { 976. }
907. System.out.println("What is your option?"); 977. System.out.println("See you again");
908. System.out.println("1. print 1 to 10"); 978. }
909. System.out.println("2. print 'ok'"); 979. public void oho1() {
910. System.out.println("3. exit"); 980. for (int i=1;i<=10;i++) {
911. } 981. System.out.println(i);
912. // buf = (char)System.in.read(); (it have 13 and 10 on enter) 982. }
913. buf = System.in.read(); 983. }
914. switch (buf) { 984. public void oho2() {
915. case 49: // character 1 985. System.out.println("ok");
916. for (int i=1;i<=10;i++) { 986. }
917. System.out.println(i); 987. }
918. } 988. class pyramid01 {
919. break; 989. public static void main(String args[]) {
920. case 50: // character 2 990. int k = 4;
921. System.out.println("ok"); 991. for (int i=1;i<=k;i++) {
922. break; 992. for (int j=2;j<=i;j++) { System.out.print(" "); }
923. case 51: break; // character 3 993. System.out.print(i+""+i);
924. case 13: break; 994. for (int j=k;j>=(i+1);j--) { System.out.print("**"); }
925. case 10: break; 995. System.out.println(i+""+i);
926. default: 996. } } }
927. System.out.println("Nothing to do"); 997. class pyramid02 {
928. break; 998. public static void main(String args[]) {
929. } 999. int k = 4;
930. } 1000. for (int i=1;i<=k;i++) {
931. System.out.println("See you again"); 1001. for (int j=i;j<=(i+2);j++) { System.out.print(j); }
932. } 1002. for (int j=1;j<=(2+i);j++) { System.out.print("*"); }
933. } 1003. System.out.println();
934. // ::: CKก,$F'DB 44 1004. }}}
935. // 1. ,V $%ก'BB$ก stdin.readLine 1005. class pyramid03 {
936. // 2.
if $กก%F' VO  method DกB 1006. public static void main(String args[]) {
937. import java.io.*; 1007. int k = 4;
938. class j1202 { 1008. for (int i=1;i<=k;i++) {
939. public static void main(String args[]) throws IOException { 1009. System.out.print(i+""+(i+4));
940. BufferedReader stdin = new BufferedReader(new 1010. for (int j=1;j<=(4+i);j++) {
InputStreamReader(System.in)); 1011. System.out.print("*");
941. String buf=" "; 1012. }
942. while (buf.equals("3")) { 1013. System.out.println();
943. System.out.println("What is your option?"); 1014. }}}
944. System.out.println("1. print 1 to 10"); 1015. class pyramid04 {
945. System.out.println("2. print 'ok'"); 1016. public static void main(String args[]) {
946. System.out.println("3. exit"); 1017. int k = 4;
947. buf = stdin.readLine(); 1018. for (int i=1;i<=k;i++) {
948. if (buf.equals("1")) { 1019. for (int j=1;j<=i;j++) { System.out.print("*"); }
949. for (int i=1;i<=10;i++) { 1020. for (int j=i;j>=2;j--) { System.out.print(j); }
950. System.out.println(i); 1021. for (int j=1;j<=i;j++) { System.out.print(j); }
951. } 1022. System.out.println();
952. } 1023. }}}
953. if (buf.equals("2")) {
-11-
( M A:?ก%'%MO%B%?&AbB
1. // it will compile updtxt1.java and updtxt2.java automatic
2. // you can write updtxt1.java to be external file or write it in updtxt0.java
3. import java.io.*;
4. import java.lang.*;
5. class updtxt0 {
6. public static void main(String args[]) throws IOException {
7. updtxt1 sub1 = new updtxt1();
8. updtxt2 sub2 = new updtxt2();
9. String waitopt,buf;
10. String ar[] = {"updtxt1.java",""};
11. BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
12. System.out.println("1 : read data by read");
13. System.out.println("2 : read data by readln");
14. System.out.println("Wait your choice [0, 1, 2] : ");
15. buf = stdin.readLine();
16. while (!buf.equals("0")) {
17. if (buf.equals("0")) {
18. System.out.println("Bye Bye");
19. break; // stoping of while
20. } else if (buf.equals("1")) {
21. sub1.main(ar);
22. } else if (buf.equals("2") || buf.equals("l")) {
23. sub2.list("updtxt2.java");
24. }
25. System.out.println("Wait your choice [0, 1, 2] : ");
26. buf = stdin.readLine();
27. }
28. }
29. }
30. // new fIle updtxt1.java
31. import java.io.*;
32. class updtxt1 {
33. public static void main (String args[]) throws IOException {
34. int n = 0;
35. byte b[] = new byte[128];
36. FileInputStream fin = new FileInputStream(args[0]);
37. while ((n = fin.read(b)) != -1) {
38. for(int i=0;i<n;i++) System.out.print((char)b[i]);
39. }
40. fin.close();
41. }
42. }
43. // new fIle updtxt2.java
44. import java.io.*;
45. class updtxt2 {
46. public static void main (String args[]) throws IOException {
47. list("updtxt2.java");
48. }
49. public static void list (String f) throws IOException {
50. String b;
51. FileReader fin = new FileReader(f);
52. BufferedReader bin = new BufferedReader (fin);
53. while ((b = bin.readLine()) != null) System.out.println(b);
54. fin.close();
55. }
56. }
-12-
EFGกHIJH ก2 KEก
LMN
' @Aกกlก#>@b%& #<O&!กBA %MO '%MOPEO'B#>@!OŒกŒ ?%OP=Oก!O:#< ?(Mก) %MO:BA
'  @AP=O'ก" %E<Ž A(OAP=OA 60 :?ก%>P=%M ':;:?ก%#>@AM 'O A Bก>ก ก)%MbMก&!:ก':BM Pก
%Db"BM:?ก%#>@'> %b"DP
Group : 1 "%*O%B MAAM
1. :?ก% "%* =&กlก
2. :?ก% "%* E @ ('A
3. :?ก% "%* ('B ก(?:
4. :?ก% "%* E @ ?B&กDB B!#
5. :?ก% "%* =& E @ ?B&กDB B!#
6. :?ก% "%* bB!ก A'B 2 <
7. :?ก% "%* bB!ก B! C = A'B 2 <
Group : 2 !O%B% <C
8. :?ก%"%* ('B #>@!%ก?:h"%*
9. :?ก%"%* ก #>@!%ก?:h"%*
10. :?ก%"%* bB!ก A'B 2 < #>@!%ก?:h"%*
11. :?ก%"%* bB!ก ?BB! A'B 2 < #>@!%ก?:h"%*
12. :?ก%"%* bB C ?B= A'B 2 < #>@!%ก?:h"%*
13. :?ก%"%* bB!ก A'B 3 < #>@!%ก?:h"%*
Group : 3 !O%B ?B'B ก"%*
14. :?ก% !('Bก?:h"%* 2 < ?(M"%*(=BAกM(?ก
15. :?ก% !('Bก?:h"%* 2 < P=O"%*(#>@%กกM
16. :?ก% !('Bก?:h"%* 2 < P=O"%*(#>@O กM
17. :?ก% !('Bก?:h"%* O%กกM 5 P=O"%* <M wow
18. :?ก% !('Bก?:h"%* OO กM 5 P=O"%* <M oho
19. :?ก% !('Bก?:h"%* 3 < P=O"%*(#>@%ก#>@&D
20. :?ก% !('Bก?:h"%* 3 < P=O"%*(#>@O #>@&D
Group : 4 #<$< MAAM
21. :?ก% "%* 1 A 10 O for
22. :?ก% "%* 1 A 10 O while
23. :?ก% "%* 10 A 1 O for
24. :?ก% "%* 10 A 1 O while
25. :?ก% "%* 10 A 20 O for
26. :?ก% "%* 10 A 20 O while
27. :?ก% "%* 20 A 10 O for
28. :?ก% "%* 20 A 10 O while
29. :?ก% "%*'B M=MA 1 A 10
30. :?ก% "%*'B >@=MA 1 A 10
Group : 5 #<$<$Oก
31. :?ก% "%*&( C?%M 2
32. :?ก% "%*&( C?%M 3
33. :?ก% "%*&( C?%M 2 '&) ?BO"%*?%M 3 (M
-13-
34. :?ก% "%*&( C?%M 2 ?B 3 B Column
35. :?ก% "%*('B?!! for $OO for
36. :?ก% "%*('B?!! for $OO while
37. :?ก% "%*('B?!! while $OO for
38. :?ก% "%*('B?!! while $OO while
Group : 6 *' *
39. :?ก% MO%Bก*' ?* !!('B 3 &%E"ก%"%* %MPEO for
40. :?ก% MO%Bก*' ?* !!(ก 3 &%E"ก%"%* %MPEO for
41. :?ก% MO%Bก*' ?* !!('B 3 &%E"ก%"%* PEO for
42. :?ก% MO%Bก*' ?* !!(ก 3 &%E"ก%"%* PEO for
43. :?ก% !O%Bก?:h"%*'ก)!BA*' * ?BO<กB!%"%*P=%M
44. :?ก% !O%Bก?:h"%*'ก)!BA*' * ?BO<กB!%"%*P=%M '#>@%กกM 10
45. :?ก% !O%Bก?:h"%*'ก)!BA*' * ?BO<กB!%"%*P=%M '#>@O กM 10
Group : 7 <C'! A(O
46. :?ก% "%* M&A&D ก*' *#>@กก<=':; M A#>P@ :?ก%
47. :?ก% "%* M(@< &D ก*' *#>@กก<=':; M A#>P@ :?ก%
48. :?ก% "%* MbB% ก*' *#>@กก<=':; M A#>P@ :?ก%
49. :?ก% "%* M'B>@ ก*' *#>@กก<=':; M A#>P@ :?ก%
50. :?ก% "%* M&A&D ก*' *#>@! Mก?:h"%*
51. :?ก% "%* M(@< &D ก*' *#>@! Mก?:h"%*
52. :?ก% "%* MbB% ก*' *#>@! Mก?:h"%*
53. :?ก% "%* M'B>@ ก*' *#>@! Mก?:h"%*
Group : 8 ?th%O%B
54. :?ก% MO%Bก?th%O%B %?&A#A
55. :?ก% MO%Bก?th%O%B %?&A#A  %>'BB<!ก<ก!
56. :?ก% MO%Bก?:h"%* ?BO'> BA?th%O%B
57. :?ก% MO%Bก?th%O%B '> BA?th%P=%M>ก?th%=@A
58. :?ก% '"@%O%BP?th%O%B '% @O!O%Bก?:h"%*
59. :?ก% B!O%B ?!!(MA N
60. :?ก% ?กOO%B ?!!(MA N

H LS 1ก
1. ก?!!&OA Game O Java, ElE "AE("'"Ž
2. Advanced Java Programming, DMA*  < ?B:B> %C>(*
3. ก'> :?ก%'E"A(D, bl.EE A%&("Al*
4. Java programming volumne 1, .>lก"‘ $A
5. Java !! p, ก"((" ก>
 กDB
6. 'ก&:ก!ก!% Java Programming Language (SL-275) A!"# SUN
-14-

You might also like