From 32cdfa8408e90caff1f52492402cfa4d5f1d1060 Mon Sep 17 00:00:00 2001 From: DonaldIsFreak Date: Wed, 11 Dec 2013 23:50:55 +0800 Subject: [PATCH 1/2] Encoding UTF8 for CH3 of example --- example/CH3/BitwiseOperator.java | 8 ++++---- example/CH3/BufferedReaderDemo.java | 4 ++-- example/CH3/ConditionalOperator.java | 6 +++--- example/CH3/HelloJava.java | 2 +- example/CH3/HelloJavaForC.java | 4 ++-- example/CH3/IncrementDecrement2.java | 4 ++-- example/CH3/IncrementDecrement3.java | 4 ++-- example/CH3/NumberDemo.java | 6 +++--- example/CH3/OddDecider.java | 6 +++--- example/CH3/OddDecider2.java | 6 +++--- example/CH3/OddDecider3.java | 10 +++++----- example/CH3/OddDecider4.java | 6 +++--- example/CH3/ScannerDemo.java | 4 ++-- example/CH3/ScannerDemo2.java | 4 ++-- example/CH3/ScoreAverage.java | 4 ++-- example/CH3/ScoreLevel.java | 12 ++++++------ example/CH3/ScoreLevel2.java | 12 ++++++------ example/CH3/SecondJavaForC.java | 4 ++-- example/CH3/ShiftOperator.java | 8 ++++---- example/CH3/ThirdJavaForC.java | 4 ++-- example/CH3/TigerNumberDemo.java | 6 +++--- example/CH3/VariableDemo.java | 2 +- example/CH3/XorCode.java | 6 +++--- example/HelloJava.java | 2 +- 24 files changed, 67 insertions(+), 67 deletions(-) diff --git a/example/CH3/BitwiseOperator.java b/example/CH3/BitwiseOperator.java index fa1afa5..0946d2d 100644 --- a/example/CH3/BitwiseOperator.java +++ b/example/CH3/BitwiseOperator.java @@ -1,18 +1,18 @@ -public class BitwiseOperator { +public class BitwiseOperator { public static void main(String[] args) { - System.out.println("AND�B��G"); + System.out.println("AND運算:"); System.out.println("0 AND 0\t\t" + (0 & 0)); System.out.println("0 AND 1\t\t" + (0 & 1)); System.out.println("1 AND 0\t\t" + (1 & 0)); System.out.println("1 AND 1\t\t" + (1 & 1)); - System.out.println("\nOR�B��G"); + System.out.println("\nOR運算:"); System.out.println("0 OR 0\t\t" + (0 | 0)); System.out.println("0 OR 1\t\t" + (0 | 1)); System.out.println("1 OR 0\t\t" + (1 | 0)); System.out.println("1 OR 1\t\t" + (1 | 1)); - System.out.println("\nXOR�B��G"); + System.out.println("\nXOR運算:"); System.out.println("0 XOR 0\t\t" + (0 ^ 0)); System.out.println("0 XOR 1\t\t" + (0 ^ 1)); System.out.println("1 XOR 0\t\t" + (1 ^ 0)); diff --git a/example/CH3/BufferedReaderDemo.java b/example/CH3/BufferedReaderDemo.java index 67fefa9..2186f17 100644 --- a/example/CH3/BufferedReaderDemo.java +++ b/example/CH3/BufferedReaderDemo.java @@ -6,8 +6,8 @@ public static void main(String[] args) throws IOException { new BufferedReader( new InputStreamReader(System.in)); - System.out.print("�п�J�@�C��r�A�i�]�A�ť�: "); + System.out.print("請輸入一列文字,可包括空白: "); String text = bufferedReader.readLine(); - System.out.println("�z��J����r: " + text); + System.out.println("您輸入的文字: " + text); } } \ No newline at end of file diff --git a/example/CH3/ConditionalOperator.java b/example/CH3/ConditionalOperator.java index 826ce4c..941a07b 100644 --- a/example/CH3/ConditionalOperator.java +++ b/example/CH3/ConditionalOperator.java @@ -4,9 +4,9 @@ public class ConditionalOperator { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); - System.out.print("�п�J�ǥͤ���: "); + System.out.print("請輸入學生分數: "); int scoreOfStudent = scanner.nextInt(); - System.out.println("�ӥͬO�_�ή�? " + - (scoreOfStudent >= 60 ? '�O' : '�_')); + System.out.println("該生是否及格? " + + (scoreOfStudent >= 60 ? '是' : '否')); } } \ No newline at end of file diff --git a/example/CH3/HelloJava.java b/example/CH3/HelloJava.java index 6d9902b..d92955a 100644 --- a/example/CH3/HelloJava.java +++ b/example/CH3/HelloJava.java @@ -1,5 +1,5 @@ public class HelloJava { public static void main(String[] args) { - System.out.println("�١I�ڪ��Ĥ@��Java�{���I"); + System.out.println("嗨!我的第一個Java程式!"); } } \ No newline at end of file diff --git a/example/CH3/HelloJavaForC.java b/example/CH3/HelloJavaForC.java index 1787967..f08a623 100644 --- a/example/CH3/HelloJavaForC.java +++ b/example/CH3/HelloJavaForC.java @@ -1,6 +1,6 @@ public class HelloJavaForC { public static void main(String[] args) { - System.out.printf("%s�I �o�O�z���Ĥ@��Java�{���I\n", - "C�y��Fan"); + System.out.printf("%s! 這是您的第一個Java程式!\n", + "C語言Fan"); } } \ No newline at end of file diff --git a/example/CH3/IncrementDecrement2.java b/example/CH3/IncrementDecrement2.java index 0b61a2d..0fac7f1 100644 --- a/example/CH3/IncrementDecrement2.java +++ b/example/CH3/IncrementDecrement2.java @@ -3,9 +3,9 @@ public static void main(String[] args) { int i = 0; int number = 0; - number = ++i; // �۷���i = i + 1; number = i; + number = ++i; // 相當於i = i + 1; number = i; System.out.println(number); - number = --i; // �۷���i = i - 1; number = i; + number = --i; // 相當於i = i - 1; number = i; System.out.println(number); } } \ No newline at end of file diff --git a/example/CH3/IncrementDecrement3.java b/example/CH3/IncrementDecrement3.java index 495275e..7a07577 100644 --- a/example/CH3/IncrementDecrement3.java +++ b/example/CH3/IncrementDecrement3.java @@ -3,9 +3,9 @@ public static void main(String[] args) { int i = 0; int number = 0; - number = i++; // �۷���number = i; i = i + 1; + number = i++; // 相當於number = i; i = i + 1; System.out.println(number); - number = i--; // �۷��� number = i; i = i - 1; + number = i--; // 相當於 number = i; i = i - 1; System.out.println(number); } } \ No newline at end of file diff --git a/example/CH3/NumberDemo.java b/example/CH3/NumberDemo.java index 4f7430f..2c5d4cc 100644 --- a/example/CH3/NumberDemo.java +++ b/example/CH3/NumberDemo.java @@ -1,12 +1,12 @@ public class NumberDemo { public static void main(String[] args) { - // �Q�i�� 19 �ন�G�i�� 10011 + // 十進位 19 轉成二進位 10011 System.out.println(Integer.toBinaryString(19)); - // �Q�i�� 19 �ন�Q���i�� 13 + // 十進位 19 轉成十六進位 13 System.out.println(Integer.toHexString(19)); - // �Q�i�� 19 �ন�K�i�� 23 + // 十進位 19 轉成八進位 23 System.out.println(Integer.toOctalString(19)); } } \ No newline at end of file diff --git a/example/CH3/OddDecider.java b/example/CH3/OddDecider.java index 2ed0c94..acb8b18 100644 --- a/example/CH3/OddDecider.java +++ b/example/CH3/OddDecider.java @@ -4,9 +4,9 @@ public class OddDecider { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); - System.out.print("�п�J�Ʀr: "); + System.out.print("請輸入數字: "); int number = scanner.nextInt(); - System.out.println("�O�_���_��? " + - (number%2 != 0 ? '�O' : '�_')); + System.out.println("是否為奇數? " + + (number%2 != 0 ? '是' : '否')); } } \ No newline at end of file diff --git a/example/CH3/OddDecider2.java b/example/CH3/OddDecider2.java index b8fd6e0..4619080 100644 --- a/example/CH3/OddDecider2.java +++ b/example/CH3/OddDecider2.java @@ -4,9 +4,9 @@ public class OddDecider2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); - System.out.print("�п�J�Ʀr: "); + System.out.print("請輸入數字: "); int number = scanner.nextInt(); - System.out.println("�O�_���_��? " + - ((number&1) != 0 ? '�O' : '�_')); + System.out.println("是否為奇數? " + + ((number&1) != 0 ? '是' : '否')); } } \ No newline at end of file diff --git a/example/CH3/OddDecider3.java b/example/CH3/OddDecider3.java index 409ccc2..46ba8fe 100644 --- a/example/CH3/OddDecider3.java +++ b/example/CH3/OddDecider3.java @@ -4,13 +4,13 @@ public class OddDecider3 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); - System.out.print("�п�J�Ʀr: "); + System.out.print("請輸入數字: "); int input = scanner.nextInt(); - int remain = input % 2; // �D�� 2 ���l�� + int remain = input % 2; // 求除 2 的餘數 - if(remain == 1) // �p�G�l�Ƭ�1 - System.out.println(input + "���_��"); + if(remain == 1) // 如果餘數為1 + System.out.println(input + "為奇數"); else - System.out.println(input + "������"); + System.out.println(input + "為偶數"); } } \ No newline at end of file diff --git a/example/CH3/OddDecider4.java b/example/CH3/OddDecider4.java index c94afbc..ddc571d 100644 --- a/example/CH3/OddDecider4.java +++ b/example/CH3/OddDecider4.java @@ -7,11 +7,11 @@ public static void main(String[] args) { int replay = 0; do { - System.out.print("��J��ƭȡG"); + System.out.print("輸入整數值:"); input = scanner.nextInt(); - System.out.println("��J�Ƭ��_�ơH" + + System.out.println("輸入數為奇數?" + ((input%2 == 1) ? 'Y': 'N')); - System.out.print("�~��(1:�~�� 0:����)�H"); + System.out.print("繼續(1:繼續 0:結束)?"); replay = scanner.nextInt(); } while(replay == 1); } diff --git a/example/CH3/ScannerDemo.java b/example/CH3/ScannerDemo.java index 3b3c256..0374e92 100644 --- a/example/CH3/ScannerDemo.java +++ b/example/CH3/ScannerDemo.java @@ -3,7 +3,7 @@ public class ScannerDemo { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); - System.out.print("�п�J�z���W�r�G"); - System.out.printf("���o�I %s!\n", scanner.next()); + System.out.print("請輸入您的名字:"); + System.out.printf("哈囉! %s!\n", scanner.next()); } } \ No newline at end of file diff --git a/example/CH3/ScannerDemo2.java b/example/CH3/ScannerDemo2.java index a80b7e1..5629a4b 100644 --- a/example/CH3/ScannerDemo2.java +++ b/example/CH3/ScannerDemo2.java @@ -3,8 +3,8 @@ public class ScannerDemo2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); - System.out.print("�п�J�@�ӼƦr�G "); - System.out.printf("�z��J�F %d �I\n", + System.out.print("請輸入一個數字: "); + System.out.printf("您輸入了 %d !\n", scanner.nextInt()); } } \ No newline at end of file diff --git a/example/CH3/ScoreAverage.java b/example/CH3/ScoreAverage.java index 65f5ef4..0f0f594 100644 --- a/example/CH3/ScoreAverage.java +++ b/example/CH3/ScoreAverage.java @@ -10,10 +10,10 @@ public static void main(String[] args) { while(score != -1) { count++; sum += score; - System.out.print("��J����(-1����)�G"); + System.out.print("輸入分數(-1結束):"); score = scanner.nextInt(); } - System.out.println("�����G" + (double) sum/count); + System.out.println("平均:" + (double) sum/count); } } \ No newline at end of file diff --git a/example/CH3/ScoreLevel.java b/example/CH3/ScoreLevel.java index 8a6422d..a0a639d 100644 --- a/example/CH3/ScoreLevel.java +++ b/example/CH3/ScoreLevel.java @@ -4,18 +4,18 @@ public class ScoreLevel { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); - System.out.print("��J���ơG"); + System.out.print("輸入分數:"); int score = scanner.nextInt(); if(score >= 90) - System.out.println("�oA"); + System.out.println("得A"); else if(score >= 80 && score < 90) - System.out.println("�oB"); + System.out.println("得B"); else if(score >= 70 && score < 80) - System.out.println("�oC"); + System.out.println("得C"); else if(score >= 60 && score < 70) - System.out.println("�oD"); + System.out.println("得D"); else - System.out.println("�oE(���ή�)"); + System.out.println("得E(不及格)"); } } \ No newline at end of file diff --git a/example/CH3/ScoreLevel2.java b/example/CH3/ScoreLevel2.java index d03fe16..7e96f28 100644 --- a/example/CH3/ScoreLevel2.java +++ b/example/CH3/ScoreLevel2.java @@ -4,26 +4,26 @@ public class ScoreLevel2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); - System.out.print("�п�J����: "); + System.out.print("請輸入分數: "); int score = scanner.nextInt(); int level = (int) score/10; switch(level) { case 10: case 9: - System.out.println("�oA"); + System.out.println("得A"); break; case 8: - System.out.println("�oB"); + System.out.println("得B"); break; case 7: - System.out.println("�oC"); + System.out.println("得C"); break; case 6: - System.out.println("�oD"); + System.out.println("得D"); break; default: - System.out.println("�oE(���ή�)"); + System.out.println("得E(不及格)"); } } } diff --git a/example/CH3/SecondJavaForC.java b/example/CH3/SecondJavaForC.java index 2b55334..104d703 100644 --- a/example/CH3/SecondJavaForC.java +++ b/example/CH3/SecondJavaForC.java @@ -1,6 +1,6 @@ public class SecondJavaForC { public static void main(String[] args) { - System.out.printf("%s�I �o�O�z���Ĥ@��Java�{���I", - "C�y��Fan").println(); + System.out.printf("%s! 這是您的第一個Java程式!", + "C語言Fan").println(); } } \ No newline at end of file diff --git a/example/CH3/ShiftOperator.java b/example/CH3/ShiftOperator.java index 53acee0..d0d4346 100644 --- a/example/CH3/ShiftOperator.java +++ b/example/CH3/ShiftOperator.java @@ -2,15 +2,15 @@ public class ShiftOperator { public static void main(String[] args) { int number = 1; - System.out.println( "2��0��: " + number); + System.out.println( "2的0次: " + number); number = number << 1; - System.out.println("2��1��: " + number); + System.out.println("2的1次: " + number); number = number << 1; - System.out.println("2��2��: " + number); + System.out.println("2的2次: " + number); number = number << 1; - System.out.println("2��3���G" + number); + System.out.println("2的3次:" + number); } } \ No newline at end of file diff --git a/example/CH3/ThirdJavaForC.java b/example/CH3/ThirdJavaForC.java index 6c1592e..b539459 100644 --- a/example/CH3/ThirdJavaForC.java +++ b/example/CH3/ThirdJavaForC.java @@ -1,6 +1,6 @@ public class ThirdJavaForC { public static void main(String[] args) { - System.out.printf("%s�I �o�O�z���� %d ��Java�{���I\n", - "C�y��Fan", 3); + System.out.printf("%s! 這是您的第 %d 個Java程式!\n", + "C語言Fan", 3); } } \ No newline at end of file diff --git a/example/CH3/TigerNumberDemo.java b/example/CH3/TigerNumberDemo.java index 1268919..d39de57 100644 --- a/example/CH3/TigerNumberDemo.java +++ b/example/CH3/TigerNumberDemo.java @@ -1,12 +1,12 @@ public class TigerNumberDemo { public static void main(String[] args) { - // ��X 19 ���Q�i����� + // 輸出 19 的十進位表示 System.out.printf("%d%n", 19); - // ��X 19 ���K�i����� + // 輸出 19 的八進位表示 System.out.printf("%o%n", 19); - // ��X 19 ���Q���i����� + // 輸出 19 的十六進位表示 System.out.printf("%x%n", 19); } } \ No newline at end of file diff --git a/example/CH3/VariableDemo.java b/example/CH3/VariableDemo.java index 84a8945..8211814 100644 --- a/example/CH3/VariableDemo.java +++ b/example/CH3/VariableDemo.java @@ -4,7 +4,7 @@ public static void main(String[] args) { double scoreOfStudent = 80.0; char levelOfStudent = 'B'; - System.out.println("�~��\t �o��\t ����"); + System.out.println("年級\t 得分\t 等級"); System.out.printf("%4d\t %4.1f\t %4c", ageOfStudent, scoreOfStudent, levelOfStudent); } diff --git a/example/CH3/XorCode.java b/example/CH3/XorCode.java index ce7099d..8fdaf54 100644 --- a/example/CH3/XorCode.java +++ b/example/CH3/XorCode.java @@ -1,12 +1,12 @@ public class XorCode { public static void main(String[] args) { char ch = 'A'; - System.out.println("�s�X�e�G" + ch); + System.out.println("編碼前:" + ch); ch = (char)(ch^7); - System.out.println("�s�X��G" + ch); + System.out.println("編碼後:" + ch); ch = (char)(ch^7); - System.out.println("�ѽX�G" + ch); + System.out.println("解碼:" + ch); } } diff --git a/example/HelloJava.java b/example/HelloJava.java index 6d9902b..d92955a 100644 --- a/example/HelloJava.java +++ b/example/HelloJava.java @@ -1,5 +1,5 @@ public class HelloJava { public static void main(String[] args) { - System.out.println("�١I�ڪ��Ĥ@��Java�{���I"); + System.out.println("嗨!我的第一個Java程式!"); } } \ No newline at end of file From 15afd317c9f45b950f77ce2639df018b546b65d7 Mon Sep 17 00:00:00 2001 From: DonaldIsFreak Date: Thu, 12 Dec 2013 09:59:24 +0800 Subject: [PATCH 2/2] Encoding other Java file to UTF8 --- example/CH10/AssertionDemo.java | 2 +- example/CH10/CatchWho.java | 6 +- example/CH10/CatchWho2.java | 6 +- example/CH10/CheckArgsDemo.java | 4 +- example/CH10/CheckedExceptionDemo.java | 6 +- example/CH10/ExceptionDemo.java | 2 +- example/CH10/ExceptionDemo2.java | 2 +- example/CH10/ThrowDemo.java | 4 +- example/CH10/ThrowsDemo.java | 6 +- example/CH11/DetailAction.java | 6 +- example/CH11/DetailAction2.java | 4 +- example/CH11/DetailAction3.java | 4 +- example/CH11/DetailActionDemo.java | 2 +- example/CH11/EnumCompareTo.java | 2 +- example/CH11/EnumDemo.java | 6 +- example/CH11/EnumDemo2.java | 6 +- example/CH11/MoreAction.java | 18 +- example/CH11/MoreAction2.java | 20 +-- example/CH11/MoreActionDemo.java | 2 +- example/CH13/ArrayListDemo.java | 4 +- example/CH13/EnhancedForDemo.java | 4 +- example/CH13/EnumMapDemo.java | 6 +- example/CH13/EnumMapDemo2.java | 6 +- example/CH13/EnumSetDemo.java | 8 +- example/CH13/EnumSetDemo2.java | 4 +- example/CH13/HashMapDemo.java | 4 +- example/CH13/HashMapDemo2.java | 8 +- example/CH13/HashSetDemo.java | 6 +- example/CH13/IteratorDemo.java | 8 +- example/CH13/LinkedHashMapDemo.java | 6 +- example/CH13/LinkedHashSetDemo.java | 2 +- example/CH13/QueueDemo.java | 8 +- example/CH13/StringQueueDemo.java | 4 +- example/CH13/StringStack.java | 8 +- example/CH13/StringStackDemo.java | 4 +- example/CH13/TreeMapDemo.java | 6 +- example/CH13/TreeMapDemo2.java | 6 +- example/CH13/TreeSetDemo.java | 2 +- example/CH13/TreeSetDemo2.java | 4 +- example/CH14/BufferedReaderWriterDemo.java | 10 +- example/CH14/BufferedStreamDemo.java | 10 +- example/CH14/ByteArrayStreamDemo.java | 16 +- example/CH14/CharArrayReaderWriterDemo.java | 14 +- example/CH14/DataStreamDemo.java | 18 +- example/CH14/FileDemo.java | 22 +-- example/CH14/FileReaderWriterDemo.java | 4 +- example/CH14/FileStreamDemo.java | 22 +-- example/CH14/ObjectStreamDemo.java | 38 ++-- example/CH14/PushbackReaderDemo.java | 8 +- example/CH14/PushbackStreamDemo.java | 10 +- example/CH14/RandomAccessFileDemo.java | 20 +-- example/CH14/ReaderDemo.java | 16 +- example/CH14/SequenceStreamDemo.java | 42 ++--- example/CH14/StreamDemo.java | 4 +- example/CH14/StreamReaderWriterDemo.java | 8 +- example/CH14/StreamWriterDemo.java | 14 +- example/CH14/Student.java | 4 +- example/CH15/Clerk.java | 18 +- example/CH15/Consumer.java | 8 +- example/CH15/DaemonThread.java | 4 +- example/CH15/Eraser.java | 6 +- example/CH15/EraserDemo.java | 12 +- example/CH15/EraserThread.java | 6 +- example/CH15/EraserThreadDemo.java | 10 +- example/CH15/ExecutorDemo.java | 2 +- example/CH15/FutureDemo.java | 4 +- example/CH15/InterruptDemo.java | 2 +- example/CH15/PersonalInfoTest.java | 4 +- example/CH15/PrimeCallable.java | 2 +- example/CH15/Producer.java | 8 +- example/CH15/ProductTest.java | 4 +- example/CH15/SimpleThreadLogger.java | 6 +- example/CH15/SomeThread.java | 2 +- example/CH15/ThreadA.java | 12 +- example/CH15/ThreadGroupDemo2.java | 12 +- example/CH15/ThreadLocal.java | 10 +- example/CH16/ArrayDemo.java | 16 +- example/CH16/ArrayElementDemo.java | 16 +- example/CH16/AssignFieldDemo.java | 6 +- example/CH16/ClassDemo.java | 10 +- example/CH16/ClassInfoDemo.java | 4 +- example/CH16/ClassLoaderDemo.java | 18 +- example/CH16/CommandUtil.java | 18 +- example/CH16/ForNameDemo.java | 14 +- example/CH16/ForNameDemoV1.java | 8 +- example/CH16/ForNameDemoV2.java | 8 +- example/CH16/ForNameDemoV3.java | 8 +- example/CH16/InvokeMethodDemo.java | 16 +- example/CH16/LoadClassTest.java | 4 +- example/CH16/LogHandler.java | 8 +- example/CH16/NewArrayDemo2.java | 2 +- example/CH16/NewInstanceDemo.java | 2 +- example/CH16/NewInstanceDemo2.java | 18 +- example/CH16/ProxyDemo.java | 2 +- example/CH16/SimpleClassViewer.java | 32 ++-- example/CH16/SomeClass.java | 10 +- example/CH16/TestClass.java | 2 +- example/CH16/TestClass2.java | 2 +- example/CH17/AnalysisApp.java | 22 +-- example/CH17/SomethingDemo.java | 2 +- example/CH18/CalendarDemo.java | 48 ++--- example/CH18/CurrentTime.java | 2 +- example/CH18/DateDemo.java | 4 +- example/CH18/DateTimeInstanceDemo.java | 18 +- example/CH18/DateTimeInstanceDemo2.java | 12 +- example/CH18/HandlerDemo.java | 2 +- example/CH18/LoggingDemo.java | 2 +- example/CH18/LoggingLevelDemo.java | 14 +- example/CH18/LoggingLevelDemo2.java | 20 +-- example/CH18/LoggingLevelDemo3.java | 14 +- example/CH18/MessageFormatDemo.java | 6 +- example/CH18/ResourceBundleDemo.java | 4 +- example/CH18/TableFormatterDemo.java | 4 +- .../19.2/onlyfun/caterpillar/JNotePadUI.java | 46 ++--- .../19.3/onlyfun/caterpillar/JNotePadUI.java | 82 ++++----- .../19.4/onlyfun/caterpillar/JNotePad.java | 166 +++++++++--------- example/CH20/BasicDBSource.java | 2 +- example/CH20/ConnectionDemo.java | 4 +- example/CH20/LobDemo.java | 8 +- example/CH21/BinarySearchDemo.java | 4 +- example/CH21/CalendarDemo.java | 6 +- example/CH21/ConnectionDemo.java | 4 +- example/CH21/FileDemo.java | 2 +- example/CH21/PasswordDemo.java | 8 +- example/CH21/PasswordDemo2.java | 8 +- example/CH21/SystemTrayDemo.java | 4 +- example/CH21/SystemTrayDemo2.java | 6 +- example/CH21/SystemTrayDemo3.java | 8 +- example/CH3/BitwiseOperator.java | 2 +- example/CH3/ComparisonOperator.java | 12 +- example/CH3/DataRange.java | 12 +- example/CH3/ErrDemo.java | 4 +- example/CH4/AutoBoxDemo.java | 4 +- example/CH4/StringDemo.java | 22 +-- example/CH4/UserLogin.java | 8 +- example/CH4/WrapperDemo.java | 8 +- example/CH5/AdvancedArray.java | 8 +- example/CH5/AdvancedArray2.java | 4 +- example/CH5/ArrayDemo.java | 4 +- example/CH5/ArraysMethodDemo.java | 12 +- example/CH5/AverageInput.java | 10 +- example/CH5/NewArraysDemo.java | 4 +- example/CH6/AppendStringTest.java | 4 +- example/CH6/CharAtString.java | 8 +- example/CH6/CommandLineArg.java | 2 +- example/CH6/CommandLineArg2.java | 2 +- example/CH6/FileFilter.java | 2 +- example/CH6/StringDemo.java | 10 +- example/CH6/UsePatternMatcher.java | 8 +- example/CH6/UseRegularExpression.java | 22 +-- example/CH7/AccountDemo.java | 8 +- example/CH7/GcTest.java | 6 +- example/CH7/MathTool.java | 2 +- example/CH7/MethodMember.java | 8 +- example/CH7/OverloadTest.java | 4 +- example/CH7/SafeArray.java | 6 +- example/CH7/SafeArrayDemo.java | 4 +- example/CH7/SomeClass.java | 2 +- example/CH7/StaticDemo.java | 2 +- example/CH7/UseGC.java | 8 +- example/CH7/UseRecursion.java | 2 +- example/CH8/AbstractGuessGame.java | 8 +- example/CH8/Bird.java | 2 +- example/CH8/Chicken.java | 10 +- example/CH8/CloneDemo.java | 10 +- example/CH8/ConcreteCircle.java | 2 +- example/CH8/Cubic.java | 2 +- example/CH8/ExtendDemo.java | 6 +- example/CH8/Foo1.java | 2 +- example/CH8/Foo2.java | 2 +- example/CH8/HelloRequest.java | 2 +- example/CH8/HollowCircle.java | 2 +- example/CH8/Point.java | 2 +- example/CH8/Rectangle.java | 2 +- example/CH8/RequestDemo.java | 4 +- example/CH8/SimpleCollection.java | 2 +- example/CH8/SimpleCollectionDemo.java | 4 +- example/CH8/Table.java | 4 +- example/CH8/TextModeGame.java | 2 +- example/CH8/WelcomeRequest.java | 2 +- example/CH9/AnonymousClassDemo.java | 4 +- example/CH9/PointDemo.java | 2 +- 182 files changed, 842 insertions(+), 842 deletions(-) diff --git a/example/CH10/AssertionDemo.java b/example/CH10/AssertionDemo.java index 5395a99..8caba11 100644 --- a/example/CH10/AssertionDemo.java +++ b/example/CH10/AssertionDemo.java @@ -5,7 +5,7 @@ public static void main(String[] args) { } else { assert args.length == 0; - System.out.println("�S����J�޼�"); + System.out.println("沒有輸入引數"); } } } \ No newline at end of file diff --git a/example/CH10/CatchWho.java b/example/CH10/CatchWho.java index ce70e24..2efaf10 100644 --- a/example/CH10/CatchWho.java +++ b/example/CH10/CatchWho.java @@ -7,18 +7,18 @@ public static void main(String[] args) { catch(ArrayIndexOutOfBoundsException e) { System.out.println( "ArrayIndexOutOfBoundsException" + - "/���htry-catch"); + "/內層try-catch"); } throw new ArithmeticException(); } catch(ArithmeticException e) { - System.out.println("�o��ArithmeticException"); + System.out.println("發生ArithmeticException"); } catch(ArrayIndexOutOfBoundsException e) { System.out.println( "ArrayIndexOutOfBoundsException" + - "/�~�htry-catch"); + "/外層try-catch"); } } } \ No newline at end of file diff --git a/example/CH10/CatchWho2.java b/example/CH10/CatchWho2.java index d37f468..7ef20dd 100644 --- a/example/CH10/CatchWho2.java +++ b/example/CH10/CatchWho2.java @@ -7,18 +7,18 @@ public static void main(String[] args) { catch(ArithmeticException e) { System.out.println( "ArrayIndexOutOfBoundsException" + - "/���htry-catch"); + "/內層try-catch"); } throw new ArithmeticException(); } catch(ArithmeticException e) { - System.out.println("�o��ArithmeticException"); + System.out.println("發生ArithmeticException"); } catch(ArrayIndexOutOfBoundsException e) { System.out.println( "ArrayIndexOutOfBoundsException" + - "/�~�htry-catch"); + "/外層try-catch"); } } } \ No newline at end of file diff --git a/example/CH10/CheckArgsDemo.java b/example/CH10/CheckArgsDemo.java index 561adcc..2d62cbf 100644 --- a/example/CH10/CheckArgsDemo.java +++ b/example/CH10/CheckArgsDemo.java @@ -1,10 +1,10 @@ public class CheckArgsDemo { public static void main(String[] args) { try { - System.out.printf("���� %s �\��%n", args[0]); + System.out.printf("執行 %s 功能%n", args[0]); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�S�����w�޼�"); + System.out.println("沒有指定引數"); e.printStackTrace(); } } diff --git a/example/CH10/CheckedExceptionDemo.java b/example/CH10/CheckedExceptionDemo.java index 0b32f33..0fa1093 100644 --- a/example/CH10/CheckedExceptionDemo.java +++ b/example/CH10/CheckedExceptionDemo.java @@ -5,15 +5,15 @@ public static void main(String[] args) { try { BufferedReader buf = new BufferedReader( new InputStreamReader(System.in)); - System.out.print("�п�J���: "); + System.out.print("請輸入整數: "); int input = Integer.parseInt(buf.readLine()); System.out.println("input x 10 = " + (input*10)); } catch(IOException e) { - System.out.println("I/O���~"); + System.out.println("I/O錯誤"); } catch(NumberFormatException e) { - System.out.println("��J���������"); + System.out.println("輸入必須為整數"); } } } \ No newline at end of file diff --git a/example/CH10/ExceptionDemo.java b/example/CH10/ExceptionDemo.java index 4826d1e..13a6363 100644 --- a/example/CH10/ExceptionDemo.java +++ b/example/CH10/ExceptionDemo.java @@ -3,7 +3,7 @@ public class ExceptionDemo { public static void main(String[] args) { try { - throw new ArithmeticException("�ҥ~����"); + throw new ArithmeticException("例外測試"); } catch(Exception e) { System.out.println(e.toString()); diff --git a/example/CH10/ExceptionDemo2.java b/example/CH10/ExceptionDemo2.java index 265d634..3afd2f1 100644 --- a/example/CH10/ExceptionDemo2.java +++ b/example/CH10/ExceptionDemo2.java @@ -3,7 +3,7 @@ public class ExceptionDemo2 { public static void main(String[] args) { try { - throw new ArithmeticException("�ҥ~����"); + throw new ArithmeticException("例外測試"); } catch(ArithmeticException e) { System.out.println(e.toString()); diff --git a/example/CH10/ThrowDemo.java b/example/CH10/ThrowDemo.java index 8cb416b..82d8887 100644 --- a/example/CH10/ThrowDemo.java +++ b/example/CH10/ThrowDemo.java @@ -2,9 +2,9 @@ public class ThrowDemo { public static void main(String[] args) { try { double data = 100 / 0.0; - System.out.println("�B�I�ư��H�s�G" + data); + System.out.println("浮點數除以零:" + data); if(String.valueOf(data).equals("Infinity")) - throw new ArithmeticException("���s�ҥ~"); + throw new ArithmeticException("除零例外"); } catch(ArithmeticException e) { System.out.println(e); diff --git a/example/CH10/ThrowsDemo.java b/example/CH10/ThrowsDemo.java index 1a8003d..f1a485c 100644 --- a/example/CH10/ThrowsDemo.java +++ b/example/CH10/ThrowsDemo.java @@ -4,14 +4,14 @@ public static void main(String[] args) { throwsTest(); } catch(ArithmeticException e) { - System.out.println("�����ҥ~"); + System.out.println("捕捉例外"); } } private static void throwsTest() throws ArithmeticException { - System.out.println("�o�u�O�@�Ӵ���"); - // �{���B�z�L�{���]�o�ͨҥ~ + System.out.println("這只是一個測試"); + // 程式處理過程假設發生例外 throw new ArithmeticException(); } } \ No newline at end of file diff --git a/example/CH11/DetailAction.java b/example/CH11/DetailAction.java index 780ddf5..e851851 100644 --- a/example/CH11/DetailAction.java +++ b/example/CH11/DetailAction.java @@ -4,11 +4,11 @@ public enum DetailAction { public String getDescription() { switch(this.ordinal()) { case 0: - return "�V����"; + return "向左轉"; case 1: - return "�V�k��"; + return "向右轉"; case 2: - return "�g��"; + return "射擊"; default: return null; } diff --git a/example/CH11/DetailAction2.java b/example/CH11/DetailAction2.java index 2dc600c..b55da97 100644 --- a/example/CH11/DetailAction2.java +++ b/example/CH11/DetailAction2.java @@ -1,9 +1,9 @@ public enum DetailAction2 { - TURN_LEFT("�V����"), TURN_RIGHT("�V�k��"), SHOOT("�g��"); + TURN_LEFT("向左轉"), TURN_RIGHT("向右轉"), SHOOT("射擊"); private String description; - // �����}���غc��k + // 不公開的建構方法 private DetailAction2(String description) { this.description = description; } diff --git a/example/CH11/DetailAction3.java b/example/CH11/DetailAction3.java index 5c1ac92..20f1e2e 100644 --- a/example/CH11/DetailAction3.java +++ b/example/CH11/DetailAction3.java @@ -1,9 +1,9 @@ public enum DetailAction3 implements IDescription { - TURN_LEFT("�V����"), TURN_RIGHT("�V�k��"), SHOOT("�g��"); + TURN_LEFT("向左轉"), TURN_RIGHT("向右轉"), SHOOT("射擊"); private String description; - // �����}���غc��k + // 不公開的建構方法 private DetailAction3(String description) { this.description = description; } diff --git a/example/CH11/DetailActionDemo.java b/example/CH11/DetailActionDemo.java index 305032d..3622001 100644 --- a/example/CH11/DetailActionDemo.java +++ b/example/CH11/DetailActionDemo.java @@ -1,7 +1,7 @@ public class DetailActionDemo { public static void main(String[] args) { for(DetailAction action : DetailAction.values()) { - System.out.printf("%s�G%s%n", + System.out.printf("%s:%s%n", action, action.getDescription()); } } diff --git a/example/CH11/EnumCompareTo.java b/example/CH11/EnumCompareTo.java index df2d7f2..8566ccc 100644 --- a/example/CH11/EnumCompareTo.java +++ b/example/CH11/EnumCompareTo.java @@ -4,7 +4,7 @@ public static void main(String[] args) { } public static void compareToAction(Action inputAction) { - System.out.println("��J�G" + inputAction); + System.out.println("輸入:" + inputAction); for(Action action: Action.values()) { System.out.println(action.compareTo(inputAction)); } diff --git a/example/CH11/EnumDemo.java b/example/CH11/EnumDemo.java index 244ad29..7f35b00 100644 --- a/example/CH11/EnumDemo.java +++ b/example/CH11/EnumDemo.java @@ -6,13 +6,13 @@ public static void main(String[] args) { public static void doAction(Action action) { switch(action) { case TURN_LEFT: - System.out.println("�V����"); + System.out.println("向左轉"); break; case TURN_RIGHT: - System.out.println("�V�k��"); + System.out.println("向右轉"); break; case SHOOT: - System.out.println("�g��"); + System.out.println("射擊"); break; } } diff --git a/example/CH11/EnumDemo2.java b/example/CH11/EnumDemo2.java index 4459f59..b8eeee0 100644 --- a/example/CH11/EnumDemo2.java +++ b/example/CH11/EnumDemo2.java @@ -8,13 +8,13 @@ public static void main(String[] args) { public static void doAction(InnerAction action) { switch(action) { case TURN_LEFT: - System.out.println("�V����"); + System.out.println("向左轉"); break; case TURN_RIGHT: - System.out.println("�V�k��"); + System.out.println("向右轉"); break; case SHOOT: - System.out.println("�g��"); + System.out.println("射擊"); break; } } diff --git a/example/CH11/MoreAction.java b/example/CH11/MoreAction.java index f129d1d..06c42d0 100644 --- a/example/CH11/MoreAction.java +++ b/example/CH11/MoreAction.java @@ -1,22 +1,22 @@ public enum MoreAction implements IDescription { TURN_LEFT { - // ��@�����W����k + // 實作介面上的方法 public String getDescription() { - return "�V����"; + return "向左轉"; } - }, // �O�o�o�䪺�C�|�Ȥ��j�ϥ� , + }, // 記得這邊的列舉值分隔使用 , TURN_RIGHT { - // ��@�����W����k + // 實作介面上的方法 public String getDescription() { - return "�V�k��"; + return "向右轉"; } - }, // �O�o�o�䪺�C�|�Ȥ��j�ϥ� , + }, // 記得這邊的列舉值分隔使用 , SHOOT { - // ��@�����W����k + // 實作介面上的方法 public String getDescription() { - return "�g��"; + return "射擊"; } - }; // �O�o�o�䪺�C�|�ȵ����ϥ� ; + }; // 記得這邊的列舉值結束使用 ; } \ No newline at end of file diff --git a/example/CH11/MoreAction2.java b/example/CH11/MoreAction2.java index 94da2ce..8bf5339 100644 --- a/example/CH11/MoreAction2.java +++ b/example/CH11/MoreAction2.java @@ -1,25 +1,25 @@ public enum MoreAction2 { TURN_LEFT { - // ��@��H��k + // 實作抽象方法 public String getDescription() { - return "�V����"; + return "向左轉"; } - }, // �O�o�o�䪺�C�|�Ȥ��j�ϥ� , + }, // 記得這邊的列舉值分隔使用 , TURN_RIGHT { - // ��@��H��k + // 實作抽象方法 public String getDescription() { - return "�V�k��"; + return "向右轉"; } - }, // �O�o�o�䪺�C�|�Ȥ��j�ϥ� , + }, // 記得這邊的列舉值分隔使用 , SHOOT { - // ��@��H��k + // 實作抽象方法 public String getDescription() { - return "�g��"; + return "射擊"; } - }; // �O�o�o�䪺�C�|�ȵ����ϥ� ; + }; // 記得這邊的列舉值結束使用 ; - // �ŧi�ө�H��k + // 宣告個抽象方法 public abstract String getDescription(); } \ No newline at end of file diff --git a/example/CH11/MoreActionDemo.java b/example/CH11/MoreActionDemo.java index bfca0ac..5bb38d3 100644 --- a/example/CH11/MoreActionDemo.java +++ b/example/CH11/MoreActionDemo.java @@ -1,7 +1,7 @@ public class MoreActionDemo { public static void main(String[] args) { for(MoreAction action : MoreAction.values()) { - System.out.printf("%s�G%s%n", + System.out.printf("%s:%s%n", action, action.getDescription()); } } diff --git a/example/CH13/ArrayListDemo.java b/example/CH13/ArrayListDemo.java index d3f7526..409620e 100644 --- a/example/CH13/ArrayListDemo.java +++ b/example/CH13/ArrayListDemo.java @@ -8,7 +8,7 @@ public static void main(String[] args) { List list = new ArrayList(); - System.out.println("��J�W��(�ϥ�quit����)"); + System.out.println("輸入名稱(使用quit結束)"); while(true) { System.out.print("# "); @@ -19,7 +19,7 @@ public static void main(String[] args) { list.add(input); } - System.out.print("��ܿ�J: "); + System.out.print("顯示輸入: "); for(int i = 0; i < list.size(); i++) System.out.print(list.get(i) + " "); System.out.println(); diff --git a/example/CH13/EnhancedForDemo.java b/example/CH13/EnhancedForDemo.java index 8fa8edf..276c7bb 100644 --- a/example/CH13/EnhancedForDemo.java +++ b/example/CH13/EnhancedForDemo.java @@ -8,7 +8,7 @@ public static void main(String[] args) { List list = new ArrayList(); - System.out.println("��J�W��(��Jquit����)"); + System.out.println("輸入名稱(輸入quit結束)"); while(true) { System.out.print("# "); String input = scanner.next(); @@ -18,7 +18,7 @@ public static void main(String[] args) { list.add(input); } - // �ϥ�foreach�ӹM�XList�������� + // 使用foreach來遍訪List中的元素 for(String s : list) { System.out.print(s + " "); } diff --git a/example/CH13/EnumMapDemo.java b/example/CH13/EnumMapDemo.java index acfd934..a7f4372 100644 --- a/example/CH13/EnumMapDemo.java +++ b/example/CH13/EnumMapDemo.java @@ -9,9 +9,9 @@ public static void main(String[] args) { Map map = new EnumMap(Action.class); - map.put(Action.TURN_LEFT, "�V����"); - map.put(Action.TURN_RIGHT, "�V�k��"); - map.put(Action.SHOOT, "�g��"); + map.put(Action.TURN_LEFT, "向左轉"); + map.put(Action.TURN_RIGHT, "向右轉"); + map.put(Action.SHOOT, "射擊"); for(Action action : Action.values( ) ) { System.out.println(map.get(action)); diff --git a/example/CH13/EnumMapDemo2.java b/example/CH13/EnumMapDemo2.java index 17f3b97..e37317c 100644 --- a/example/CH13/EnumMapDemo2.java +++ b/example/CH13/EnumMapDemo2.java @@ -9,9 +9,9 @@ public static void main(String[] args) { Map map = new EnumMap(Action.class); - map.put(Action.SHOOT, "�g��"); - map.put(Action.TURN_RIGHT, "�V�k��"); - map.put(Action.TURN_LEFT, "�V����"); + map.put(Action.SHOOT, "射擊"); + map.put(Action.TURN_RIGHT, "向右轉"); + map.put(Action.TURN_LEFT, "向左轉"); for(String value : map.values( )) { System.out.println(value); diff --git a/example/CH13/EnumSetDemo.java b/example/CH13/EnumSetDemo.java index d460b3c..2d2d4e0 100644 --- a/example/CH13/EnumSetDemo.java +++ b/example/CH13/EnumSetDemo.java @@ -2,18 +2,18 @@ import java.util.*; -// �w�q�C�|���A +// 定義列舉型態 enum FontConstant { Plain, Bold, Italic } public class EnumSetDemo { public static void main(String[] args) { - // �إߦC�|�ȶ��X + // 建立列舉值集合 EnumSet enumSet = EnumSet.of(FontConstant.Plain, FontConstant.Bold); - // ��ܶ��X���e + // 顯示集合內容 showEnumSet(enumSet); - // ��ܸɶ��X���e + // 顯示補集合內容 showEnumSet(EnumSet.complementOf(enumSet)); } diff --git a/example/CH13/EnumSetDemo2.java b/example/CH13/EnumSetDemo2.java index 50597af..7425b9f 100644 --- a/example/CH13/EnumSetDemo2.java +++ b/example/CH13/EnumSetDemo2.java @@ -6,10 +6,10 @@ enum FontConstant { Plain, Bold, Italic } public class EnumSetDemo2 { public static void main(String[] args) { - // �إ�EnumSet��ҡA��l���e���� + // 建立EnumSet實例,初始內容為空 EnumSet enumSet = EnumSet.noneOf(FontConstant.class); - // �[�J�C�| + // 加入列舉 enumSet.add(FontConstant.Bold); enumSet.add(FontConstant.Italic); diff --git a/example/CH13/HashMapDemo.java b/example/CH13/HashMapDemo.java index 785760b..4636a82 100644 --- a/example/CH13/HashMapDemo.java +++ b/example/CH13/HashMapDemo.java @@ -9,8 +9,8 @@ public static void main(String[] args) { String key1 = "caterpillar"; String key2 = "justin"; - map.put(key1, "caterpillar ���T��"); - map.put(key2, "justin ���T��"); + map.put(key1, "caterpillar 的訊息"); + map.put(key2, "justin 的訊息"); System.out.println(map.get(key1)); System.out.println(map.get(key2)); diff --git a/example/CH13/HashMapDemo2.java b/example/CH13/HashMapDemo2.java index 1bbf1fc..9f99a4e 100644 --- a/example/CH13/HashMapDemo2.java +++ b/example/CH13/HashMapDemo2.java @@ -7,9 +7,9 @@ public static void main(String[] args) { Map map = new HashMap(); - map.put("justin", "justin ���T��"); - map.put("momor", "momor ���T��"); - map.put("caterpillar", "caterpillar ���T��"); + map.put("justin", "justin 的訊息"); + map.put("momor", "momor 的訊息"); + map.put("caterpillar", "caterpillar 的訊息"); Collection collection = map.values(); Iterator iterator = collection.iterator(); @@ -18,7 +18,7 @@ public static void main(String[] args) { } System.out.println(); - // �ƹ�W�]�i�H�ϥμW�j�� for �j�� + // 事實上也可以使用增強的 for 迴圈 for(String value : map.values()) { System.out.println(value); } diff --git a/example/CH13/HashSetDemo.java b/example/CH13/HashSetDemo.java index 582dcfe..02e036f 100644 --- a/example/CH13/HashSetDemo.java +++ b/example/CH13/HashSetDemo.java @@ -9,10 +9,10 @@ public static void main(String[] args) { set.add("caterpillar"); set.add("momor"); set.add("bush"); - // �G�N�[�J���Ъ����� + // 故意加入重覆的物件 set.add("caterpillar"); - // �ϥ� Iterator ��ܪ��� + // 使用 Iterator 顯示物件 Iterator iterator = set.iterator(); while(iterator.hasNext()) { System.out.print(iterator.next() + " "); @@ -20,7 +20,7 @@ public static void main(String[] args) { System.out.println(); set.remove("bush"); - // �ϥ� enhanced for loop ��ܪ��� + // 使用 enhanced for loop 顯示物件 for(String name : set) { System.out.print(name + " "); } diff --git a/example/CH13/IteratorDemo.java b/example/CH13/IteratorDemo.java index fb296a9..7f9e86a 100644 --- a/example/CH13/IteratorDemo.java +++ b/example/CH13/IteratorDemo.java @@ -8,7 +8,7 @@ public static void main(String[] args) { List list = new ArrayList(); - System.out.println("��J�W��(��Jquit����)"); + System.out.println("輸入名稱(輸入quit結束)"); while(true) { System.out.print("# "); String input = scanner.next(); @@ -18,10 +18,10 @@ public static void main(String[] args) { list.add(input); } - // �ϥ� Iterator ���o���� + // 使用 Iterator 取得元素 Iterator iterator = list.iterator(); - while(iterator.hasNext()) { // �٦��U�@�Ӥ����ܡH - // �ϥ� next() ���o�U�@�Ӥ��� + while(iterator.hasNext()) { // 還有下一個元素嗎? + // 使用 next() 取得下一個元素 System.out.print(iterator.next() + " "); } diff --git a/example/CH13/LinkedHashMapDemo.java b/example/CH13/LinkedHashMapDemo.java index 5cdfcfc..753a896 100644 --- a/example/CH13/LinkedHashMapDemo.java +++ b/example/CH13/LinkedHashMapDemo.java @@ -7,9 +7,9 @@ public static void main(String[] args) { Map map = new LinkedHashMap(); - map.put("justin", "justin ���T��"); - map.put("momor", "momor ���T��"); - map.put("caterpillar", "caterpillar ���T��"); + map.put("justin", "justin 的訊息"); + map.put("momor", "momor 的訊息"); + map.put("caterpillar", "caterpillar 的訊息"); for(String value : map.values()) { System.out.println(value); diff --git a/example/CH13/LinkedHashSetDemo.java b/example/CH13/LinkedHashSetDemo.java index cdd8f07..f521ee8 100644 --- a/example/CH13/LinkedHashSetDemo.java +++ b/example/CH13/LinkedHashSetDemo.java @@ -10,7 +10,7 @@ public static void main(String[] args) { set.add("momor"); set.add("bush"); - // �ϥ� enhanced for loop ��ܪ��� + // 使用 enhanced for loop 顯示物件 for(String name : set) { System.out.print(name + " "); } diff --git a/example/CH13/QueueDemo.java b/example/CH13/QueueDemo.java index 38a2b6f..d37d6a8 100644 --- a/example/CH13/QueueDemo.java +++ b/example/CH13/QueueDemo.java @@ -7,7 +7,7 @@ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Queue queue = new LinkedList(); - System.out.println("��J�W��(�ϥ�quit����)"); + System.out.println("輸入名稱(使用quit結束)"); while(true) { System.out.print("# "); @@ -15,13 +15,13 @@ public static void main(String[] args) { if(input.equals("quit")) break; - // offer()�G�[�J�����ܦ�C�� + // offer():加入元素至佇列中 queue.offer(input); } - System.out.print("��ܿ�J: "); + System.out.print("顯示輸入: "); String element = null; - // poll()�G���o�ò��h��C�������� + // poll():取得並移去佇列中的元素 while((element = queue.poll()) != null) { System.out.print(element + " "); } diff --git a/example/CH13/StringQueueDemo.java b/example/CH13/StringQueueDemo.java index 0762596..fb49e16 100644 --- a/example/CH13/StringQueueDemo.java +++ b/example/CH13/StringQueueDemo.java @@ -8,7 +8,7 @@ public static void main(String[] args) { StringQueue queue = new StringQueue(); - System.out.println("��J�W��(�ϥ�quit����)"); + System.out.println("輸入名稱(使用quit結束)"); while(true) { System.out.print("# "); @@ -19,7 +19,7 @@ public static void main(String[] args) { queue.put(input); } - System.out.print("��ܿ�J: "); + System.out.print("顯示輸入: "); while(!queue.isEmpty()) { System.out.print(queue.get() + " "); } diff --git a/example/CH13/StringStack.java b/example/CH13/StringStack.java index c3e4c18..82dacd1 100644 --- a/example/CH13/StringStack.java +++ b/example/CH13/StringStack.java @@ -10,22 +10,22 @@ public StringStack() { } public void push(String name) { - // �N�����[�J��C�e�� + // 將元素加入串列前端 linkedList.addFirst(name); } public String top() { - // ���o��C�Ĥ@�Ӥ��� + // 取得串列第一個元素 return linkedList.getFirst(); } public String pop() { - // ���X�Ĥ@�Ӥ��� + // 移出第一個元素 return linkedList.removeFirst(); } public boolean isEmpty() { - // ��C�O�_���� + // 串列是否為空 return linkedList.isEmpty(); } } \ No newline at end of file diff --git a/example/CH13/StringStackDemo.java b/example/CH13/StringStackDemo.java index 7a4ee5e..c817f04 100644 --- a/example/CH13/StringStackDemo.java +++ b/example/CH13/StringStackDemo.java @@ -8,7 +8,7 @@ public static void main(String[] args) { StringStack stack = new StringStack(); - System.out.println("��J�W��(�ϥ�quit����)"); + System.out.println("輸入名稱(使用quit結束)"); while(true) { System.out.print("# "); @@ -19,7 +19,7 @@ public static void main(String[] args) { stack.push(input); } - System.out.print("��ܿ�J: "); + System.out.print("顯示輸入: "); while(!stack.isEmpty()) { System.out.print(stack.pop() + " "); } diff --git a/example/CH13/TreeMapDemo.java b/example/CH13/TreeMapDemo.java index 4aef835..379502d 100644 --- a/example/CH13/TreeMapDemo.java +++ b/example/CH13/TreeMapDemo.java @@ -7,9 +7,9 @@ public static void main(String[] args) { Map map = new TreeMap(); - map.put("justin", "justin ���T��"); - map.put("momor", "momor ���T��"); - map.put("caterpillar", "caterpillar ���T��"); + map.put("justin", "justin 的訊息"); + map.put("momor", "momor 的訊息"); + map.put("caterpillar", "caterpillar 的訊息"); for(String value : map.values()) { System.out.println(value); diff --git a/example/CH13/TreeMapDemo2.java b/example/CH13/TreeMapDemo2.java index d588929..4ecc678 100644 --- a/example/CH13/TreeMapDemo2.java +++ b/example/CH13/TreeMapDemo2.java @@ -9,9 +9,9 @@ public static void main(String[] args) { Map map = new TreeMap(comparator); - map.put("justin", "justin ���T��"); - map.put("momor", "momor ���T��"); - map.put("caterpillar", "caterpillar ���T��"); + map.put("justin", "justin 的訊息"); + map.put("momor", "momor 的訊息"); + map.put("caterpillar", "caterpillar 的訊息"); for(String value : map.values()) { System.out.println(value); diff --git a/example/CH13/TreeSetDemo.java b/example/CH13/TreeSetDemo.java index 4d7cd92..a4877ba 100644 --- a/example/CH13/TreeSetDemo.java +++ b/example/CH13/TreeSetDemo.java @@ -10,7 +10,7 @@ public static void main(String[] args) { set.add("caterpillar"); set.add("momor"); - // �ϥ� enhanced for loop ��ܪ��� + // 使用 enhanced for loop 顯示物件 for(String name : set) { System.out.print(name + " "); } diff --git a/example/CH13/TreeSetDemo2.java b/example/CH13/TreeSetDemo2.java index 595ed3f..0ade833 100644 --- a/example/CH13/TreeSetDemo2.java +++ b/example/CH13/TreeSetDemo2.java @@ -4,7 +4,7 @@ public class TreeSetDemo2 { public static void main(String[] args) { - // �ۭqComparator + // 自訂Comparator Comparator comparator = new CustomComparator(); Set set = @@ -14,7 +14,7 @@ public static void main(String[] args) { set.add("caterpillar"); set.add("momor"); - // �ϥ� enhanced for loop ��ܪ��� + // 使用 enhanced for loop 顯示物件 for(String name : set) { System.out.print(name + " "); } diff --git a/example/CH14/BufferedReaderWriterDemo.java b/example/CH14/BufferedReaderWriterDemo.java index 9b98802..9d94f80 100644 --- a/example/CH14/BufferedReaderWriterDemo.java +++ b/example/CH14/BufferedReaderWriterDemo.java @@ -5,21 +5,21 @@ public class BufferedReaderWriterDemo { public static void main(String[] args) { try { - // �w��System.in��J��y + // 緩衝System.in輸入串流 BufferedReader bufReader = new BufferedReader( new InputStreamReader(System.in)); - // �w��FileWriter�r����X��y + // 緩衝FileWriter字元輸出串流 BufferedWriter bufWriter = new BufferedWriter(new FileWriter(args[0])); String input = null; - // �CŪ�@��i��@���g�J�ʧ@ + // 每讀一行進行一次寫入動作 while(!(input = bufReader.readLine()).equals("quit")) { bufWriter.write(input); - // newLine()��k�g�J�P�@�~�t�ά̪ۨ�����r�� + // newLine()方法寫入與作業系統相依的換行字元 bufWriter.newLine(); } @@ -27,7 +27,7 @@ public static void main(String[] args) { bufWriter.close(); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�S�����w�ɮ�"); + System.out.println("沒有指定檔案"); } catch(IOException e) { e.printStackTrace(); diff --git a/example/CH14/BufferedStreamDemo.java b/example/CH14/BufferedStreamDemo.java index 2920d54..d15cd0a 100644 --- a/example/CH14/BufferedStreamDemo.java +++ b/example/CH14/BufferedStreamDemo.java @@ -17,21 +17,21 @@ public static void main(String[] args) { new BufferedOutputStream( new FileOutputStream(desFile)); - System.out.println("�ƻs�ɮסG" + - srcFile.length() + "�줸��"); + System.out.println("複製檔案:" + + srcFile.length() + "位元組"); while(bufferedInputStream.read(data) != -1) { bufferedOutputStream.write(data); } - // �N�w�İϤ�����ƥ����g�X + // 將緩衝區中的資料全部寫出 bufferedOutputStream.flush(); - // ������y + // 關閉串流 bufferedInputStream.close(); bufferedOutputStream.close(); - System.out.println("�ƻs����"); + System.out.println("複製完成"); } catch(ArrayIndexOutOfBoundsException e) { System.out.println( diff --git a/example/CH14/ByteArrayStreamDemo.java b/example/CH14/ByteArrayStreamDemo.java index fbc7f1e..dadc972 100644 --- a/example/CH14/ByteArrayStreamDemo.java +++ b/example/CH14/ByteArrayStreamDemo.java @@ -16,30 +16,30 @@ public static void main(String[] args) { byte[] bytes = new byte[1]; - // �N�ɮפ��e�g�J�줸�}�C��y + // 將檔案內容寫入位元陣列串流 while(bufferedInputStream.read(bytes) != -1) { arrayOutputStream.write(bytes); } arrayOutputStream.close(); bufferedInputStream.close(); - // �H�r���覡��ܦ줸�}�C���e + // 以字元方式顯示位元陣列內容 bytes = arrayOutputStream.toByteArray(); for(int i = 0; i < bytes.length; i++) { System.out.print((char) bytes[i]); } System.out.println(); - // ���ϥΪ̿�J��m�P�r���ק�줸�}�C���e + // 讓使用者輸入位置與字元修改位元陣列內容 Scanner scanner = new Scanner(System.in); - System.out.print("��J�ק��m�G"); + System.out.print("輸入修改位置:"); int pos = scanner.nextInt(); - System.out.print("��J�ק�r���G"); - // �ק�}�C���������r�� + System.out.print("輸入修改字元:"); + // 修改陣列中對應的字元 bytes[pos-1] = (byte) scanner.next().charAt(0); - // �N�줸�}�C���e�s�^�ɮ� + // 將位元陣列內容存回檔案 ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); BufferedOutputStream bufOutputStream = @@ -53,7 +53,7 @@ public static void main(String[] args) { bufOutputStream.close(); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�Ы��w�ɮצW��"); + System.out.println("請指定檔案名稱"); } catch(IOException e) { e.printStackTrace(); diff --git a/example/CH14/CharArrayReaderWriterDemo.java b/example/CH14/CharArrayReaderWriterDemo.java index deac40e..58928ca 100644 --- a/example/CH14/CharArrayReaderWriterDemo.java +++ b/example/CH14/CharArrayReaderWriterDemo.java @@ -11,7 +11,7 @@ public static void main(String[] args) { new BufferedReader( new FileReader(file)); - // �N�ɮ�Ū�J�r���}�C + // 將檔案讀入字元陣列 CharArrayWriter charArrayWriter = new CharArrayWriter(); char[] array = new char[1]; @@ -22,22 +22,22 @@ public static void main(String[] args) { charArrayWriter.close(); bufInputReader.close(); - // ��ܦr���}�C���e + // 顯示字元陣列內容 array = charArrayWriter.toCharArray(); for(int i = 0; i < array.length; i++) System.out.print(array[i] + " "); System.out.println(); - // ���ϥΪ̿�J��m�P�r���ק�r���}�C���e + // 讓使用者輸入位置與字元修改字元陣列內容 Scanner scanner = new Scanner(System.in); - System.out.print("��J�ק��m�G"); + System.out.print("輸入修改位置:"); int pos = scanner.nextInt(); - System.out.print("��J�ק�r���G"); + System.out.print("輸入修改字元:"); char ch = scanner.next().charAt(0); array[pos-1] = ch; - // �N�r���}�C���e�s�^�ɮ� + // 將字元陣列內容存回檔案 CharArrayReader charArrayReader = new CharArrayReader(array); BufferedWriter bufWriter = @@ -53,7 +53,7 @@ public static void main(String[] args) { bufWriter.close(); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�S�����w�ɮ�"); + System.out.println("沒有指定檔案"); } catch(IOException e) { e.printStackTrace(); diff --git a/example/CH14/DataStreamDemo.java b/example/CH14/DataStreamDemo.java index 0a66bc2..885ac92 100644 --- a/example/CH14/DataStreamDemo.java +++ b/example/CH14/DataStreamDemo.java @@ -13,31 +13,31 @@ public static void main(String[] args) { new FileOutputStream(args[0])); for(Member member : members) { - // �g�JUTF�r�� + // 寫入UTF字串 dataOutputStream.writeUTF(member.getName()); - // �g�Jint��� + // 寫入int資料 dataOutputStream.writeInt(member.getAge()); } - // �X�M�Ҧ���Ʀܥت��a + // 出清所有資料至目的地 dataOutputStream.flush(); - // ������y + // 關閉串流 dataOutputStream.close(); DataInputStream dataInputStream = new DataInputStream( new FileInputStream(args[0])); - // Ū�X��ƨ��٭쬰���� + // 讀出資料並還原為物件 for(int i = 0; i < members.length; i++) { - // Ū�XUTF�r�� + // 讀出UTF字串 String name = dataInputStream.readUTF(); - // Ū�Xint��� + // 讀出int資料 int score = dataInputStream.readInt(); members[i] = new Member(name, score); } - // ������y + // 關閉串流 dataInputStream.close(); - // ����٭�᪺��� + // 顯示還原後的資料 for(Member member : members) { System.out.printf("%s\t%d%n", member.getName(), member.getAge()); } diff --git a/example/CH14/FileDemo.java b/example/CH14/FileDemo.java index 615eea5..5454862 100644 --- a/example/CH14/FileDemo.java +++ b/example/CH14/FileDemo.java @@ -7,34 +7,34 @@ public class FileDemo { public static void main(String[] args) { try { File file = new File(args[0]); - if(file.isFile()) { // �O�_���ɮ� - System.out.println(args[0] + " �ɮ�"); + if(file.isFile()) { // 是否為檔案 + System.out.println(args[0] + " 檔案"); System.out.print( - file.canRead() ? "�iŪ " : "���iŪ "); + file.canRead() ? "可讀 " : "不可讀 "); System.out.print( - file.canWrite() ? "�i�g " : "���i�g "); + file.canWrite() ? "可寫 " : "不可寫 "); System.out.println( - file.length() + "�줸��"); + file.length() + "位元組"); } else { - // �C�X�Ҧ����ɮפΥؿ� + // 列出所有的檔案及目錄 File[] files = file.listFiles(); ArrayList fileList = new ArrayList(); for(int i = 0; i < files.length; i++) { - // ���C�X�ؿ� - if(files[i].isDirectory()) { //�O�_���ؿ� - // ���o���|�W + // 先列出目錄 + if(files[i].isDirectory()) { //是否為目錄 + // 取得路徑名 System.out.println("[" + files[i].getPath() + "]"); } else { - // �ɮץ��s�JfileList�A�ݷ|�A�C�X + // 檔案先存入fileList,待會再列出 fileList.add(files[i]); } } - // �C�X�ɮ� + // 列出檔案 for(File f: fileList) { System.out.println(f.toString()); } diff --git a/example/CH14/FileReaderWriterDemo.java b/example/CH14/FileReaderWriterDemo.java index 42bf0ef..ab3f27d 100644 --- a/example/CH14/FileReaderWriterDemo.java +++ b/example/CH14/FileReaderWriterDemo.java @@ -14,7 +14,7 @@ public static void main(String[] args) { char[] wlnChar = {'\r', '\n'}; while((in = fileReader.read()) != -1) { if(in == '\n') { - // �g�J"\r\n" + // 寫入"\r\n" fileWriter.write(wlnChar); } else @@ -24,7 +24,7 @@ public static void main(String[] args) { fileWriter.close(); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�Ы��w�ɮ�"); + System.out.println("請指定檔案"); } catch(IOException e) { e.printStackTrace(); diff --git a/example/CH14/FileStreamDemo.java b/example/CH14/FileStreamDemo.java index 1c5a28c..43e10bc 100644 --- a/example/CH14/FileStreamDemo.java +++ b/example/CH14/FileStreamDemo.java @@ -7,21 +7,21 @@ public static void main(String[] args) { try { byte[] buffer = new byte[1024]; - // �ӷ��ɮ� + // 來源檔案 FileInputStream fileInputStream = new FileInputStream(new File(args[0])); - // �ت��ɮ� + // 目的檔案 FileOutputStream fileOutputStream = new FileOutputStream(new File(args[1])); - // available()�i���o��Ū������ƪ��� - System.out.println("�ƻs�ɮסG" + - fileInputStream.available() + "�줸��"); + // available()可取得未讀取的資料長度 + System.out.println("複製檔案:" + + fileInputStream.available() + "位元組"); while(true) { if(fileInputStream.available() < 1024) { - // �Ѿl����Ƥ�1024�줸�դ� - // �@�줸�@�줸Ū�X�A�g�J�ت��ɮ� + // 剩餘的資料比1024位元組少 + // 一位元一位元讀出再寫入目的檔案 int remain = -1; while((remain = fileInputStream.read()) != -1) { @@ -30,18 +30,18 @@ public static void main(String[] args) { break; } else { - // �q�ӷ��ɮ�Ū����Ʀܽw�İ� + // 從來源檔案讀取資料至緩衝區 fileInputStream.read(buffer); - // �N�}�C��Ƽg�J�ت��ɮ� + // 將陣列資料寫入目的檔案 fileOutputStream.write(buffer); } } - // ������y + // 關閉串流 fileInputStream.close(); fileOutputStream.close(); - System.out.println("�ƻs����"); + System.out.println("複製完成"); } catch(ArrayIndexOutOfBoundsException e) { System.out.println( diff --git a/example/CH14/ObjectStreamDemo.java b/example/CH14/ObjectStreamDemo.java index f83a9d6..ebde866 100644 --- a/example/CH14/ObjectStreamDemo.java +++ b/example/CH14/ObjectStreamDemo.java @@ -7,13 +7,13 @@ public class ObjectStreamDemo { public static void main(String[] args) { User[] users = {new User("cater", 101), new User("justin", 102)}; - // �g�J�s�� + // 寫入新檔 writeObjectsToFile(users, args[0]); try { - // Ū���ɮ׸�� + // 讀取檔案資料 users = readObjectsFromFile(args[0]); - // ���Ū�^������ + // 顯示讀回的物件 for(User user : users) { System.out.printf("%s\t%d%n", user.getName(), user.getNumber()); } @@ -23,25 +23,25 @@ public static void main(String[] args) { users[0] = new User("momor", 103); users[1] = new User("becky", 104); - // ���[�s������ɮ� + // 附加新物件至檔案 appendObjectsToFile(users, args[0]); - // Ū���ɮ׸�� + // 讀取檔案資料 users = readObjectsFromFile(args[0]); - // ���Ū�^������ + // 顯示讀回的物件 for(User user : users) { System.out.printf("%s\t%d%n", user.getName(), user.getNumber()); } } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�S�����w�ɦW"); + System.out.println("沒有指定檔名"); } catch(FileNotFoundException e) { e.printStackTrace(); } } - // �N���w������g�J�ܫ��w���ɮ� + // 將指定的物件寫入至指定的檔案 public static void writeObjectsToFile( Object[] objs, String filename) { File file = new File(filename); @@ -51,10 +51,10 @@ public static void writeObjectsToFile( new ObjectOutputStream( new FileOutputStream(file)); for(Object obj : objs) { - // �N����g�J�ɮ� + // 將物件寫入檔案 objOutputStream.writeObject(obj); } - // ������y + // 關閉串流 objOutputStream.close(); } catch(IOException e) { @@ -62,17 +62,17 @@ public static void writeObjectsToFile( } } - // �N���w�ɮפ���������Ū�^ + // 將指定檔案中的物件資料讀回 public static User[] readObjectsFromFile( String filename) throws FileNotFoundException { File file = new File(filename); - // �p�G�ɮפ��s�b�N��X�ҥ~ + // 如果檔案不存在就丟出例外 if(!file.exists()) throw new FileNotFoundException(); - // �ϥ�List���x�sŪ�^������ + // 使用List先儲存讀回的物件 List list = new ArrayList(); try { @@ -97,30 +97,30 @@ public static User[] readObjectsFromFile( return list.toArray(users); } - // �N������[�ܫ��w���ɮפ��� + // 將物件附加至指定的檔案之後 public static void appendObjectsToFile( Object[] objs, String filename) throws FileNotFoundException { File file = new File(filename); - // �p�G�ɮפ��s�b�h��X�ҥ~ + // 如果檔案不存在則丟出例外 if(!file.exists()) throw new FileNotFoundException(); try { - // ���[�Ҧ� + // 附加模式 ObjectOutputStream objOutputStream = new ObjectOutputStream( new FileOutputStream(file, true)) { - // �p�G�n���[������ɮ׫� - // �������s�w�q�o�Ӥ�k + // 如果要附加物件至檔案後 + // 必須重新定義這個方法 protected void writeStreamHeader() throws IOException {} }; for(Object obj : objs) { - // �N����g�J�ɮ� + // 將物件寫入檔案 objOutputStream.writeObject(obj); } objOutputStream.close(); diff --git a/example/CH14/PushbackReaderDemo.java b/example/CH14/PushbackReaderDemo.java index 332c796..c9d5215 100644 --- a/example/CH14/PushbackReaderDemo.java +++ b/example/CH14/PushbackReaderDemo.java @@ -4,9 +4,9 @@ public class PushbackReaderDemo { public static void main(String[] args) { - char[] symbols = {'��', '��', - '��', '��', - '��', '��'}; + char[] symbols = {'<', '>', + '≦', '≧', + '≠', '='}; try { PushbackReader pushbackReader = @@ -50,7 +50,7 @@ public static void main(String[] args) { fileWriter.close(); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�Ы��w�ɮ�"); + System.out.println("請指定檔案"); } catch(IOException e) { e.printStackTrace(); diff --git a/example/CH14/PushbackStreamDemo.java b/example/CH14/PushbackStreamDemo.java index 1672ad2..f738f41 100644 --- a/example/CH14/PushbackStreamDemo.java +++ b/example/CH14/PushbackStreamDemo.java @@ -14,20 +14,20 @@ public static void main(String[] args) { while((count = pushbackInputStream.read(array)) != -1) { - // ��Ӧ줸���ഫ����� + // 兩個位元組轉換為整數 tmp = (short)((array[0] << 8) | (array[1] & 0xff)); tmp = tmp & 0xFFFF; - // �P�_�O�_��BIG5�A�p�G�O�h���BIG5����r + // 判斷是否為BIG5,如果是則顯示BIG5中文字 if(tmp >= 0xA440 && tmp < 0xFFFF) { System.out.println("BIG5: " + new String(array)); } else { - // �N�ĤG�Ӧ줸�ձ��^��y + // 將第二個位元組推回串流 pushbackInputStream.unread(array, 1, 1); - // ���ASCII�d�򪺦r�� + // 顯示ASCII範圍的字元 System.out.println("ASCII: " + (char)array[0]); } @@ -36,7 +36,7 @@ public static void main(String[] args) { pushbackInputStream.close(); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�Ы��w�ɮצW��"); + System.out.println("請指定檔案名稱"); } catch(IOException e) { e.printStackTrace(); diff --git a/example/CH14/RandomAccessFileDemo.java b/example/CH14/RandomAccessFileDemo.java index 7c5b9b3..bd9651f 100644 --- a/example/CH14/RandomAccessFileDemo.java +++ b/example/CH14/RandomAccessFileDemo.java @@ -13,38 +13,38 @@ public static void main(String[] args) { try { File file = new File(args[0]); - // �إ�RandomAccessFile��ҨåHŪ�g�Ҧ��}���ɮ� + // 建立RandomAccessFile實例並以讀寫模式開啟檔案 RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); for(int i = 0; i < students.length; i++) { - // �ϥι�����write��k�g�J��� + // 使用對應的write方法寫入資料 randomAccessFile.writeChars(students[i].getName()); randomAccessFile.writeInt(students[i].getScore()); } Scanner scanner = new Scanner(System.in); - System.out.print("Ū���ĴX����ơH"); + System.out.print("讀取第幾筆資料?"); int num = scanner.nextInt(); - // �ϥ�seek()��k�ާ@�s����m + // 使用seek()方法操作存取位置 randomAccessFile.seek((num-1) * Student.size()); Student student = new Student(); - // �ϥι�����read��kŪ�X��� + // 使用對應的read方法讀出資料 student.setName(readName(randomAccessFile)); student.setScore(randomAccessFile.readInt()); - System.out.println("�m�W�G" + student.getName()); - System.out.println("���ơG" + student.getScore()); + System.out.println("姓名:" + student.getName()); + System.out.println("分數:" + student.getScore()); - // �]�w�����ɮ� + // 設定關閉檔案 randomAccessFile.close(); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�Ы��w�ɮצW��"); + System.out.println("請指定檔案名稱"); } catch(IOException e) { e.printStackTrace(); @@ -59,7 +59,7 @@ private static String readName( for(int i = 0; i < name.length; i++) name[i] = randomAccessfile.readChar(); - // �N�Ŧr�����N���ťզr���öǦ^ + // 將空字元取代為空白字元並傳回 return new String(name).replace('\0', ' '); } } \ No newline at end of file diff --git a/example/CH14/ReaderDemo.java b/example/CH14/ReaderDemo.java index 8cde30f..2dd4500 100644 --- a/example/CH14/ReaderDemo.java +++ b/example/CH14/ReaderDemo.java @@ -13,7 +13,7 @@ public static void main(String[] args) { ByteArrayInputStream byteArrayStream = new ByteArrayInputStream(array); - // reader�|�q�wŪ���줸�}�C�����X��� + // reader會從已讀的位元陣列中取出資料 InputStreamReader reader = new InputStreamReader(byteArrayStream); @@ -22,23 +22,23 @@ public static void main(String[] args) { while((count = pushbackInputStream.read(array)) != -1) { - // ��Ӧ줸���ഫ����� + // 兩個位元組轉換為整數 tmp = (short)((array[0] << 8) | (array[1] & 0xff)); tmp = tmp & 0xFFFF; - // �P�_�O�_��BIG5�A�p�G�O�h���BIG5����r + // 判斷是否為BIG5,如果是則顯示BIG5中文字 if(tmp >= 0xA440 && tmp < 0xFFFF) { System.out.println("BIG5: " + (char)reader.read()); - // ���mArrayInputStream��Ū����� - // �U��reader�~�|�A���YŪ����� + // 重置ArrayInputStream的讀取游標 + // 下次reader才會再重頭讀取資料 byteArrayStream.reset(); } else { - // �N�ĤG�Ӧ줸�ձ��^��y + // 將第二個位元組推回串流 pushbackInputStream.unread(array, 1, 1); - // ���ASCII�d�򪺦r�� + // 顯示ASCII範圍的字元 System.out.println("ASCII: " + (char)array[0]); } @@ -47,7 +47,7 @@ public static void main(String[] args) { pushbackInputStream.close(); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�Ы��w�ɮצW��"); + System.out.println("請指定檔案名稱"); } catch(IOException e) { e.printStackTrace(); diff --git a/example/CH14/SequenceStreamDemo.java b/example/CH14/SequenceStreamDemo.java index 68fcd23..21581c5 100644 --- a/example/CH14/SequenceStreamDemo.java +++ b/example/CH14/SequenceStreamDemo.java @@ -6,18 +6,18 @@ public class SequenceStreamDemo { public static void main(String[] args) { try { - // args[0]: ���w���Ρ]s�^�γs���]c�^ + // args[0]: 指定分割(s)或連接(c) switch (args[0].charAt(1)) { case 's': - // args[1]: �C�Ӥ����ɮת��j�p + // args[1]: 每個分割檔案的大小 int size = Integer.parseInt(args[1]); - // args[2]: ���w�n�Q���Ϊ��ɮצW�� + // args[2]: 指定要被分割的檔案名稱 seperate(args[2], size); break; case 'c': - // args[1]: ���w�n�Q�զX���ɮ׭Ӽ� + // args[1]: 指定要被組合的檔案個數 int number = Integer.parseInt(args[1]); - // args[2]: �զX�᪺�ɮצW�� + // args[2]: 組合後的檔案名稱 concatenate(args[2], number); break; } @@ -26,14 +26,14 @@ public static void main(String[] args) { System.out.println( "Using: java UseSequenceStream [-s/-c]" + " (size/number) filename"); - System.out.println("-s: �����ɮ�\n-c: �զX�ɮ�"); + System.out.println("-s: 分割檔案\n-c: 組合檔案"); } catch(IOException e) { e.printStackTrace(); } } - // �����ɮ� + // 分割檔案 public static void seperate(String filename, int size) throws IOException { FileInputStream fileInputStream = @@ -43,17 +43,17 @@ public static void seperate(String filename, int size) byte[] data = new byte[1]; int count = 0; - // �q���ɮפj�p�Ϋ��w���Ϊ��j�p - // �M�w�n���ά��X���ɮ� + // 從原檔案大小及指定分割的大小 + // 決定要分割為幾個檔案 if(fileInputStream.available() % size == 0) count = fileInputStream.available() / size; else count = fileInputStream.available() / size + 1; - // �}�l�i����� + // 開始進行分割 for(int i = 0; i < count; i++) { int num = 0; - // ���Ϊ��ɮץ[�W���u�P�s�� + // 分割的檔案加上底線與編號 File file = new File(filename + "_" + (i + 1)); BufferedOutputStream bufOutputStream = new BufferedOutputStream( @@ -62,7 +62,7 @@ public static void seperate(String filename, int size) while(bufInputStream.read(data) != -1) { bufOutputStream.write(data); num++; - if(num == size) { // ���ΥX�@���ɮ� + if(num == size) { // 分割出一個檔案 bufOutputStream.flush(); bufOutputStream.close(); break; @@ -75,25 +75,25 @@ public static void seperate(String filename, int size) } } - System.out.println("���ά�" + count + "���ɮ�"); + System.out.println("分割為" + count + "個檔案"); } - // �s���ɮ� + // 連接檔案 public static void concatenate(String filename, int number) throws IOException { - // �����ɮץΪ�List + // 收集檔案用的List List list = new ArrayList(); for(int i = 0; i < number; i++) { - // �ɮצW���������u�[�W�s�� + // 檔案名必須為底線加上編號 File file = new File(filename + "_" + (i+1)); list.add(i, new FileInputStream(file)); } final Iterator iterator = list.iterator(); - // SequenceInputStream �ݭn�@��Enumeration����ӫغc + // SequenceInputStream 需要一個Enumeration物件來建構 Enumeration enumation = new Enumeration() { public boolean hasMoreElements() { @@ -105,8 +105,8 @@ public InputStream nextElement() { } }; - // �إ�SequenceInputStream - // �èϥ�BufferedInputStream + // 建立SequenceInputStream + // 並使用BufferedInputStream BufferedInputStream bufInputStream = new BufferedInputStream( new SequenceInputStream(enumation), @@ -117,13 +117,13 @@ public InputStream nextElement() { new FileOutputStream(filename), 8192); byte[] data = new byte[1]; - // Ū���Ҧ��ɮ׸�ƨüg�J�ت��a�ɮ� + // 讀取所有檔案資料並寫入目的地檔案 while(bufInputStream.read(data) != -1) bufOutputStream.write(data); bufInputStream.close(); bufOutputStream.flush(); bufOutputStream.close(); - System.out.println("�զX" + number + "���ɮ� OK!!"); + System.out.println("組合" + number + "個檔案 OK!!"); } } \ No newline at end of file diff --git a/example/CH14/StreamDemo.java b/example/CH14/StreamDemo.java index 67b8233..cb602af 100644 --- a/example/CH14/StreamDemo.java +++ b/example/CH14/StreamDemo.java @@ -5,8 +5,8 @@ public class StreamDemo { public static void main(String[] args) { try { - System.out.print("��J�r��: "); - System.out.println("��J�r���Q�i�����: " + + System.out.print("輸入字元: "); + System.out.println("輸入字元十進位表示: " + System.in.read()); } catch(IOException e) { diff --git a/example/CH14/StreamReaderWriterDemo.java b/example/CH14/StreamReaderWriterDemo.java index 7cf55b9..085751b 100644 --- a/example/CH14/StreamReaderWriterDemo.java +++ b/example/CH14/StreamReaderWriterDemo.java @@ -7,18 +7,18 @@ public static void main(String[] args) { try { FileInputStream fileInputStream = new FileInputStream(args[0]); - // ��FileInputStream�[�W�r���B�z�\�� + // 為FileInputStream加上字元處理功能 InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream); FileOutputStream fileOutputStream = new FileOutputStream("backup_" + args[0]); - // ��FileOutputStream�[�W�r���B�z�\�� + // 為FileOutputStream加上字元處理功能 OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream); int ch = 0; - // �H�r���覡����ɮפ��e + // 以字元方式顯示檔案內容 while((ch = inputStreamReader.read()) != -1) { System.out.print((char) ch); outputStreamWriter.write(ch); @@ -29,7 +29,7 @@ public static void main(String[] args) { outputStreamWriter.close(); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�S�����w�ɮ�"); + System.out.println("沒有指定檔案"); } catch(IOException e) { e.printStackTrace(); diff --git a/example/CH14/StreamWriterDemo.java b/example/CH14/StreamWriterDemo.java index d8b7c47..4abcf88 100644 --- a/example/CH14/StreamWriterDemo.java +++ b/example/CH14/StreamWriterDemo.java @@ -5,19 +5,19 @@ public class StreamWriterDemo { public static void main(String[] args) { try { - // �u²�餤��v�|�Ӧr�� GB2312 �s�X + // 「簡體中文」四個字的 GB2312 編碼 byte[] sim = {(byte)0xbc, (byte)0xf2, (byte)0xcc, (byte)0xe5, (byte)0xd6, (byte)0xd0, (byte)0xce, (byte)0xc4}; - // �}�C�@����y�ӷ� + // 陣列作為串流來源 ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(sim); InputStreamReader inputStreamReader = new InputStreamReader( byteArrayInputStream, "GB2312"); - // PrintWriter�ٱ���Writer��ҧ@���޼� + // PrintWriter還接受Writer實例作為引數 PrintWriter printWriter = new PrintWriter( new OutputStreamWriter( @@ -26,7 +26,7 @@ public static void main(String[] args) { int in = 0; printWriter.print("PrintWriter: "); - // �g�J�}�C���e + // 寫入陣列內容 while((in = inputStreamReader.read()) != -1) { printWriter.print((char)in); } @@ -35,13 +35,13 @@ public static void main(String[] args) { printWriter.close(); byteArrayInputStream.reset(); - // PrintStream ����OutputStream��ҧ@���޼� + // PrintStream 接受OutputStream實例作為引數 PrintStream printStream = new PrintStream(new FileOutputStream(args[0], true), true, "GB2312"); printStream.print("PrintStream: "); - // �g�J�}�C���e + // 寫入陣列內容 while((in = inputStreamReader.read()) != -1) { printStream.print((char)in); } @@ -51,7 +51,7 @@ public static void main(String[] args) { printStream.close(); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�S�����w�ɮ�"); + System.out.println("沒有指定檔案"); } catch(IOException e) { e.printStackTrace(); diff --git a/example/CH14/Student.java b/example/CH14/Student.java index 0968d38..1609600 100644 --- a/example/CH14/Student.java +++ b/example/CH14/Student.java @@ -1,7 +1,7 @@ package onlyfun.caterpillar; public class Student { - private String name; // �T�w 15 �r�� + private String name; // 固定 15 字元 private int score; public Student() { @@ -35,7 +35,7 @@ public String getName() { public int getScore() { return score; } - // �C����ƩT�w�g�J34�줸�� + // 每筆資料固定寫入34位元組 public static int size() { return 34; } diff --git a/example/CH15/Clerk.java b/example/CH15/Clerk.java index b11a39c..6794030 100644 --- a/example/CH15/Clerk.java +++ b/example/CH15/Clerk.java @@ -1,14 +1,14 @@ package onlyfun.caterpillar; public class Clerk { - // -1 ���ܥثe�S�����~ + // -1 表示目前沒有產品 private int product = -1; - // �o�Ӥ�k�ѥͲ��̩I�s + // 這個方法由生產者呼叫 public synchronized void setProduct(int product) { if(this.product != -1) { try { - // �ثe�����S���Ŷ������~�A�еy�ԡI + // 目前店員沒有空間收產品,請稍候! wait(); } catch(InterruptedException e) { @@ -17,17 +17,17 @@ public synchronized void setProduct(int product) { } this.product = product; - System.out.printf("�Ͳ��̳]�w (%d)%n", this.product); + System.out.printf("生產者設定 (%d)%n", this.product); - // �q�����ݰϤ����@�Ӯ��O�̥i�H�~��u�@�F + // 通知等待區中的一個消費者可以繼續工作了 notify(); } - // �o�Ӥ�k�Ѯ��O�̩I�s + // 這個方法由消費者呼叫 public synchronized int getProduct() { if(this.product == -1) { try { - // �ʳf�F�A�еy�ԡI + // 缺貨了,請稍候! wait(); } catch(InterruptedException e) { @@ -37,10 +37,10 @@ public synchronized int getProduct() { int p = this.product; System.out.printf( - "���O�̨��� (%d)%n", this.product); + "消費者取走 (%d)%n", this.product); this.product = -1; - // �q�����ݰϤ����@�ӥͲ��̥i�H�~��u�@�F + // 通知等待區中的一個生產者可以繼續工作了 notify(); return p; diff --git a/example/CH15/Consumer.java b/example/CH15/Consumer.java index afc4024..3c842cc 100644 --- a/example/CH15/Consumer.java +++ b/example/CH15/Consumer.java @@ -9,19 +9,19 @@ public Consumer(Clerk clerk) { public void run() { System.out.println( - "���O�̶}�l���Ӿ��......"); + "消費者開始消耗整數......"); - // ����10�Ӿ�� + // 消耗10個整數 for(int i = 1; i <= 10; i++) { try { - // �����H���ɶ� + // 等待隨機時間 Thread.sleep((int) (Math.random() * 3000)); } catch(InterruptedException e) { e.printStackTrace(); } - // �q�����B������� + // 從店員處取走整數 clerk.getProduct(); } } diff --git a/example/CH15/DaemonThread.java b/example/CH15/DaemonThread.java index 875bd05..9a4145f 100644 --- a/example/CH15/DaemonThread.java +++ b/example/CH15/DaemonThread.java @@ -4,7 +4,7 @@ public class DaemonThread { public static void main(String[] args) { Thread thread = new Thread( - // �o�O�ΦW���O���g�k + // 這是匿名類別的寫法 new Runnable() { public void run() { while(true) { @@ -12,7 +12,7 @@ public void run() { } } }); - // �]�w��Daemon����� + // 設定為Daemon執行緒 thread.setDaemon(true); thread.start(); } diff --git a/example/CH15/Eraser.java b/example/CH15/Eraser.java index 055f695..b1a8ca4 100644 --- a/example/CH15/Eraser.java +++ b/example/CH15/Eraser.java @@ -13,7 +13,7 @@ public Eraser(char maskChar) { mask = "\010" + maskChar; } - // ���������ɳ]�w��false + // 停止執行緒時設定為false public void setActive(boolean active) { this.active = active; } @@ -22,12 +22,12 @@ public boolean isActive() { return active; } - // ���s�w�qrun()��k + // 重新定義run()方法 public void run () { while(isActive()) { System.out.print(mask); try { - // �Ȱ��ثe�������50�@�� + // 暫停目前的執行緒50毫秒 Thread.currentThread().sleep(50); } catch(InterruptedException e) { diff --git a/example/CH15/EraserDemo.java b/example/CH15/EraserDemo.java index dec73ef..6100991 100644 --- a/example/CH15/EraserDemo.java +++ b/example/CH15/EraserDemo.java @@ -7,15 +7,15 @@ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(true) { - System.out.print("��J�W�١G"); + System.out.print("輸入名稱:"); String name = scanner.next(); - System.out.print("��J�K�X�G "); + System.out.print("輸入密碼: "); - // Eraser��@Runnable���� + // Eraser實作Runnable介面 Eraser eraser = new Eraser('#'); - // �Ұ� Eraser ����� + // 啟動 Eraser 執行緒 Thread eraserThread = new Thread(eraser); eraserThread.start(); String password = scanner.next(); @@ -23,11 +23,11 @@ public static void main(String[] args) { if("caterpillar".equals(name) && "123456".equals(password)) { - System.out.println("�w�� caterpillar "); + System.out.println("歡迎 caterpillar "); break; } else { - System.out.printf("%s�A�W�٩αK�X���~�A�Э��s��J�I%n", name); + System.out.printf("%s,名稱或密碼錯誤,請重新輸入!%n", name); } } diff --git a/example/CH15/EraserThread.java b/example/CH15/EraserThread.java index d7405a8..c183de1 100644 --- a/example/CH15/EraserThread.java +++ b/example/CH15/EraserThread.java @@ -13,7 +13,7 @@ public EraserThread(char maskChar) { mask = "\010" + maskChar; } - // ���������ɳ]�w��false + // 停止執行緒時設定為false public void setActive(boolean active) { this.active = active; } @@ -22,12 +22,12 @@ public boolean isActive() { return active; } - // ���s�w�qrun()��k + // 重新定義run()方法 public void run () { while(isActive()) { System.out.print(mask); try { - // �Ȱ��ثe�������50�@�� + // 暫停目前的執行緒50毫秒 Thread.currentThread().sleep(50); } catch(InterruptedException e) { diff --git a/example/CH15/EraserThreadDemo.java b/example/CH15/EraserThreadDemo.java index fc846a5..7490bcd 100644 --- a/example/CH15/EraserThreadDemo.java +++ b/example/CH15/EraserThreadDemo.java @@ -7,11 +7,11 @@ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(true) { - System.out.print("��J�W�١G"); + System.out.print("輸入名稱:"); String name = scanner.next(); - System.out.print("��J�K�X�G "); - // �Ұ� Eraser ����� + System.out.print("輸入密碼: "); + // 啟動 Eraser 執行緒 EraserThread eraserThread = new EraserThread('#'); eraserThread.start(); String password = scanner.next(); @@ -19,11 +19,11 @@ public static void main(String[] args) { if("caterpillar".equals(name) && "123456".equals(password)) { - System.out.println("�w�� caterpillar "); + System.out.println("歡迎 caterpillar "); break; } else { - System.out.printf("%s�A�W�٩αK�X���~�A�Э��s��J�I%n", name); + System.out.printf("%s,名稱或密碼錯誤,請重新輸入!%n", name); } } diff --git a/example/CH15/ExecutorDemo.java b/example/CH15/ExecutorDemo.java index d6373e7..6e17e28 100644 --- a/example/CH15/ExecutorDemo.java +++ b/example/CH15/ExecutorDemo.java @@ -25,6 +25,6 @@ public void run() { service.submit(runnable); } - service.shutdown(); // �̫�O�o����Thread pool + service.shutdown(); // 最後記得關閉Thread pool } } \ No newline at end of file diff --git a/example/CH15/FutureDemo.java b/example/CH15/FutureDemo.java index 961aea1..cb98a6d 100644 --- a/example/CH15/FutureDemo.java +++ b/example/CH15/FutureDemo.java @@ -13,10 +13,10 @@ public static void main(String[] args) { t.start(); try { - // ���]�{�b���䥦�Ʊ� + // 假設現在做其它事情 Thread.sleep(5000); - // �^�Ӭݬݽ�Ƨ�n�F�� + // 回來看看質數找好了嗎 if(primeTask.isDone()) { int[] primes = primeTask.get(); for(int prime : primes) { diff --git a/example/CH15/InterruptDemo.java b/example/CH15/InterruptDemo.java index c96acd7..f99b01b 100644 --- a/example/CH15/InterruptDemo.java +++ b/example/CH15/InterruptDemo.java @@ -5,7 +5,7 @@ public static void main(String[] args) { Thread thread = new Thread(new Runnable() { public void run() { try { - // �Ȱ�99999�@�� + // 暫停99999毫秒 Thread.sleep(99999); } catch(InterruptedException e) { diff --git a/example/CH15/PersonalInfoTest.java b/example/CH15/PersonalInfoTest.java index de9f832..6a6b5a0 100644 --- a/example/CH15/PersonalInfoTest.java +++ b/example/CH15/PersonalInfoTest.java @@ -4,7 +4,7 @@ public class PersonalInfoTest { public static void main(String[] args) { final PersonalInfo person = new PersonalInfo(); - // ���]�|����Ӱ�����i���sperson���� + // 假設會有兩個執行緒可能更新person物件 Thread thread1 = new Thread(new Runnable() { public void run() { while(true) @@ -19,7 +19,7 @@ public void run() { } }); - System.out.println("�}�l����....."); + System.out.println("開始測試....."); thread1.start(); thread2.start(); diff --git a/example/CH15/PrimeCallable.java b/example/CH15/PrimeCallable.java index 5b4d2e6..b21582b 100644 --- a/example/CH15/PrimeCallable.java +++ b/example/CH15/PrimeCallable.java @@ -19,7 +19,7 @@ public int[] call() throws Exception { for(int i = 2; i <= max; i++) prime[i] = 1; - for(int i = 2; i*i <= max; i++) { // �o��i�H��i + for(int i = 2; i*i <= max; i++) { // 這邊可以改進 if(prime[i] == 1) { for(int j = 2*i; j <= max; j++) { if(j % i == 0) diff --git a/example/CH15/Producer.java b/example/CH15/Producer.java index 6751d91..5ab10e4 100644 --- a/example/CH15/Producer.java +++ b/example/CH15/Producer.java @@ -9,18 +9,18 @@ public Producer(Clerk clerk) { public void run() { System.out.println( - "�Ͳ��̶}�l�Ͳ����......"); + "生產者開始生產整數......"); - // �Ͳ�1��10����� + // 生產1到10的整數 for(int product = 1; product <= 10; product++) { try { - // �Ȱ��H���ɶ� + // 暫停隨機時間 Thread.sleep((int) Math.random() * 3000); } catch(InterruptedException e) { e.printStackTrace(); } - // �N���~�浹���� + // 將產品交給店員 clerk.setProduct(product); } } diff --git a/example/CH15/ProductTest.java b/example/CH15/ProductTest.java index 11f5039..0fc3b13 100644 --- a/example/CH15/ProductTest.java +++ b/example/CH15/ProductTest.java @@ -4,11 +4,11 @@ public class ProductTest { public static void main(String[] args) { Clerk clerk = new Clerk(); - // �Ͳ��̰���� + // 生產者執行緒 Thread producerThread = new Thread( new Producer(clerk)); - // ���O�̰���� + // 消費者執行緒 Thread consumerThread = new Thread( new Consumer(clerk)); diff --git a/example/CH15/SimpleThreadLogger.java b/example/CH15/SimpleThreadLogger.java index a40938f..537494d 100644 --- a/example/CH15/SimpleThreadLogger.java +++ b/example/CH15/SimpleThreadLogger.java @@ -19,9 +19,9 @@ private static Logger getThreadLogger() { try { logger = Logger.getLogger( Thread.currentThread().getName()); - // Logger �w�]�O�b�D���x��X - // �ڭ̥[�J�@���ɮ׿�X��Handler - // ���|��XXML���O����� + // Logger 預設是在主控台輸出 + // 我們加入一個檔案輸出的Handler + // 它會輸出XML的記錄文件 logger.addHandler( new FileHandler( Thread.currentThread().getName() diff --git a/example/CH15/SomeThread.java b/example/CH15/SomeThread.java index 700621e..724ad01 100644 --- a/example/CH15/SomeThread.java +++ b/example/CH15/SomeThread.java @@ -2,7 +2,7 @@ public class SomeThread implements Runnable { public void run() { - System.out.println("sleep....�� blocked ���A"); + System.out.println("sleep....至 blocked 狀態"); try { Thread.sleep(9999); } diff --git a/example/CH15/ThreadA.java b/example/CH15/ThreadA.java index f8a86f0..22b13b5 100644 --- a/example/CH15/ThreadA.java +++ b/example/CH15/ThreadA.java @@ -2,17 +2,17 @@ public class ThreadA { public static void main(String[] args) { - System.out.println("Thread A ����"); + System.out.println("Thread A 執行"); Thread threadB = new Thread(new Runnable() { public void run() { try { - System.out.println("Thread B �}�l.."); + System.out.println("Thread B 開始.."); for(int i = 0; i < 5; i++) { Thread.sleep(1000); - System.out.println("Thread B ����.."); + System.out.println("Thread B 執行.."); } - System.out.println("Thread B �Y�N����.."); + System.out.println("Thread B 即將結束.."); } catch(InterruptedException e) { e.printStackTrace(); @@ -23,13 +23,13 @@ public void run() { threadB.start(); try { - // Thread B �[�J Thread A + // Thread B 加入 Thread A threadB.join(); } catch(InterruptedException e) { e.printStackTrace(); } - System.out.println("Thread A ����"); + System.out.println("Thread A 執行"); } } \ No newline at end of file diff --git a/example/CH15/ThreadGroupDemo2.java b/example/CH15/ThreadGroupDemo2.java index ae329e5..4dbbf97 100644 --- a/example/CH15/ThreadGroupDemo2.java +++ b/example/CH15/ThreadGroupDemo2.java @@ -4,23 +4,23 @@ public class ThreadGroupDemo2 { public static void main(String[] args) { - // �إߨҥ~�B�z�� + // 建立例外處理者 ThreadExceptionHandler handler = new ThreadExceptionHandler(); ThreadGroup threadGroup1 = new ThreadGroup("group1"); - // �o�O�ΦW���O�g�k + // 這是匿名類別寫法 Thread thread1 = - // �o�Ӱ�����OthreadGroup1���@�� + // 這個執行緒是threadGroup1的一員 new Thread(threadGroup1, new Runnable() { public void run() { - // ��Xunchecked�ҥ~ - throw new RuntimeException("���ըҥ~"); + // 丟出unchecked例外 + throw new RuntimeException("測試例外"); } }); - // �]�w�ҥ~�B�z�� + // 設定例外處理者 thread1.setUncaughtExceptionHandler(handler); thread1.start(); } diff --git a/example/CH15/ThreadLocal.java b/example/CH15/ThreadLocal.java index 6c00835..4ae82e2 100644 --- a/example/CH15/ThreadLocal.java +++ b/example/CH15/ThreadLocal.java @@ -3,18 +3,18 @@ import java.util.*; public class ThreadLocal { - // ���o�@�ӦP�B�ƪ�Map���� + // 取得一個同步化的Map物件 private Map storage = Collections.synchronizedMap(new HashMap()); public T get() { - // ���o�ثe����get()��k������� + // 取得目前執行get()方法的執行緒 Thread current = Thread.currentThread(); - // �ھڰ�������o������ۦ����귽 + // 根據執行緒取得執行緒自有的資源 T t = storage.get(current); - // �p�G�٨S��������M�Ϊ��귽�Ŷ� - // �h�إߤ@�ӷs���Ŷ� + // 如果還沒有執行緒專用的資源空間 + // 則建立一個新的空間 if(t == null && !storage.containsKey(current)) { t = initialValue(); diff --git a/example/CH16/ArrayDemo.java b/example/CH16/ArrayDemo.java index 67db078..dfaa3b4 100644 --- a/example/CH16/ArrayDemo.java +++ b/example/CH16/ArrayDemo.java @@ -11,13 +11,13 @@ public static void main(String[] args) { boolean[] zArr = new boolean[5]; String[] strArr = new String[5]; - System.out.println("short �}�C���O�G" + sArr.getClass()); - System.out.println("int �}�C���O�G" + iArr.getClass()); - System.out.println("long �}�C���O�G" + lArr.getClass()); - System.out.println("float �}�C���O�G" + fArr.getClass()); - System.out.println("double �}�C���O�G" + dArr.getClass()); - System.out.println("byte �}�C���O�G" + bArr.getClass()); - System.out.println("boolean �}�C���O�G" + zArr.getClass()); - System.out.println("String �}�C���O�G" + strArr.getClass()); + System.out.println("short 陣列類別:" + sArr.getClass()); + System.out.println("int 陣列類別:" + iArr.getClass()); + System.out.println("long 陣列類別:" + lArr.getClass()); + System.out.println("float 陣列類別:" + fArr.getClass()); + System.out.println("double 陣列類別:" + dArr.getClass()); + System.out.println("byte 陣列類別:" + bArr.getClass()); + System.out.println("boolean 陣列類別:" + zArr.getClass()); + System.out.println("String 陣列類別:" + strArr.getClass()); } } \ No newline at end of file diff --git a/example/CH16/ArrayElementDemo.java b/example/CH16/ArrayElementDemo.java index 9bbadde..7ad5395 100644 --- a/example/CH16/ArrayElementDemo.java +++ b/example/CH16/ArrayElementDemo.java @@ -11,13 +11,13 @@ public static void main(String[] args) { boolean[] zArr = new boolean[5]; String[] strArr = new String[5]; - System.out.println("short �}�C���O�G" + sArr.getClass()); - System.out.println("int �}�C���O�G" + iArr.getClass()); - System.out.println("long �}�C���O�G" + lArr.getClass()); - System.out.println("float �}�C���O�G" + fArr.getClass()); - System.out.println("double �}�C���O�G" + dArr.getClass()); - System.out.println("byte �}�C���O�G" + bArr.getClass()); - System.out.println("boolean �}�C���O�G" + zArr.getClass()); - System.out.println("String �}�C���O�G" + strArr.getClass()); + System.out.println("short 陣列類別:" + sArr.getClass()); + System.out.println("int 陣列類別:" + iArr.getClass()); + System.out.println("long 陣列類別:" + lArr.getClass()); + System.out.println("float 陣列類別:" + fArr.getClass()); + System.out.println("double 陣列類別:" + dArr.getClass()); + System.out.println("byte 陣列類別:" + bArr.getClass()); + System.out.println("boolean 陣列類別:" + zArr.getClass()); + System.out.println("String 陣列類別:" + strArr.getClass()); } } \ No newline at end of file diff --git a/example/CH16/AssignFieldDemo.java b/example/CH16/AssignFieldDemo.java index 6c274e2..cd2799b 100644 --- a/example/CH16/AssignFieldDemo.java +++ b/example/CH16/AssignFieldDemo.java @@ -16,13 +16,13 @@ public static void main(String[] args) { System.out.println(targetObj); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�S�����w���O"); + System.out.println("沒有指定類別"); } catch (ClassNotFoundException e) { - System.out.println("�䤣����w�����O"); + System.out.println("找不到指定的類別"); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { - System.out.println("�䤣����w����Ʀ���"); + System.out.println("找不到指定的資料成員"); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { diff --git a/example/CH16/ClassDemo.java b/example/CH16/ClassDemo.java index 9cb7db5..23034bf 100644 --- a/example/CH16/ClassDemo.java +++ b/example/CH16/ClassDemo.java @@ -4,15 +4,15 @@ public class ClassDemo { public static void main(String[] args) { String name = "caterpillar"; Class stringClass = name.getClass(); - System.out.println("���O�W�١G" + + System.out.println("類別名稱:" + stringClass.getName()); - System.out.println("�O�_�������G" + + System.out.println("是否為介面:" + stringClass.isInterface()); - System.out.println("�O�_���򥻫��A�G" + + System.out.println("是否為基本型態:" + stringClass.isPrimitive()); - System.out.println("�O�_���}�C����G" + + System.out.println("是否為陣列物件:" + stringClass.isArray()); - System.out.println("�����O�W�١G" + + System.out.println("父類別名稱:" + stringClass.getSuperclass().getName()); } } \ No newline at end of file diff --git a/example/CH16/ClassInfoDemo.java b/example/CH16/ClassInfoDemo.java index c9c527c..14991a3 100644 --- a/example/CH16/ClassInfoDemo.java +++ b/example/CH16/ClassInfoDemo.java @@ -8,10 +8,10 @@ public static void main(String[] args) { System.out.println(p.getName()); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�S�����w���O"); + System.out.println("沒有指定類別"); } catch(ClassNotFoundException e) { - System.out.println("�䤣����w���O"); + System.out.println("找不到指定類別"); } } } diff --git a/example/CH16/ClassLoaderDemo.java b/example/CH16/ClassLoaderDemo.java index 7667988..259e2b7 100644 --- a/example/CH16/ClassLoaderDemo.java +++ b/example/CH16/ClassLoaderDemo.java @@ -7,18 +7,18 @@ public class ClassLoaderDemo { public static void main(String[] args) { try { - // ���ո��| + // 測試路徑 String classPath = args[0]; - // �������O + // 測試類別 String className = args[1]; URL url1 = new URL(classPath); - // �إ�ClassLoader + // 建立ClassLoader ClassLoader loader1 = new URLClassLoader(new URL[] {url1}); - // ���J���w���O + // 載入指定類別 Class c1 = loader1.loadClass(className); - // ������O�y�z + // 顯示類別描述 System.out.println(c1); URL url2 = new URL(classPath); @@ -28,17 +28,17 @@ public static void main(String[] args) { System.out.println(c2); - System.out.println("c1 �P c1 ���P�@��ҡH" + System.out.println("c1 與 c1 為同一實例?" + (c1 == c2)); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�S�����w���O���J���|�P�W��"); + System.out.println("沒有指定類別載入路徑與名稱"); } catch(MalformedURLException e) { - System.out.println("���J���|���~"); + System.out.println("載入路徑錯誤"); } catch(ClassNotFoundException e) { - System.out.println("�䤣����w�����O"); + System.out.println("找不到指定的類別"); } } } \ No newline at end of file diff --git a/example/CH16/CommandUtil.java b/example/CH16/CommandUtil.java index 50c16af..b925e56 100644 --- a/example/CH16/CommandUtil.java +++ b/example/CH16/CommandUtil.java @@ -5,8 +5,8 @@ import java.util.Map; public class CommandUtil { - // ���wMap����έn���ͪ�Bean���O�W�� - // �i�H���^�w�g�]�w���������� + // 給定Map物件及要產生的Bean類別名稱 + // 可以取回已經設定完成的物件 public static Object getCommand(Map requestMap, String commandClass) throws Exception { @@ -16,7 +16,7 @@ public static Object getCommand(Map requestMap, return updateCommand(requestMap, o); } - // �ϥ�reflection�۰ʧ�X�n��s���ݩ� + // 使用reflection自動找出要更新的屬性 public static Object updateCommand( Map requestMap, Object command) @@ -25,17 +25,17 @@ public static Object updateCommand( command.getClass().getDeclaredMethods(); for(int i = 0; i < methods.length; i++) { - // ���Lprivate�Bprotected���� - // �B��X�����Oset�}�Y����k�W�� + // 略過private、protected成員 + // 且找出必須是set開頭的方法名稱 if(!Modifier.isPrivate(methods[i].getModifiers()) && !Modifier.isProtected(methods[i].getModifiers()) && methods[i].getName().startsWith("set")) { - // ���o���]�Aset���W�� + // 取得不包括set的名稱 String name = methods[i].getName() .substring(3) .toLowerCase(); - // �p�Gsetter�W�ٻP��ȬۦP - // �I�s������setter�ó]�w�� + // 如果setter名稱與鍵值相同 + // 呼叫對應的setter並設定值 if(requestMap.containsKey(name)) { String param = (String) requestMap.get(name); Object[] values = findOutParamValues( @@ -47,7 +47,7 @@ public static Object updateCommand( return command; } - // �ഫ���������A���� + // 轉換為對應型態的值 private static Object[] findOutParamValues( String param, Method method) { Class[] params = method.getParameterTypes(); diff --git a/example/CH16/ForNameDemo.java b/example/CH16/ForNameDemo.java index e495d14..9a552ff 100644 --- a/example/CH16/ForNameDemo.java +++ b/example/CH16/ForNameDemo.java @@ -4,21 +4,21 @@ public class ForNameDemo { public static void main(String[] args) { try { Class c = Class.forName(args[0]); - System.out.println("���O�W�١G" + + System.out.println("類別名稱:" + c.getName()); - System.out.println("�O�_�������G" + + System.out.println("是否為介面:" + c.isInterface()); - System.out.println("�O�_���򥻫��A�G" + + System.out.println("是否為基本型態:" + c.isPrimitive()); - System.out.println("�O�_���}�C�G" + c.isArray()); - System.out.println("�����O�G" + + System.out.println("是否為陣列:" + c.isArray()); + System.out.println("父類別:" + c.getSuperclass().getName()); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�S�����w���O�W��"); + System.out.println("沒有指定類別名稱"); } catch(ClassNotFoundException e) { - System.out.println("�䤣����w�����O"); + System.out.println("找不到指定的類別"); } } } \ No newline at end of file diff --git a/example/CH16/ForNameDemoV1.java b/example/CH16/ForNameDemoV1.java index 6dde368..87d4410 100644 --- a/example/CH16/ForNameDemoV1.java +++ b/example/CH16/ForNameDemoV1.java @@ -3,17 +3,17 @@ public class ForNameDemoV1 { public static void main(String[] args) { try { - System.out.println("���JTestClass2"); + System.out.println("載入TestClass2"); Class c = Class.forName("onlyfun.caterpillar.TestClass2"); - System.out.println("�ϥ�TestClass2�ŧi�ѦҦW��"); + System.out.println("使用TestClass2宣告參考名稱"); TestClass2 test = null; - System.out.println("�ϥ�TestClass2�إߪ���"); + System.out.println("使用TestClass2建立物件"); test = new TestClass2(); } catch(ClassNotFoundException e) { - System.out.println("�䤣����w�����O"); + System.out.println("找不到指定的類別"); } } } \ No newline at end of file diff --git a/example/CH16/ForNameDemoV2.java b/example/CH16/ForNameDemoV2.java index 7c9a145..811d0be 100644 --- a/example/CH16/ForNameDemoV2.java +++ b/example/CH16/ForNameDemoV2.java @@ -3,20 +3,20 @@ public class ForNameDemoV2 { public static void main(String[] args) { try { - System.out.println("���JTestClass2"); + System.out.println("載入TestClass2"); Class c = Class.forName( "onlyfun.caterpillar.TestClass2", false, Thread.currentThread().getContextClassLoader()); - System.out.println("�ϥ�TestClass2�ŧi�ѦҦW��"); + System.out.println("使用TestClass2宣告參考名稱"); TestClass2 test = null; - System.out.println("�ϥ�TestClass2�إߪ���"); + System.out.println("使用TestClass2建立物件"); test = new TestClass2(); } catch(ClassNotFoundException e) { - System.out.println("�䤣����w�����O"); + System.out.println("找不到指定的類別"); } } } \ No newline at end of file diff --git a/example/CH16/ForNameDemoV3.java b/example/CH16/ForNameDemoV3.java index aa5acfd..37aa233 100644 --- a/example/CH16/ForNameDemoV3.java +++ b/example/CH16/ForNameDemoV3.java @@ -3,18 +3,18 @@ public class ForNameDemoV3 { public static void main(String[] args) { try { - System.out.println("���JTestClass2"); + System.out.println("載入TestClass2"); ClassLoader loader = ForNameDemoV3.class.getClassLoader(); Class c = loader.loadClass("onlyfun.caterpillar.TestClass2"); - System.out.println("�ϥ�TestClass2�ŧi�ѦҦW��"); + System.out.println("使用TestClass2宣告參考名稱"); TestClass2 test = null; - System.out.println("�ϥ�TestClass2�إߪ���"); + System.out.println("使用TestClass2建立物件"); test = new TestClass2(); } catch(ClassNotFoundException e) { - System.out.println("�䤣����w�����O"); + System.out.println("找不到指定的類別"); } } } \ No newline at end of file diff --git a/example/CH16/InvokeMethodDemo.java b/example/CH16/InvokeMethodDemo.java index afbf0b8..8719b83 100644 --- a/example/CH16/InvokeMethodDemo.java +++ b/example/CH16/InvokeMethodDemo.java @@ -7,15 +7,15 @@ public class InvokeMethodDemo { public static void main(String[] args) { try { Class c = Class.forName(args[0]); - // �ϥεL�Ѽƫغc��k�إߪ��� + // 使用無參數建構方法建立物件 Object targetObj = c.newInstance(); - // �]�w�Ѽƫ��A + // 設定參數型態 Class[] param1 = {String.class}; - // �ھڰѼƫ��A���^��k���� + // 根據參數型態取回方法物件 Method setNameMethod = c.getMethod("setName", param1); - // �]�w�޼ƭ� + // 設定引數值 Object[] argObjs1 = {"caterpillar"}; - // ���w�޼ƩI�s���w���󤧤�k + // 給定引數呼叫指定物件之方法 setNameMethod.invoke(targetObj, argObjs1); @@ -25,15 +25,15 @@ public static void main(String[] args) { Object[] argObjs2 = {new Integer(90)}; setScoreMethod.invoke(targetObj, argObjs2); - // ��ܪ���y�z + // 顯示物件描述 System.out.println(targetObj); } catch (ClassNotFoundException e) { - System.out.println("�䤣�����O"); + System.out.println("找不到類別"); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { - System.out.println("�S���o�Ӥ�k"); + System.out.println("沒有這個方法"); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { diff --git a/example/CH16/LoadClassTest.java b/example/CH16/LoadClassTest.java index 54480dc..4b88d2d 100644 --- a/example/CH16/LoadClassTest.java +++ b/example/CH16/LoadClassTest.java @@ -3,8 +3,8 @@ public class LoadClassTest { public static void main(String[] args) { TestClass test = null; - System.out.println("�ŧiTestClass�ѦҦW��"); + System.out.println("宣告TestClass參考名稱"); test = new TestClass(); - System.out.println("�ͦ�TestClass���"); + System.out.println("生成TestClass實例"); } } \ No newline at end of file diff --git a/example/CH16/LogHandler.java b/example/CH16/LogHandler.java index 9c1ebfa..990f7de 100644 --- a/example/CH16/LogHandler.java +++ b/example/CH16/LogHandler.java @@ -8,18 +8,18 @@ public class LogHandler implements InvocationHandler { Logger.getLogger(this.getClass().getName()); private Object delegate; - // �j�w�n�N�z������ + // 綁定要代理的物件 public Object bind(Object delegate) { this.delegate = delegate; - // �إߨöǦ^�N�z���� + // 建立並傳回代理物件 return Proxy.newProxyInstance( delegate.getClass().getClassLoader(), - // �n�Q�N�z������ + // 要被代理的介面 delegate.getClass().getInterfaces(), this); } - // �N�z�n�I�s����k�A�æb��e��W�[�欰 + // 代理要呼叫的方法,並在其前後增加行為 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { diff --git a/example/CH16/NewArrayDemo2.java b/example/CH16/NewArrayDemo2.java index 4475dc3..ec16fbe 100644 --- a/example/CH16/NewArrayDemo2.java +++ b/example/CH16/NewArrayDemo2.java @@ -6,7 +6,7 @@ public class NewArrayDemo2 { public static void main(String[] args) { Class c = String.class; - // ����إߤ@��3*4�}�C + // 打算建立一個3*4陣列 int[] dim = new int[]{3, 4}; Object objArr = Array.newInstance(c, dim); diff --git a/example/CH16/NewInstanceDemo.java b/example/CH16/NewInstanceDemo.java index dff2c62..8c35c50 100644 --- a/example/CH16/NewInstanceDemo.java +++ b/example/CH16/NewInstanceDemo.java @@ -17,7 +17,7 @@ public static void main(String[] args) { } } catch(ClassNotFoundException e) { - System.out.println("�䤣����w�����O"); + System.out.println("找不到指定的類別"); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { diff --git a/example/CH16/NewInstanceDemo2.java b/example/CH16/NewInstanceDemo2.java index de1f407..65b4823 100644 --- a/example/CH16/NewInstanceDemo2.java +++ b/example/CH16/NewInstanceDemo2.java @@ -8,33 +8,33 @@ public static void main(String[] args) { try { Class c = Class.forName(args[0]); - // ���w�Ѽƫ��A + // 指定參數型態 Class[] params = new Class[2]; - // �Ĥ@�ӰѼƬOString + // 第一個參數是String params[0] = String.class; - // �ĤG�ӰѼƬOint + // 第二個參數是int params[1] = Integer.TYPE; - // ���o�����ѼƦC���غc��k + // 取得對應參數列的建構方法 Constructor constructor = c.getConstructor(params); - // ���w�޼Ƥ��e + // 指定引數內容 Object[] argObjs = new Object[2]; argObjs[0] = "caterpillar"; argObjs[1] = new Integer(90); - // ���w�޼ƨù�Ҥ� + // 給定引數並實例化 Object obj = constructor.newInstance(argObjs); - // �I�stoString()���[�ݴy�z + // 呼叫toString()來觀看描述 System.out.println(obj); } catch (ClassNotFoundException e) { - System.out.println("�䤣�����O"); + System.out.println("找不到類別"); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { - System.out.println("�S���ҫ��w����k"); + System.out.println("沒有所指定的方法"); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InstantiationException e) { diff --git a/example/CH16/ProxyDemo.java b/example/CH16/ProxyDemo.java index e08e09c..873978e 100644 --- a/example/CH16/ProxyDemo.java +++ b/example/CH16/ProxyDemo.java @@ -5,7 +5,7 @@ public static void main(String[] args) { LogHandler handler = new LogHandler(); IHello speaker = new HelloSpeaker(); - // �N�zspeaker������ + // 代理speaker的物件 IHello speakerProxy = (IHello) handler.bind(speaker); diff --git a/example/CH16/SimpleClassViewer.java b/example/CH16/SimpleClassViewer.java index 9e25cb0..5637134 100644 --- a/example/CH16/SimpleClassViewer.java +++ b/example/CH16/SimpleClassViewer.java @@ -6,16 +6,16 @@ public class SimpleClassViewer { public static void main(String[] args) { try { Class c = Class.forName(args[0]); - // ���o�M��N������ + // 取得套件代表物件 Package p = c.getPackage(); System.out.printf("package %s;%n", p.getName()); - // ���o���A�׹��A���Oclass�Binterface + // 取得型態修飾,像是class、interface int m = c.getModifiers(); System.out.print(Modifier.toString(m) + " "); - // �p�G�O���� + // 如果是介面 if(Modifier.isInterface(m)) { System.out.print("interface "); } @@ -25,51 +25,51 @@ public static void main(String[] args) { System.out.println(c.getName() + " {"); - // ���o�ŧi����Ʀ����N������ + // 取得宣告的資料成員代表物件 Field[] fields = c.getDeclaredFields(); for(Field field : fields) { - // ����v���׹��A���Opublic�Bprotected�Bprivate + // 顯示權限修飾,像是public、protected、private System.out.print("\t" + Modifier.toString(field.getModifiers())); - // ��ܫ��A�W�� + // 顯示型態名稱 System.out.print(" " + field.getType().getName() + " "); - // ��ܸ�Ʀ����W�� + // 顯示資料成員名稱 System.out.println(field.getName() + ";"); } - // ���o�ŧi���غc��k�N������ + // 取得宣告的建構方法代表物件 Constructor[] constructors = c.getDeclaredConstructors(); for(Constructor constructor : constructors) { - // ����v���׹��A���Opublic�Bprotected�Bprivate + // 顯示權限修飾,像是public、protected、private System.out.print("\t" + Modifier.toString( constructor.getModifiers())); - // ��ܫغc��k�W�� + // 顯示建構方法名稱 System.out.println(" " + constructor.getName() + "();"); } - // ���o�ŧi����k�����N������ + // 取得宣告的方法成員代表物件 Method[] methods = c.getDeclaredMethods(); for(Method method : methods) { - // ����v���׹��A���Opublic�Bprotected�Bprivate + // 顯示權限修飾,像是public、protected、private System.out.print("\t" + Modifier.toString( method.getModifiers())); - // ��ܪ�^�ȫ��A�W�� + // 顯示返回值型態名稱 System.out.print(" " + method.getReturnType().getName() + " "); - // ��ܤ�k�W�� + // 顯示方法名稱 System.out.println(method.getName() + "();"); } System.out.println("}"); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�S�����w���O"); + System.out.println("沒有指定類別"); } catch(ClassNotFoundException e) { - System.out.println("�䤣����w���O"); + System.out.println("找不到指定類別"); } } } \ No newline at end of file diff --git a/example/CH16/SomeClass.java b/example/CH16/SomeClass.java index 686a35d..bde3fa9 100644 --- a/example/CH16/SomeClass.java +++ b/example/CH16/SomeClass.java @@ -2,16 +2,16 @@ public class SomeClass { public static void main(String[] args) { - // �إ�SomeClass��� + // 建立SomeClass實例 SomeClass some = new SomeClass(); - // ���oSomeClass��Class��� + // 取得SomeClass的Class實例 Class c = some.getClass(); - // ���oClassLoader + // 取得ClassLoader ClassLoader loader = c.getClassLoader(); System.out.println(loader); - // ���o��ClassLoader + // 取得父ClassLoader System.out.println(loader.getParent()); - // �A���o��ClassLoader + // 再取得父ClassLoader System.out.println(loader.getParent().getParent()); } } \ No newline at end of file diff --git a/example/CH16/TestClass.java b/example/CH16/TestClass.java index 896048a..c64d9da 100644 --- a/example/CH16/TestClass.java +++ b/example/CH16/TestClass.java @@ -2,6 +2,6 @@ public class TestClass { static { - System.out.println("���O�Q���J"); + System.out.println("類別被載入"); } } \ No newline at end of file diff --git a/example/CH16/TestClass2.java b/example/CH16/TestClass2.java index 4c6edb3..10d59ce 100644 --- a/example/CH16/TestClass2.java +++ b/example/CH16/TestClass2.java @@ -2,6 +2,6 @@ public class TestClass2 { static { - System.out.println("[�����R�A�϶�]"); + System.out.println("[執行靜態區塊]"); } } \ No newline at end of file diff --git a/example/CH17/AnalysisApp.java b/example/CH17/AnalysisApp.java index ee7d5ac..1e63269 100644 --- a/example/CH17/AnalysisApp.java +++ b/example/CH17/AnalysisApp.java @@ -8,30 +8,30 @@ public static void main(String[] args) throws NoSuchMethodException { Class c = SomeClass3.class; - // �]��SomeAnnotation�Хܩ�doSomething()��k�W - // �ҥH�n���odoSomething()��k��Method��� + // 因為SomeAnnotation標示於doSomething()方法上 + // 所以要取得doSomething()方法的Method實例 Method method = c.getMethod("doSomething"); - // �p�GSomeAnnotation�s�b���� + // 如果SomeAnnotation存在的話 if(method.isAnnotationPresent(SomeAnnotation.class)) { - System.out.println("��� @SomeAnnotation"); - // ���oSomeAnnotation + System.out.println("找到 @SomeAnnotation"); + // 取得SomeAnnotation SomeAnnotation annotation = method.getAnnotation(SomeAnnotation.class); - // ���ovalue������ + // 取得value成員值 System.out.println("\tvalue = " + annotation.value()); - // ���oname������ + // 取得name成員值 System.out.println("\tname = " + annotation.name()); } else { - System.out.println("�䤣�� @SomeAnnotation"); + System.out.println("找不到 @SomeAnnotation"); } - // ���odoSomething()��k�W�Ҧ���Annotation + // 取得doSomething()方法上所有的Annotation Annotation[] annotations = method.getAnnotations(); - // ���Annotation�W�� + // 顯示Annotation名稱 for(Annotation annotation : annotations) { - System.out.println("Annotation�W�١G" + + System.out.println("Annotation名稱:" + annotation.annotationType().getName()); } } diff --git a/example/CH17/SomethingDemo.java b/example/CH17/SomethingDemo.java index 71b85da..8595aaa 100644 --- a/example/CH17/SomethingDemo.java +++ b/example/CH17/SomethingDemo.java @@ -3,7 +3,7 @@ public class SomethingDemo { public static void main(String[] args) { Something some = new Something(); - // �I�s�Q@Deprecated�Хܪ���k + // 呼叫被@Deprecated標示的方法 some.getSomething(); } } \ No newline at end of file diff --git a/example/CH18/CalendarDemo.java b/example/CH18/CalendarDemo.java index 247226c..1e77583 100644 --- a/example/CH18/CalendarDemo.java +++ b/example/CH18/CalendarDemo.java @@ -6,14 +6,14 @@ public class CalendarDemo { public static void main(String[] args) { Calendar rightNow = Calendar.getInstance(); - System.out.println("�{�b�ɶ��O�G"); - System.out.println("�褸�G" + + System.out.println("現在時間是:"); + System.out.println("西元:" + rightNow.get(Calendar.YEAR)); - System.out.println("��G" + + System.out.println("月:" + getChineseMonth(rightNow)); - System.out.println("��G" + + System.out.println("日:" + rightNow.get(Calendar.DAY_OF_MONTH)); - System.out.println("�P���G" + + System.out.println("星期:" + getChineseDayOfWeek(rightNow)); } @@ -22,40 +22,40 @@ public static String getChineseMonth(Calendar rightNow) { switch(rightNow.get(Calendar.MONTH)) { case Calendar.JANUARY: - chineseMonth = "�@"; + chineseMonth = "一"; break; case Calendar.FEBRUARY: - chineseMonth = "�G"; + chineseMonth = "二"; break; case Calendar.MARCH: - chineseMonth = "�T"; + chineseMonth = "三"; break; case Calendar.APRIL: - chineseMonth = "�|"; + chineseMonth = "四"; break; case Calendar.MAY: - chineseMonth = "��"; + chineseMonth = "五"; break; case Calendar.JUNE: - chineseMonth = "��"; + chineseMonth = "六"; break; case Calendar.JULY: - chineseMonth = "�C"; + chineseMonth = "七"; break; case Calendar.AUGUST: - chineseMonth = "�K"; + chineseMonth = "八"; break; case Calendar.SEPTEMBER: - chineseMonth = "�E"; + chineseMonth = "九"; break; case Calendar.OCTOBER: - chineseMonth = "�Q"; + chineseMonth = "十"; break; case Calendar.NOVEMBER: - chineseMonth = "�Q�@"; + chineseMonth = "十一"; break; case Calendar.DECEMBER: - chineseMonth = "�Q�G"; + chineseMonth = "十二"; break; } @@ -68,25 +68,25 @@ public static String getChineseDayOfWeek( switch(rightNow.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: - chineseDayOfWeek = "��"; + chineseDayOfWeek = "日"; break; case Calendar.MONDAY: - chineseDayOfWeek = "�@"; + chineseDayOfWeek = "一"; break; case Calendar.TUESDAY: - chineseDayOfWeek = "�G"; + chineseDayOfWeek = "二"; break; case Calendar.WEDNESDAY: - chineseDayOfWeek = "�T"; + chineseDayOfWeek = "三"; break; case Calendar.THURSDAY: - chineseDayOfWeek = "�|"; + chineseDayOfWeek = "四"; break; case Calendar.FRIDAY: - chineseDayOfWeek = "��"; + chineseDayOfWeek = "五"; break; case Calendar.SATURDAY: - chineseDayOfWeek = "��"; + chineseDayOfWeek = "六"; break; } diff --git a/example/CH18/CurrentTime.java b/example/CH18/CurrentTime.java index 69a81fd..9072a3d 100644 --- a/example/CH18/CurrentTime.java +++ b/example/CH18/CurrentTime.java @@ -2,7 +2,7 @@ public class CurrentTime { public static void main(String[] args) { - System.out.println("�{�b�ɶ� " + System.out.println("現在時間 " + System.currentTimeMillis()); } } \ No newline at end of file diff --git a/example/CH18/DateDemo.java b/example/CH18/DateDemo.java index 3061ebc..37c748b 100644 --- a/example/CH18/DateDemo.java +++ b/example/CH18/DateDemo.java @@ -6,9 +6,9 @@ public class DateDemo { public static void main(String[] args) { Date date = new Date(); - System.out.println("�{�b�ɶ� " + System.out.println("現在時間 " + date.toString()); - System.out.println("��1970/1/1�ܤ����@���� " + System.out.println("自1970/1/1至今的毫秒數 " + date.getTime()); } } \ No newline at end of file diff --git a/example/CH18/DateTimeInstanceDemo.java b/example/CH18/DateTimeInstanceDemo.java index b028149..e56e28a 100644 --- a/example/CH18/DateTimeInstanceDemo.java +++ b/example/CH18/DateTimeInstanceDemo.java @@ -5,33 +5,33 @@ public class DateTimeInstanceDemo { public static void main(String[] args) { - // ���o�ثe�ɶ� + // 取得目前時間 Date date = new Date(); - // ²�u��T�榡 + // 簡短資訊格式 DateFormat shortFormat = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT); - // ������T�榡 + // 中等資訊格式 DateFormat mediumFormat = DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.MEDIUM); - // ����T�榡 + // 長資訊格式 DateFormat longFormat = DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.LONG); - // �ԲӸ�T�榡 + // 詳細資訊格式 DateFormat fullFormat = DateFormat.getDateTimeInstance( DateFormat.FULL, DateFormat.FULL); - System.out.println("²�u��T�榡�G" + + System.out.println("簡短資訊格式:" + shortFormat.format(date)); - System.out.println("������T�榡�G" + + System.out.println("中等資訊格式:" + mediumFormat.format(date)); - System.out.println("����T�榡�G" + + System.out.println("長資訊格式:" + longFormat.format(date)); - System.out.println("�ԲӸ�T�榡�G" + + System.out.println("詳細資訊格式:" + fullFormat.format(date)); } } \ No newline at end of file diff --git a/example/CH18/DateTimeInstanceDemo2.java b/example/CH18/DateTimeInstanceDemo2.java index 860c066..79ba1c7 100644 --- a/example/CH18/DateTimeInstanceDemo2.java +++ b/example/CH18/DateTimeInstanceDemo2.java @@ -6,25 +6,25 @@ public class DateTimeInstanceDemo2 { public static void main(String[] args) { - // ���o�ثe�ɶ� + // 取得目前時間 Date date = new Date(); - // en: �^�y�t US: ���� + // en: 英語系 US: 美國 Locale locale = new Locale("en", "US"); - // ²�u��T�榡 + // 簡短資訊格式 DateFormat shortFormat = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT, locale); - // ������T�榡 + // 中等資訊格式 DateFormat mediumFormat = DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.MEDIUM, locale); - // ����T�榡 + // 長資訊格式 DateFormat longFormat = DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.LONG, locale); - // �ԲӸ�T�榡 + // 詳細資訊格式 DateFormat fullFormat = DateFormat.getDateTimeInstance( DateFormat.FULL, DateFormat.FULL, locale); diff --git a/example/CH18/HandlerDemo.java b/example/CH18/HandlerDemo.java index f8fc358..eb08133 100644 --- a/example/CH18/HandlerDemo.java +++ b/example/CH18/HandlerDemo.java @@ -11,7 +11,7 @@ public static void main(String[] args) { FileHandler fileHandler = new FileHandler("%h/myLogger.log"); logger.addHandler(fileHandler); - logger.info("���հT��"); + logger.info("測試訊息"); } catch (SecurityException e) { e.printStackTrace(); } catch (IOException e) { diff --git a/example/CH18/LoggingDemo.java b/example/CH18/LoggingDemo.java index 996e54e..f60fc05 100644 --- a/example/CH18/LoggingDemo.java +++ b/example/CH18/LoggingDemo.java @@ -10,7 +10,7 @@ public static void main(String[] args) { System.out.println(args[0]); } catch(ArrayIndexOutOfBoundsException e) { - logger.warning("�S�����Ѱ���ɪ��޼ơI"); + logger.warning("沒有提供執行時的引數!"); } } } \ No newline at end of file diff --git a/example/CH18/LoggingLevelDemo.java b/example/CH18/LoggingLevelDemo.java index b5f6b80..9c18d20 100644 --- a/example/CH18/LoggingLevelDemo.java +++ b/example/CH18/LoggingLevelDemo.java @@ -6,12 +6,12 @@ public class LoggingLevelDemo { public static void main(String[] args) { Logger logger = Logger.getLogger("loggingLevelDemo"); - logger.severe("�Y���T��"); - logger.warning("ĵ�ܰT��"); - logger.info("�@��T��"); - logger.config("�]�w�譱���T��"); - logger.fine("�ӷL���T��"); - logger.finer("��ӷL���T��"); - logger.finest("�̲ӷL���T��"); + logger.severe("嚴重訊息"); + logger.warning("警示訊息"); + logger.info("一般訊息"); + logger.config("設定方面的訊息"); + logger.fine("細微的訊息"); + logger.finer("更細微的訊息"); + logger.finest("最細微的訊息"); } } \ No newline at end of file diff --git a/example/CH18/LoggingLevelDemo2.java b/example/CH18/LoggingLevelDemo2.java index b2aefea..ca26ceb 100644 --- a/example/CH18/LoggingLevelDemo2.java +++ b/example/CH18/LoggingLevelDemo2.java @@ -5,21 +5,21 @@ public class LoggingLevelDemo2 { public static void main(String[] args) { Logger logger = Logger.getLogger("loggingLevelDemo2"); - // ��ܩҦ����Ū��T�� + // 顯示所有等級的訊息 logger.setLevel(Level.ALL); ConsoleHandler consoleHandler = new ConsoleHandler(); - // ��ܩҦ����Ū��T�� + // 顯示所有等級的訊息 consoleHandler.setLevel(Level.ALL); - // �]�w�B�z�̬�ConsoleHandler + // 設定處理者為ConsoleHandler logger.addHandler(consoleHandler); - logger.severe("�Y���T��"); - logger.warning("ĵ�ܰT��"); - logger.info("�@��T��"); - logger.config("�]�w�譱���T��"); - logger.fine("�ӷL���T��"); - logger.finer("��ӷL���T��"); - logger.finest("�̲ӷL���T��"); + logger.severe("嚴重訊息"); + logger.warning("警示訊息"); + logger.info("一般訊息"); + logger.config("設定方面的訊息"); + logger.fine("細微的訊息"); + logger.finer("更細微的訊息"); + logger.finest("最細微的訊息"); } } \ No newline at end of file diff --git a/example/CH18/LoggingLevelDemo3.java b/example/CH18/LoggingLevelDemo3.java index 829d4f5..ccbfafa 100644 --- a/example/CH18/LoggingLevelDemo3.java +++ b/example/CH18/LoggingLevelDemo3.java @@ -11,12 +11,12 @@ public static void main(String[] args) { consoleHandler.setLevel(Level.ALL); logger.addHandler(consoleHandler); - logger.log(Level.SEVERE, "�Y���T��"); - logger.log(Level.WARNING, "ĵ�ܰT��"); - logger.log(Level.INFO, "�@��T��"); - logger.log(Level.CONFIG, "�]�w�譱���T��"); - logger.log(Level.FINE, "�ӷL���T��"); - logger.log(Level.FINER, "��ӷL���T��"); - logger.log(Level.FINEST, "�̲ӷL���T��"); + logger.log(Level.SEVERE, "嚴重訊息"); + logger.log(Level.WARNING, "警示訊息"); + logger.log(Level.INFO, "一般訊息"); + logger.log(Level.CONFIG, "設定方面的訊息"); + logger.log(Level.FINE, "細微的訊息"); + logger.log(Level.FINER, "更細微的訊息"); + logger.log(Level.FINEST, "最細微的訊息"); } } \ No newline at end of file diff --git a/example/CH18/MessageFormatDemo.java b/example/CH18/MessageFormatDemo.java index 17b780c..4a85119 100644 --- a/example/CH18/MessageFormatDemo.java +++ b/example/CH18/MessageFormatDemo.java @@ -6,7 +6,7 @@ public class MessageFormatDemo { public static void main(String[] args) { try { - // �j�wmessages.properties + // 綁定messages.properties ResourceBundle resource = ResourceBundle.getBundle("messages2"); @@ -17,11 +17,11 @@ public static void main(String[] args) { MessageFormat formatter = new MessageFormat(message); - // ��ܮ榡�ƫ᪺�T�� + // 顯示格式化後的訊息 System.out.println(formatter.format(params)); } catch(ArrayIndexOutOfBoundsException e) { - System.out.println("�S�����w�޼�"); + System.out.println("沒有指定引數"); } } } \ No newline at end of file diff --git a/example/CH18/ResourceBundleDemo.java b/example/CH18/ResourceBundleDemo.java index 7a3dd3d..5d2e318 100644 --- a/example/CH18/ResourceBundleDemo.java +++ b/example/CH18/ResourceBundleDemo.java @@ -4,10 +4,10 @@ public class ResourceBundleDemo { public static void main(String[] args) { - // �j�wmessages.properties + // 綁定messages.properties ResourceBundle resource = ResourceBundle.getBundle("messages"); - // ���o�����T�� + // 取得對應訊息 System.out.print(resource.getString( "onlyfun.caterpillar.welcome") + "!"); System.out.println(resource.getString( diff --git a/example/CH18/TableFormatterDemo.java b/example/CH18/TableFormatterDemo.java index 5a0778f..3d25a20 100644 --- a/example/CH18/TableFormatterDemo.java +++ b/example/CH18/TableFormatterDemo.java @@ -13,8 +13,8 @@ public static void main(String[] args) { } } - logger.info("�T��1"); - logger.warning("�T��2"); + logger.info("訊息1"); + logger.warning("訊息2"); } catch (SecurityException e) { e.printStackTrace(); } diff --git a/example/CH19/19.2/onlyfun/caterpillar/JNotePadUI.java b/example/CH19/19.2/onlyfun/caterpillar/JNotePadUI.java index 9ad0f3f..324dcc8 100644 --- a/example/CH19/19.2/onlyfun/caterpillar/JNotePadUI.java +++ b/example/CH19/19.2/onlyfun/caterpillar/JNotePadUI.java @@ -20,7 +20,7 @@ public class JNotePadUI extends JFrame { public JNotePadUI() { - super("�s�W��r�ɮ�"); + super("新增文字檔案"); setUpUIComponent(); setUpEventListener(); setVisible(true); @@ -29,48 +29,48 @@ public JNotePadUI() { private void setUpUIComponent() { setSize(640, 480); - // ���C + // 選單列 JMenuBar menuBar = new JMenuBar(); - // �]�m�u�ɮסv��� - JMenu fileMenu = new JMenu("�ɮ�"); - JMenuItem menuOpen = new JMenuItem("�}������"); - // �ֳt��]�m + // 設置「檔案」選單 + JMenu fileMenu = new JMenu("檔案"); + JMenuItem menuOpen = new JMenuItem("開啟舊檔"); + // 快速鍵設置 menuOpen.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_O, InputEvent.CTRL_MASK)); - JMenuItem menuSave = new JMenuItem("�x�s�ɮ�"); + JMenuItem menuSave = new JMenuItem("儲存檔案"); menuSave.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_S, InputEvent.CTRL_MASK)); - JMenuItem menuSaveAs = new JMenuItem("�t�s�s��"); + JMenuItem menuSaveAs = new JMenuItem("另存新檔"); - JMenuItem menuClose = new JMenuItem("����"); + JMenuItem menuClose = new JMenuItem("關閉"); menuClose.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_Q, InputEvent.CTRL_MASK)); fileMenu.add(menuOpen); - fileMenu.addSeparator(); // ���j�u + fileMenu.addSeparator(); // 分隔線 fileMenu.add(menuSave); fileMenu.add(menuSaveAs); - fileMenu.addSeparator(); // ���j�u + fileMenu.addSeparator(); // 分隔線 fileMenu.add(menuClose); - // �]�m�u�s��v��� - JMenu editMenu = new JMenu("�s��"); - JMenuItem menuCut = new JMenuItem("�ŤU"); + // 設置「編輯」選單 + JMenu editMenu = new JMenu("編輯"); + JMenuItem menuCut = new JMenuItem("剪下"); menuCut.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); - JMenuItem menuCopy = new JMenuItem("�ƻs"); + JMenuItem menuCopy = new JMenuItem("複製"); menuCopy.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK)); - JMenuItem menuPaste = new JMenuItem("�K�W"); + JMenuItem menuPaste = new JMenuItem("貼上"); menuPaste.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK)); @@ -78,9 +78,9 @@ private void setUpUIComponent() { editMenu.add(menuCopy); editMenu.add(menuPaste); - // �]�m�u����v��� - JMenu aboutMenu = new JMenu("����"); - JMenuItem menuAbout = new JMenuItem("����JNotePad"); + // 設置「關於」選單 + JMenu aboutMenu = new JMenu("關於"); + JMenuItem menuAbout = new JMenuItem("關於JNotePad"); aboutMenu.add(menuAbout); menuBar.add(fileMenu); @@ -89,9 +89,9 @@ private void setUpUIComponent() { setJMenuBar(menuBar); - // ��r�s��ϰ� + // 文字編輯區域 JTextArea textArea = new JTextArea(); - textArea.setFont(new Font("�ө���", Font.PLAIN, 16)); + textArea.setFont(new Font("細明體", Font.PLAIN, 16)); textArea.setLineWrap(true); JScrollPane panel = new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, @@ -100,8 +100,8 @@ private void setUpUIComponent() { Container contentPane = getContentPane(); contentPane.add(panel, BorderLayout.CENTER); - // ���A�C - JLabel stateBar = new JLabel("���ק�"); + // 狀態列 + JLabel stateBar = new JLabel("未修改"); stateBar.setHorizontalAlignment(SwingConstants.LEFT); stateBar.setBorder( BorderFactory.createEtchedBorder()); diff --git a/example/CH19/19.3/onlyfun/caterpillar/JNotePadUI.java b/example/CH19/19.3/onlyfun/caterpillar/JNotePadUI.java index 9b8fba7..0a94763 100644 --- a/example/CH19/19.3/onlyfun/caterpillar/JNotePadUI.java +++ b/example/CH19/19.3/onlyfun/caterpillar/JNotePadUI.java @@ -45,7 +45,7 @@ public class JNotePadUI extends JFrame { private JPopupMenu popUpMenu; public JNotePadUI() { - super("�s�W��r�ɮ�"); + super("新增文字檔案"); setUpUIComponent(); setUpEventListener(); setVisible(true); @@ -54,48 +54,48 @@ public JNotePadUI() { private void setUpUIComponent() { setSize(640, 480); - // ���C + // 選單列 JMenuBar menuBar = new JMenuBar(); - // �]�m�u�ɮסv��� - JMenu fileMenu = new JMenu("�ɮ�"); - menuOpen = new JMenuItem("�}������"); - // �ֳt��]�m + // 設置「檔案」選單 + JMenu fileMenu = new JMenu("檔案"); + menuOpen = new JMenuItem("開啟舊檔"); + // 快速鍵設置 menuOpen.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_O, InputEvent.CTRL_MASK)); - menuSave = new JMenuItem("�x�s�ɮ�"); + menuSave = new JMenuItem("儲存檔案"); menuSave.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_S, InputEvent.CTRL_MASK)); - menuSaveAs = new JMenuItem("�t�s�s��"); + menuSaveAs = new JMenuItem("另存新檔"); - menuClose = new JMenuItem("����"); + menuClose = new JMenuItem("關閉"); menuClose.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_Q, InputEvent.CTRL_MASK)); fileMenu.add(menuOpen); - fileMenu.addSeparator(); // ���j�u + fileMenu.addSeparator(); // 分隔線 fileMenu.add(menuSave); fileMenu.add(menuSaveAs); - fileMenu.addSeparator(); // ���j�u + fileMenu.addSeparator(); // 分隔線 fileMenu.add(menuClose); - // �]�m�u�s��v��� - editMenu = new JMenu("�s��"); - menuCut = new JMenuItem("�ŤU"); + // 設置「編輯」選單 + editMenu = new JMenu("編輯"); + menuCut = new JMenuItem("剪下"); menuCut.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); - menuCopy = new JMenuItem("�ƻs"); + menuCopy = new JMenuItem("複製"); menuCopy.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK)); - menuPaste = new JMenuItem("�K�W"); + menuPaste = new JMenuItem("貼上"); menuPaste.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK)); @@ -103,9 +103,9 @@ private void setUpUIComponent() { editMenu.add(menuCopy); editMenu.add(menuPaste); - // �]�m�u����v��� - JMenu aboutMenu = new JMenu("����"); - menuAbout = new JMenuItem("����JNotePad"); + // 設置「關於」選單 + JMenu aboutMenu = new JMenu("關於"); + menuAbout = new JMenuItem("關於JNotePad"); aboutMenu.add(menuAbout); menuBar.add(fileMenu); @@ -114,9 +114,9 @@ private void setUpUIComponent() { setJMenuBar(menuBar); - // ��r�s��ϰ� + // 文字編輯區域 textArea = new JTextArea(); - textArea.setFont(new Font("�ө���", Font.PLAIN, 16)); + textArea.setFont(new Font("細明體", Font.PLAIN, 16)); textArea.setLineWrap(true); JScrollPane panel = new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, @@ -125,8 +125,8 @@ private void setUpUIComponent() { Container contentPane = getContentPane(); contentPane.add(panel, BorderLayout.CENTER); - // ���A�C - JLabel stateBar = new JLabel("���ק�"); + // 狀態列 + JLabel stateBar = new JLabel("未修改"); stateBar.setHorizontalAlignment(SwingConstants.LEFT); stateBar.setBorder( BorderFactory.createEtchedBorder()); @@ -136,7 +136,7 @@ private void setUpUIComponent() { } private void setUpEventListener() { - // ���U���������s�ƥ�B�z + // 按下視窗關閉鈕事件處理 addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { @@ -145,7 +145,7 @@ public void windowClosing(WindowEvent e) { } ); - // ��� - �}������ + // 選單 - 開啟舊檔 menuOpen.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -154,7 +154,7 @@ public void actionPerformed(ActionEvent e) { } ); - // ��� - �x�s�ɮ� + // 選單 - 儲存檔案 menuSave.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -163,7 +163,7 @@ public void actionPerformed(ActionEvent e) { } ); - // ��� - �t�s�s�� + // 選單 - 另存新檔 menuSaveAs.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -173,7 +173,7 @@ public void actionPerformed(ActionEvent e) { ); - // ��� - �����ɮ� + // 選單 - 關閉檔案 menuClose.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -182,7 +182,7 @@ public void actionPerformed(ActionEvent e) { } ); - // ��� - �ŤU + // 選單 - 剪下 menuCut.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -191,7 +191,7 @@ public void actionPerformed(ActionEvent e) { } ); - // ��� - �ƻs + // 選單 - 複製 menuCopy.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -200,7 +200,7 @@ public void actionPerformed(ActionEvent e) { } ); - // ��� - �K�W + // 選單 - 貼上 menuPaste.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -209,19 +209,19 @@ public void actionPerformed(ActionEvent e) { } ); - // ��� - ���� + // 選單 - 關於 menuAbout.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { - // ��ܹ�ܤ�� + // 顯示對話方塊 JOptionPane.showOptionDialog(null, - "�{���W��:\n JNotePad \n" + - "�{���]�p:\n �}����\n" + - "²��:\n �@��²�檺��r�s�边\n" + - " �i�@���禬Java����@��H\n" + - " �w����ͤU����s��y\n\n" + + "程式名稱:\n JNotePad \n" + + "程式設計:\n 良葛格\n" + + "簡介:\n 一個簡單的文字編輯器\n" + + " 可作為驗收Java的實作對象\n" + + " 歡迎網友下載研究交流\n\n" + "http://caterpillar.onlyfun.net/", - "����JNotePad", + "關於JNotePad", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null); @@ -229,7 +229,7 @@ public void actionPerformed(ActionEvent e) { } ); - // �s�����L�ƥ� + // 編輯區鍵盤事件 textArea.addKeyListener( new KeyAdapter() { public void keyTyped(KeyEvent e) { @@ -238,7 +238,7 @@ public void keyTyped(KeyEvent e) { } ); - // �s��Ϸƹ��ƥ� + // 編輯區滑鼠事件 textArea.addMouseListener( new MouseAdapter() { public void mouseReleased(MouseEvent e) { diff --git a/example/CH19/19.4/onlyfun/caterpillar/JNotePad.java b/example/CH19/19.4/onlyfun/caterpillar/JNotePad.java index 76d006f..2b0c8ae 100644 --- a/example/CH19/19.4/onlyfun/caterpillar/JNotePad.java +++ b/example/CH19/19.4/onlyfun/caterpillar/JNotePad.java @@ -56,7 +56,7 @@ public class JNotePad extends JFrame { private JFileChooser fileChooser; public JNotePad() { - super("�s�W��r�ɮ�"); + super("新增文字檔案"); setUpUIComponent(); setUpEventListener(); setVisible(true); @@ -65,48 +65,48 @@ public JNotePad() { private void setUpUIComponent() { setSize(640, 480); - // ���C + // 選單列 JMenuBar menuBar = new JMenuBar(); - // �]�m�u�ɮסv��� - JMenu fileMenu = new JMenu("�ɮ�"); - menuOpen = new JMenuItem("�}������"); - // �ֳt��]�m + // 設置「檔案」選單 + JMenu fileMenu = new JMenu("檔案"); + menuOpen = new JMenuItem("開啟舊檔"); + // 快速鍵設置 menuOpen.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_O, InputEvent.CTRL_MASK)); - menuSave = new JMenuItem("�x�s�ɮ�"); + menuSave = new JMenuItem("儲存檔案"); menuSave.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_S, InputEvent.CTRL_MASK)); - menuSaveAs = new JMenuItem("�t�s�s��"); + menuSaveAs = new JMenuItem("另存新檔"); - menuClose = new JMenuItem("����"); + menuClose = new JMenuItem("關閉"); menuClose.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_Q, InputEvent.CTRL_MASK)); fileMenu.add(menuOpen); - fileMenu.addSeparator(); // ���j�u + fileMenu.addSeparator(); // 分隔線 fileMenu.add(menuSave); fileMenu.add(menuSaveAs); - fileMenu.addSeparator(); // ���j�u + fileMenu.addSeparator(); // 分隔線 fileMenu.add(menuClose); - // �]�m�u�s��v��� - editMenu = new JMenu("�s��"); - menuCut = new JMenuItem("�ŤU"); + // 設置「編輯」選單 + editMenu = new JMenu("編輯"); + menuCut = new JMenuItem("剪下"); menuCut.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); - menuCopy = new JMenuItem("�ƻs"); + menuCopy = new JMenuItem("複製"); menuCopy.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK)); - menuPaste = new JMenuItem("�K�W"); + menuPaste = new JMenuItem("貼上"); menuPaste.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK)); @@ -114,9 +114,9 @@ private void setUpUIComponent() { editMenu.add(menuCopy); editMenu.add(menuPaste); - // �]�m�u����v��� - JMenu aboutMenu = new JMenu("����"); - menuAbout = new JMenuItem("����JNotePad"); + // 設置「關於」選單 + JMenu aboutMenu = new JMenu("關於"); + menuAbout = new JMenuItem("關於JNotePad"); aboutMenu.add(menuAbout); menuBar.add(fileMenu); @@ -125,9 +125,9 @@ private void setUpUIComponent() { setJMenuBar(menuBar); - // ��r�s��ϰ� + // 文字編輯區域 textArea = new JTextArea(); - textArea.setFont(new Font("�ө���", Font.PLAIN, 16)); + textArea.setFont(new Font("細明體", Font.PLAIN, 16)); textArea.setLineWrap(true); JScrollPane panel = new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, @@ -136,8 +136,8 @@ private void setUpUIComponent() { Container contentPane = getContentPane(); contentPane.add(panel, BorderLayout.CENTER); - // ���A�C - stateBar = new JLabel("���ק�"); + // 狀態列 + stateBar = new JLabel("未修改"); stateBar.setHorizontalAlignment(SwingConstants.LEFT); stateBar.setBorder( BorderFactory.createEtchedBorder()); @@ -149,7 +149,7 @@ private void setUpUIComponent() { } private void setUpEventListener() { - // ���U���������s�ƥ�B�z + // 按下視窗關閉鈕事件處理 addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { @@ -158,7 +158,7 @@ public void windowClosing(WindowEvent e) { } ); - // ��� - �}������ + // 選單 - 開啟舊檔 menuOpen.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -167,7 +167,7 @@ public void actionPerformed(ActionEvent e) { } ); - // ��� - �x�s�ɮ� + // 選單 - 儲存檔案 menuSave.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -176,7 +176,7 @@ public void actionPerformed(ActionEvent e) { } ); - // ��� - �t�s�s�� + // 選單 - 另存新檔 menuSaveAs.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -185,7 +185,7 @@ public void actionPerformed(ActionEvent e) { } ); - // ��� - �����ɮ� + // 選單 - 關閉檔案 menuClose.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -194,7 +194,7 @@ public void actionPerformed(ActionEvent e) { } ); - // ��� - �ŤU + // 選單 - 剪下 menuCut.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -203,7 +203,7 @@ public void actionPerformed(ActionEvent e) { } ); - // ��� - �ƻs + // 選單 - 複製 menuCopy.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -212,7 +212,7 @@ public void actionPerformed(ActionEvent e) { } ); - // ��� - �K�W + // 選單 - 貼上 menuPaste.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -221,19 +221,19 @@ public void actionPerformed(ActionEvent e) { } ); - // ��� - ���� + // 選單 - 關於 menuAbout.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { - // ��ܹ�ܤ�� + // 顯示對話方塊 JOptionPane.showOptionDialog(null, - "�{���W��:\n JNotePad \n" + - "�{���]�p:\n �}����\n" + - "²��:\n �@��²�檺��r�s�边\n" + - " �i�@���禬Java����@��H\n" + - " �w����ͤU����s��y\n\n" + + "程式名稱:\n JNotePad \n" + + "程式設計:\n 良葛格\n" + + "簡介:\n 一個簡單的文字編輯器\n" + + " 可作為驗收Java的實作對象\n" + + " 歡迎網友下載研究交流\n\n" + "http://caterpillar.onlyfun.net/", - "����JNotePad", + "關於JNotePad", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null); @@ -241,7 +241,7 @@ public void actionPerformed(ActionEvent e) { } ); - // �s�����L�ƥ� + // 編輯區鍵盤事件 textArea.addKeyListener( new KeyAdapter() { public void keyTyped(KeyEvent e) { @@ -250,7 +250,7 @@ public void keyTyped(KeyEvent e) { } ); - // �s��Ϸƹ��ƥ� + // 編輯區滑鼠事件 textArea.addMouseListener( new MouseAdapter() { public void mouseReleased(MouseEvent e) { @@ -267,21 +267,21 @@ public void mouseClicked(MouseEvent e) { } private void openFile() { - if(isCurrentFileSaved()) { // ���O�_���x�s���A - open(); // �}������ + if(isCurrentFileSaved()) { // 文件是否為儲存狀態 + open(); // 開啟舊檔 } else { - // ��ܹ�ܤ�� + // 顯示對話方塊 int option = JOptionPane.showConfirmDialog( - null, "�ɮפw�ק�A�O�_�x�s�H", - "�x�s�ɮסH", JOptionPane.YES_NO_OPTION, + null, "檔案已修改,是否儲存?", + "儲存檔案?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null); switch(option) { - // �T�{�ɮ��x�s + // 確認檔案儲存 case JOptionPane.YES_OPTION: - saveFile(); // �x�s�ɮ� + saveFile(); // 儲存檔案 break; - // ����ɮ��x�s + // 放棄檔案儲存 case JOptionPane.NO_OPTION: open(); break; @@ -290,28 +290,28 @@ private void openFile() { } private void open() { - // fileChooser �O JFileChooser ����� - // ����ɮ׿������ܤ�� + // fileChooser 是 JFileChooser 的實例 + // 顯示檔案選取的對話方塊 int option = fileChooser.showDialog(null, null); - // �ϥΪ̫��U�T�{�� + // 使用者按下確認鍵 if(option == JFileChooser.APPROVE_OPTION) { try { - // �}�ҿ�����ɮ� + // 開啟選取的檔案 BufferedReader buf = new BufferedReader( new FileReader( fileChooser.getSelectedFile())); - // �]�w�����D + // 設定文件標題 setTitle(fileChooser.getSelectedFile().toString()); - // �M���e�@����� + // 清除前一次文件 textArea.setText(""); - // �]�w���A�C - stateBar.setText("���ק�"); - // ���o�t�ά̪ۨ�����r�� + // 設定狀態列 + stateBar.setText("未修改"); + // 取得系統相依的換行字元 String lineSeparator = System.getProperty("line.separator"); - // Ū���ɮרê��[�ܤ�r�s��� + // 讀取檔案並附加至文字編輯區 String text; while((text = buf.readLine()) != null) { textArea.append(text); @@ -322,13 +322,13 @@ private void open() { } catch(IOException e) { JOptionPane.showMessageDialog(null, e.toString(), - "�}���ɮץ���", JOptionPane.ERROR_MESSAGE); + "開啟檔案失敗", JOptionPane.ERROR_MESSAGE); } } } private boolean isCurrentFileSaved() { - if(stateBar.getText().equals("�w�ק�")) { + if(stateBar.getText().equals("已修改")) { return false; } else { @@ -337,68 +337,68 @@ private boolean isCurrentFileSaved() { } private void saveFile() { - // �q���D�C���o�ɮצW�� + // 從標題列取得檔案名稱 File file = new File(getTitle()); - // �Y���w���ɮפ��s�b + // 若指定的檔案不存在 if(!file.exists()) { - // ����t�s�s�� + // 執行另存新檔 saveFileAs(); } else { try { - // �}�ҫ��w���ɮ� + // 開啟指定的檔案 BufferedWriter buf = new BufferedWriter( new FileWriter(file)); - // �N��r�s��Ϫ���r�g�J�ɮ� + // 將文字編輯區的文字寫入檔案 buf.write(textArea.getText()); buf.close(); - // �]�w���A�C�����ק� - stateBar.setText("���ק�"); + // 設定狀態列為未修改 + stateBar.setText("未修改"); } catch(IOException e) { JOptionPane.showMessageDialog(null, e.toString(), - "�g�J�ɮץ���", JOptionPane.ERROR_MESSAGE); + "寫入檔案失敗", JOptionPane.ERROR_MESSAGE); } } } private void saveFileAs() { - // ����ɮ׹�ܤ�� + // 顯示檔案對話方塊 int option = fileChooser.showDialog(null, null); - // �p�G�T�{����ɮ� + // 如果確認選取檔案 if(option == JFileChooser.APPROVE_OPTION) { - // ���o��ܪ��ɮ� + // 取得選擇的檔案 File file = fileChooser.getSelectedFile(); - // �b���D�C�W�]�w�ɮצW�� + // 在標題列上設定檔案名稱 setTitle(file.toString()); try { - // �إ��ɮ� + // 建立檔案 file.createNewFile(); - // �i���ɮ��x�s + // 進行檔案儲存 saveFile(); } catch(IOException e) { JOptionPane.showMessageDialog(null, e.toString(), - "�L�k�إ߷s��", JOptionPane.ERROR_MESSAGE); + "無法建立新檔", JOptionPane.ERROR_MESSAGE); } } } private void closeFile() { - // �O�_�w�x�s��� + // 是否已儲存文件 if(isCurrentFileSaved()) { - // ��������귽�A�ӫ������{�� + // 釋放視窗資源,而後關閉程式 dispose(); } else { int option = JOptionPane.showConfirmDialog( - null, "�ɮפw�ק�A�O�_�x�s�H", - "�x�s�ɮסH", JOptionPane.YES_NO_OPTION, + null, "檔案已修改,是否儲存?", + "儲存檔案?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null); switch(option) { @@ -413,7 +413,7 @@ private void closeFile() { private void cut() { textArea.cut(); - stateBar.setText("�w�ק�"); + stateBar.setText("已修改"); popUpMenu.setVisible(false); } @@ -424,12 +424,12 @@ private void copy() { private void paste() { textArea.paste(); - stateBar.setText("�w�ק�"); + stateBar.setText("已修改"); popUpMenu.setVisible(false); } private void processTextArea() { - stateBar.setText("�w�ק�"); + stateBar.setText("已修改"); } public static void main(String[] args) { diff --git a/example/CH20/BasicDBSource.java b/example/CH20/BasicDBSource.java index 455674b..350003e 100644 --- a/example/CH20/BasicDBSource.java +++ b/example/CH20/BasicDBSource.java @@ -14,7 +14,7 @@ public class BasicDBSource implements DBSource { private String url; private String user; private String passwd; - private int max; // �s�������̤jConnection�ƥ� + private int max; // 連接池中最大Connection數目 private List connections; public BasicDBSource() throws IOException, ClassNotFoundException { diff --git a/example/CH20/ConnectionDemo.java b/example/CH20/ConnectionDemo.java index 7f8f564..9b32eb1 100644 --- a/example/CH20/ConnectionDemo.java +++ b/example/CH20/ConnectionDemo.java @@ -11,13 +11,13 @@ public static void main(String[] args) { Connection conn = dbsource.getConnection(); if(!conn.isClosed()) { - System.out.println("��Ʈw�s�u�w�}�ҡK"); + System.out.println("資料庫連線已開啟…"); } dbsource.closeConnection(conn); if(conn.isClosed()) { - System.out.println("��Ʈw�s�u�w�����K"); + System.out.println("資料庫連線已關閉…"); } } catch (IOException e) { diff --git a/example/CH20/LobDemo.java b/example/CH20/LobDemo.java index f20ccba..05debf9 100644 --- a/example/CH20/LobDemo.java +++ b/example/CH20/LobDemo.java @@ -13,12 +13,12 @@ public static void main(String[] args) { dbsource = new SimpleDBSource(); conn = dbsource.getConnection(); - // ���o�ɮ� + // 取得檔案 File file = new File(args[0]); int length = (int) file.length(); InputStream fin = new FileInputStream(file); - // ��J��Ʈw + // 填入資料庫 pstmt = conn.prepareStatement( "INSERT INTO t_file VALUES(?, ?, ?)"); pstmt.setInt(1, 1); @@ -51,7 +51,7 @@ public static void main(String[] args) { Statement stmt = null; try { - // �q��Ʈw���X�ɮ� + // 從資料庫取出檔案 stmt = conn.createStatement(); ResultSet result = stmt.executeQuery( "SELECT * FROM t_file"); @@ -59,7 +59,7 @@ public static void main(String[] args) { String filename = result.getString(2); Blob blob = result.getBlob(3); - // �g�J�ɮ� + // 寫入檔案 FileOutputStream fout = new FileOutputStream(filename + ".bak"); fout.write(blob.getBytes(1, (int)blob.length())); diff --git a/example/CH21/BinarySearchDemo.java b/example/CH21/BinarySearchDemo.java index bb01835..71543e5 100644 --- a/example/CH21/BinarySearchDemo.java +++ b/example/CH21/BinarySearchDemo.java @@ -8,10 +8,10 @@ public static void main(String[] args) { int result = Arrays.binarySearch(arr1, 6, 9, 85); if(result > -1) { - System.out.printf("���� %d �B�����%n", result); + System.out.printf("索引 %d 處找到資料%n", result); } else { - System.out.printf("���J�I %d %n", (result + 1) * -1); + System.out.printf("插入點 %d %n", (result + 1) * -1); } } } \ No newline at end of file diff --git a/example/CH21/CalendarDemo.java b/example/CH21/CalendarDemo.java index 9c92521..af3bdf3 100644 --- a/example/CH21/CalendarDemo.java +++ b/example/CH21/CalendarDemo.java @@ -8,13 +8,13 @@ public static void main(String[] args) { Calendar rightNow = Calendar.getInstance(); Locale locale = Locale.getDefault(); - System.out.println("�{�b�ɶ��O�G"); - System.out.printf("%s�G%d %n", + System.out.println("現在時間是:"); + System.out.printf("%s:%d %n", rightNow.getDisplayName(ERA, LONG, locale), rightNow.get(YEAR)); System.out.println( rightNow.getDisplayName(MONTH, LONG, locale)); - System.out.printf("%d ��%n", + System.out.printf("%d 日%n", rightNow.get(DAY_OF_MONTH)); System.out.println( rightNow.getDisplayName(DAY_OF_WEEK, LONG, locale)); diff --git a/example/CH21/ConnectionDemo.java b/example/CH21/ConnectionDemo.java index 15879be..d34fb4f 100644 --- a/example/CH21/ConnectionDemo.java +++ b/example/CH21/ConnectionDemo.java @@ -11,13 +11,13 @@ public static void main(String[] args) { Connection conn = dbsource.getConnection(); if(!conn.isClosed()) { - System.out.println("��Ʈw�s���w�}�ҡK"); + System.out.println("資料庫連接已開啟…"); } dbsource.closeConnection(conn); if(conn.isClosed()) { - System.out.println("��Ʈw�s���w�����K"); + System.out.println("資料庫連接已關閉…"); } } catch (IOException e) { diff --git a/example/CH21/FileDemo.java b/example/CH21/FileDemo.java index 35b54d8..045eda2 100644 --- a/example/CH21/FileDemo.java +++ b/example/CH21/FileDemo.java @@ -6,7 +6,7 @@ public class FileDemo { public static void main(String[] args) { File[] roots = File.listRoots(); for(File root : roots) { - System.out.printf("%s �`�e�q %d�A�i�ήe�q %d %n", + System.out.printf("%s 總容量 %d,可用容量 %d %n", root.getPath(), root.getTotalSpace(), root.getUsableSpace()); } } diff --git a/example/CH21/PasswordDemo.java b/example/CH21/PasswordDemo.java index 6a3ab6b..d0bbb20 100644 --- a/example/CH21/PasswordDemo.java +++ b/example/CH21/PasswordDemo.java @@ -3,20 +3,20 @@ public class PasswordDemo { public static void main(String[] args) { while(true) { - System.out.print("��J�W�١G"); + System.out.print("輸入名稱:"); String name = System.console().readLine(); - System.out.print("��J�K�X�G "); + System.out.print("輸入密碼: "); char[] passwd = System.console().readPassword(); String password = new String(passwd); if("caterpillar".equals(name) && "123456".equals(password)) { - System.out.println("�w�� caterpillar "); + System.out.println("歡迎 caterpillar "); break; } else { - System.out.printf("%s�A�W�٩αK�X���~�A�Э��s��J�I%n", name); + System.out.printf("%s,名稱或密碼錯誤,請重新輸入!%n", name); } } diff --git a/example/CH21/PasswordDemo2.java b/example/CH21/PasswordDemo2.java index 0a33b19..bde21e0 100644 --- a/example/CH21/PasswordDemo2.java +++ b/example/CH21/PasswordDemo2.java @@ -7,18 +7,18 @@ public static void main(String[] args) { Console console = System.console(); while(true) { - String name = console.readLine("[%s] ", "��J�W�١K"); + String name = console.readLine("[%s] ", "輸入名稱…"); - char[] passwd = console.readPassword("[%s]", "��J�K�X�K"); + char[] passwd = console.readPassword("[%s]", "輸入密碼…"); String password = new String(passwd); if("caterpillar".equals(name) && "123456".equals(password)) { - System.out.println("�w�� caterpillar "); + System.out.println("歡迎 caterpillar "); break; } else { - System.out.printf("%s�A�W�٩αK�X���~�A�Э��s��J�I%n", name); + System.out.printf("%s,名稱或密碼錯誤,請重新輸入!%n", name); } } diff --git a/example/CH21/SystemTrayDemo.java b/example/CH21/SystemTrayDemo.java index 2d35b14..a9cdd67 100644 --- a/example/CH21/SystemTrayDemo.java +++ b/example/CH21/SystemTrayDemo.java @@ -12,11 +12,11 @@ public static void main(String[] args) { try { tray.add(trayIcon); } catch (AWTException e) { - System.err.println("�L�k�[�J�t�Τu��C�ϥ�"); + System.err.println("無法加入系統工具列圖示"); e.printStackTrace(); } } else { - System.err.println("�L�k���o�t�Τu��C"); + System.err.println("無法取得系統工具列"); } } } \ No newline at end of file diff --git a/example/CH21/SystemTrayDemo2.java b/example/CH21/SystemTrayDemo2.java index 4278440..20b6a24 100644 --- a/example/CH21/SystemTrayDemo2.java +++ b/example/CH21/SystemTrayDemo2.java @@ -10,17 +10,17 @@ public static void main(String[] args) { Image image = Toolkit.getDefaultToolkit() .getImage("musical_note_smile.gif"); PopupMenu popup = new PopupMenu(); - MenuItem item = new MenuItem("�}��JNotePad 1.0"); + MenuItem item = new MenuItem("開啟JNotePad 1.0"); popup.add(item); TrayIcon trayIcon = new TrayIcon(image, "JNotePad 1.0", popup); try { tray.add(trayIcon); } catch (AWTException e) { - System.err.println("�L�k�[�J�t�Τu��C�ϥ�"); + System.err.println("無法加入系統工具列圖示"); e.printStackTrace(); } } else { - System.err.println("�L�k���o�t�Τu��C"); + System.err.println("無法取得系統工具列"); } } } \ No newline at end of file diff --git a/example/CH21/SystemTrayDemo3.java b/example/CH21/SystemTrayDemo3.java index 4c08e4d..81eb3d2 100644 --- a/example/CH21/SystemTrayDemo3.java +++ b/example/CH21/SystemTrayDemo3.java @@ -11,13 +11,13 @@ public static void main(String[] args) { Image image = Toolkit.getDefaultToolkit() .getImage("musical_note_smile.gif"); PopupMenu popup = new PopupMenu(); - MenuItem item = new MenuItem("�}��JNotePad 1.0"); + MenuItem item = new MenuItem("開啟JNotePad 1.0"); popup.add(item); final TrayIcon trayIcon = new TrayIcon(image, "JNotePad 1.0", popup); ActionListener menuActionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { -trayIcon.displayMessage("���o", "�ӥ𮧤F�ܡH", +trayIcon.displayMessage("哈囉", "該休息了嗎?", TrayIcon.MessageType.WARNING); } @@ -26,11 +26,11 @@ public void actionPerformed(ActionEvent e) { try { tray.add(trayIcon); } catch (AWTException e) { - System.err.println("�L�k�[�J�t�Τu��C�ϥ�"); + System.err.println("無法加入系統工具列圖示"); e.printStackTrace(); } } else { - System.err.println("�L�k���o�t�Τu��C"); + System.err.println("無法取得系統工具列"); } } } \ No newline at end of file diff --git a/example/CH3/BitwiseOperator.java b/example/CH3/BitwiseOperator.java index 0946d2d..26065be 100644 --- a/example/CH3/BitwiseOperator.java +++ b/example/CH3/BitwiseOperator.java @@ -1,4 +1,4 @@ -public class BitwiseOperator { +public class BitwiseOperator { public static void main(String[] args) { System.out.println("AND運算:"); System.out.println("0 AND 0\t\t" + (0 & 0)); diff --git a/example/CH3/ComparisonOperator.java b/example/CH3/ComparisonOperator.java index 6792232..56b2fc3 100644 --- a/example/CH3/ComparisonOperator.java +++ b/example/CH3/ComparisonOperator.java @@ -1,10 +1,10 @@ public class ComparisonOperator { public static void main(String[] args) { - System.out.println("10 > 5 ���G " + (10 > 5)); - System.out.println("10 >= 5 ���G " + (10 >= 5)); - System.out.println("10 < 5 ���G " + (10 < 5)); - System.out.println("10 <= 5 ���G " + (10 <= 5)); - System.out.println("10 == 5 ���G " + (10 == 5)); - System.out.println("10 != 5 ���G " + (10 != 5)); + System.out.println("10 > 5 結果 " + (10 > 5)); + System.out.println("10 >= 5 結果 " + (10 >= 5)); + System.out.println("10 < 5 結果 " + (10 < 5)); + System.out.println("10 <= 5 結果 " + (10 <= 5)); + System.out.println("10 == 5 結果 " + (10 == 5)); + System.out.println("10 != 5 結果 " + (10 != 5)); } } \ No newline at end of file diff --git a/example/CH3/DataRange.java b/example/CH3/DataRange.java index b302a79..3836559 100644 --- a/example/CH3/DataRange.java +++ b/example/CH3/DataRange.java @@ -1,16 +1,16 @@ public class DataRange { public static void main(String[] args) { - System.out.printf("short \t�ƭȽd��G%d ~ %d\n", + System.out.printf("short \t數值範圍:%d ~ %d\n", Short.MAX_VALUE, Short.MIN_VALUE); - System.out.printf("int \t�ƭȽd��G%d ~ %d\n", + System.out.printf("int \t數值範圍:%d ~ %d\n", Integer.MAX_VALUE, Integer.MIN_VALUE); - System.out.printf("long \t�ƭȽd��G%d ~ %d\n", + System.out.printf("long \t數值範圍:%d ~ %d\n", Long.MAX_VALUE, Long.MIN_VALUE); - System.out.printf("byte \t�ƭȽd��G%d ~ %d\n", + System.out.printf("byte \t數值範圍:%d ~ %d\n", Byte.MAX_VALUE, Byte.MIN_VALUE); - System.out.printf("float \t�ƭȽd��G%e ~ %e\n", + System.out.printf("float \t數值範圍:%e ~ %e\n", Float.MAX_VALUE, Float.MIN_VALUE); - System.out.printf("double \t�ƭȽd��G%e ~ %e\n", + System.out.printf("double \t數值範圍:%e ~ %e\n", Double.MAX_VALUE, Double.MIN_VALUE); } } \ No newline at end of file diff --git a/example/CH3/ErrDemo.java b/example/CH3/ErrDemo.java index a64dcd0..954fc26 100644 --- a/example/CH3/ErrDemo.java +++ b/example/CH3/ErrDemo.java @@ -1,6 +1,6 @@ public class ErrDemo { public static void main(String[] args) { - System.out.println("�ϥ�out��X�T��"); - System.err.println("�ϥ�err��X�T��"); + System.out.println("使用out輸出訊息"); + System.err.println("使用err輸出訊息"); } } \ No newline at end of file diff --git a/example/CH4/AutoBoxDemo.java b/example/CH4/AutoBoxDemo.java index 3dfead7..d395b1a 100644 --- a/example/CH4/AutoBoxDemo.java +++ b/example/CH4/AutoBoxDemo.java @@ -3,10 +3,10 @@ public static void main(String[] args) { Integer data1 = 10; Integer data2 = 20; - // �ରdouble�ȦA���H3 + // 轉為double值再除以3 System.out.println(data1.doubleValue() / 3); - // �i���ӭȪ���� + // 進行兩個值的比較 System.out.println(data1.compareTo(data2)); } } \ No newline at end of file diff --git a/example/CH4/StringDemo.java b/example/CH4/StringDemo.java index 1eab01d..c9b08c6 100644 --- a/example/CH4/StringDemo.java +++ b/example/CH4/StringDemo.java @@ -2,21 +2,21 @@ public class StringDemo { public static void main(String[] args) { String text = "Have a nice day!! :)"; - System.out.println("���G" + text); + System.out.println("原文:" + text); - // �Ǧ^�����j�g���r�ꤺ�e - System.out.println("�j�g�G" + text.toUpperCase()); + // 傳回全為大寫的字串內容 + System.out.println("大寫:" + text.toUpperCase()); - // ��^�����p�g���r�ꤺ�e - System.out.println("�p�g�G" + text.toLowerCase()); + // 轉回全為小寫的字串內容 + System.out.println("小寫:" + text.toLowerCase()); - // �p��r����� - System.out.println("���סG" + text.length()); + // 計算字串長度 + System.out.println("長度:" + text.length()); - // �Ǧ^���N��r�᪺�r�� - System.out.println("���N�G" + text.replaceAll("nice", "good")); + // 傳回取代文字後的字串 + System.out.println("取代:" + text.replaceAll("nice", "good")); - // �Ǧ^���w��m�᪺�l�r�� - System.out.println("�l�r��G" + text.substring(5)); + // 傳回指定位置後的子字串 + System.out.println("子字串:" + text.substring(5)); } } \ No newline at end of file diff --git a/example/CH4/UserLogin.java b/example/CH4/UserLogin.java index 3ff8d58..a538fd2 100644 --- a/example/CH4/UserLogin.java +++ b/example/CH4/UserLogin.java @@ -4,20 +4,20 @@ public class UserLogin { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); - System.out.print("�ϥΪ̦W�١G"); + System.out.print("使用者名稱:"); String username = scanner.next(); - System.out.print("�ϥΪ̱K�X�G"); + System.out.print("使用者密碼:"); String password = scanner.next(); if("caterpillar".equals(username) && "1975".equals(password)) { - System.out.println("���K��T�b���I"); + System.out.println("秘密資訊在此!"); } else { System.out.println(username + - " �z�n�A��J���n�J��Ʀ��~�A�Э��s��J�I"); + " 您好,輸入的登入資料有誤,請重新輸入!"); } } } \ No newline at end of file diff --git a/example/CH4/WrapperDemo.java b/example/CH4/WrapperDemo.java index 4872f65..4c1e172 100644 --- a/example/CH4/WrapperDemo.java +++ b/example/CH4/WrapperDemo.java @@ -3,17 +3,17 @@ public static void main(String[] args) { int data1 = 10; int data2 = 20; - // �ϥ�Integer�ӥ]��int��� + // 使用Integer來包裏int資料 Integer data1Wrapper = new Integer(data1); Integer data2Wrapper = new Integer(data2); - // �������H3 + // 直接除以3 System.out.println(data1 / 3); - // �ରdouble�ȦA���H3 + // 轉為double值再除以3 System.out.println(data1Wrapper.doubleValue() / 3); - // �i���ӭȪ���� + // 進行兩個值的比較 System.out.println(data1Wrapper.compareTo(data2Wrapper)); } } \ No newline at end of file diff --git a/example/CH5/AdvancedArray.java b/example/CH5/AdvancedArray.java index efb94e8..9833c42 100644 --- a/example/CH5/AdvancedArray.java +++ b/example/CH5/AdvancedArray.java @@ -4,20 +4,20 @@ public static void main(String[] args) { int[] tmp1 = arr1; int[] tmp2 = arr1; - System.out.print("�z�Ltmp1���X�}�C�ȡG"); + System.out.print("透過tmp1取出陣列值:"); for(int i = 0; i < tmp1.length; i++) System.out.print(tmp1[i] + " "); - System.out.print("\n�z�Ltmp2���X�}�C�ȡG"); + System.out.print("\n透過tmp2取出陣列值:"); for(int i = 0; i < tmp2.length; i++) System.out.print(tmp2[i] + " "); tmp1[2] = 9; - System.out.print("\n\n�z�Ltmp1���X�}�C�ȡG"); + System.out.print("\n\n透過tmp1取出陣列值:"); for(int i = 0; i < tmp1.length; i++) System.out.print(tmp1[i] + " "); - System.out.print("\n�z�Ltmp2���X�}�C�ȡG"); + System.out.print("\n透過tmp2取出陣列值:"); for(int i = 0; i < tmp2.length; i++) System.out.print(tmp2[i] + " "); System.out.println(); diff --git a/example/CH5/AdvancedArray2.java b/example/CH5/AdvancedArray2.java index c47e0f2..c4c3cd3 100644 --- a/example/CH5/AdvancedArray2.java +++ b/example/CH5/AdvancedArray2.java @@ -4,12 +4,12 @@ public static void main(String[] args) { int[] arr2 = {5, 6, 7}; int[] tmp = arr1; - System.out.print("�ϥ�tmp���Xarr1���������G"); + System.out.print("使用tmp取出arr1中的元素:"); for(int i = 0; i < tmp.length; i++) System.out.print(tmp[i] + " "); tmp = arr2; - System.out.print("\n�ϥ�tmp���Xarr2���������G"); + System.out.print("\n使用tmp取出arr2中的元素:"); for(int i = 0; i < tmp.length; i++) System.out.print(tmp[i] + " "); System.out.println(); diff --git a/example/CH5/ArrayDemo.java b/example/CH5/ArrayDemo.java index e724577..6ed9fad 100644 --- a/example/CH5/ArrayDemo.java +++ b/example/CH5/ArrayDemo.java @@ -2,13 +2,13 @@ public class ArrayDemo { public static void main(String[] args) { int arr[] = new int[10]; - System.out.print("arr ��l��: "); + System.out.print("arr 初始值: "); for(int i = 0; i < arr.length; i++) { System.out.print(arr[i] + " "); arr[i] = i; } - System.out.print("\narr �]�w��: "); + System.out.print("\narr 設定值: "); for(int i = 0; i < arr.length; i++) System.out.print(arr[i] + " "); System.out.println(); diff --git a/example/CH5/ArraysMethodDemo.java b/example/CH5/ArraysMethodDemo.java index d892455..8416728 100644 --- a/example/CH5/ArraysMethodDemo.java +++ b/example/CH5/ArraysMethodDemo.java @@ -7,25 +7,25 @@ public static void main(String[] args) { int[] arr = {93, 5, 3, 55, 57, 7, 2 ,73, 41, 91}; - System.out.print("�Ƨǫe: "); + System.out.print("排序前: "); for(int i = 0; i < arr.length; i++) System.out.print(arr[i] + " "); System.out.println(); Arrays.sort(arr); - System.out.print("�Ƨǫ�: "); + System.out.print("排序後: "); for(int i = 0; i < arr.length; i++) System.out.print(arr[i] + " "); - System.out.print("\n�п�J�j�M��: "); + System.out.print("\n請輸入搜尋值: "); int key = scanner.nextInt(); int find = -1; if((find = Arrays.binarySearch(arr, key)) > -1) { - System.out.println("���ȩ���� " + - find + " ��m"); + System.out.println("找到值於索引 " + + find + " 位置"); } else - System.out.println("�䤣����w��"); + System.out.println("找不到指定值"); } } \ No newline at end of file diff --git a/example/CH5/AverageInput.java b/example/CH5/AverageInput.java index b05f852..b855870 100644 --- a/example/CH5/AverageInput.java +++ b/example/CH5/AverageInput.java @@ -4,24 +4,24 @@ public class AverageInput { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); - System.out.print("�п�J�ǥͤH��: "); + System.out.print("請輸入學生人數: "); int length = scanner.nextInt(); - float[] score = new float[length]; // �ʺA�t�m���� + float[] score = new float[length]; // 動態配置長度 for(int i = 0; i < score.length; i++) { - System.out.print("��J���ơG"); + System.out.print("輸入分數:"); float input = scanner.nextFloat(); score[i] = input; } - System.out.print("\n���ơG"); + System.out.print("\n分數:"); float total = 0; for(int i = 0; i < score.length; i++) { total = total + score[i]; System.out.print(score[i] + " "); } - System.out.printf("\n�����G%.2f", total / score.length); + System.out.printf("\n平均:%.2f", total / score.length); } } \ No newline at end of file diff --git a/example/CH5/NewArraysDemo.java b/example/CH5/NewArraysDemo.java index b78ba6a..30c2492 100644 --- a/example/CH5/NewArraysDemo.java +++ b/example/CH5/NewArraysDemo.java @@ -12,9 +12,9 @@ public static void main(String args[]) { {4, 6, 4}, {7, 8, 9}}; - System.out.println("arr1 ���e���� arr2 ? " + + System.out.println("arr1 內容等於 arr2 ? " + Arrays.deepEquals(arr1, arr2)); - System.out.println("arr1 ���e���� arr3 ? " + + System.out.println("arr1 內容等於 arr3 ? " + Arrays.deepEquals(arr1, arr3)); System.out.println("arr1 deepToString()\n\t" + Arrays.deepToString(arr1)); diff --git a/example/CH6/AppendStringTest.java b/example/CH6/AppendStringTest.java index 87de294..bb0118d 100644 --- a/example/CH6/AppendStringTest.java +++ b/example/CH6/AppendStringTest.java @@ -6,13 +6,13 @@ public static void main(String[] args) { for(int i = 0; i < 10000; i++) text = text + i; long endTime = System.currentTimeMillis(); - System.out.println("����ɶ��G" + (endTime - beginTime)); + System.out.println("執行時間:" + (endTime - beginTime)); StringBuilder builder = new StringBuilder(""); beginTime = System.currentTimeMillis(); for(int i = 0; i < 10000; i++) builder.append(String.valueOf(i)); endTime = System.currentTimeMillis(); - System.out.println("����ɶ��G" + (endTime - beginTime)); + System.out.println("執行時間:" + (endTime - beginTime)); } } \ No newline at end of file diff --git a/example/CH6/CharAtString.java b/example/CH6/CharAtString.java index 40c0491..ec93724 100644 --- a/example/CH6/CharAtString.java +++ b/example/CH6/CharAtString.java @@ -3,17 +3,17 @@ public static void main(String[] args) { String text = "One's left brain has nothing right.\n" + "One's right brain has nothing left.\n"; - System.out.println("�r�ꤺ�e: "); + System.out.println("字串內容: "); for(int i = 0; i < text.length(); i++) System.out.print(text.charAt(i)); - System.out.println("\n�Ĥ@��left: " + + System.out.println("\n第一個left: " + text.indexOf("left")); - System.out.println("�̫�@��left: " + + System.out.println("最後一個left: " + text.lastIndexOf("left")); char[] charArr = text.toCharArray(); - System.out.println("\n�r��Array���e: "); + System.out.println("\n字元Array內容: "); for(int i = 0; i < charArr.length; i++) System.out.print(charArr[i]); } diff --git a/example/CH6/CommandLineArg.java b/example/CH6/CommandLineArg.java index 447687f..9ea8171 100644 --- a/example/CH6/CommandLineArg.java +++ b/example/CH6/CommandLineArg.java @@ -1,6 +1,6 @@ public class CommandLineArg { public static void main(String[] args) { - System.out.print("Ū�J���޼�: "); + System.out.print("讀入的引數: "); for(int i = 0; i < args.length; i++) System.out.print(args[i] + " "); System.out.println(); diff --git a/example/CH6/CommandLineArg2.java b/example/CH6/CommandLineArg2.java index 90709f7..0ac5326 100644 --- a/example/CH6/CommandLineArg2.java +++ b/example/CH6/CommandLineArg2.java @@ -1,6 +1,6 @@ public class CommandLineArg2 { public static void main(String[] args) { - System.out.print("Ū�J���޼�: "); + System.out.print("讀入的引數: "); for(String arg : args) System.out.print(arg + " "); System.out.println(); diff --git a/example/CH6/FileFilter.java b/example/CH6/FileFilter.java index 0461636..9ad010b 100644 --- a/example/CH6/FileFilter.java +++ b/example/CH6/FileFilter.java @@ -3,7 +3,7 @@ public static void main(String[] args) { String[] filenames = {"caterpillar.jpg", "cater.gif", "bush.jpg", "wuwu.jpg", "clockman.gif"}; - System.out.print("�L�o�Xjpg�ɮ�: "); + System.out.print("過濾出jpg檔案: "); for(int i = 0; i < filenames.length; i++) { if(filenames[i].endsWith("jpg")) { diff --git a/example/CH6/StringDemo.java b/example/CH6/StringDemo.java index ade6ee0..faa08a6 100644 --- a/example/CH6/StringDemo.java +++ b/example/CH6/StringDemo.java @@ -2,13 +2,13 @@ public class StringDemo { public static void main(String[] args) { String text = "hello"; - System.out.println("�r�ꤺ�e: " + text); - System.out.println("�r�����: " + text.length()); - System.out.println("����hello? " + + System.out.println("字串內容: " + text); + System.out.println("字串長度: " + text.length()); + System.out.println("等於hello? " + text.equals("hello")); - System.out.println("�ର�j�g: " + + System.out.println("轉為大寫: " + text.toUpperCase()); - System.out.println("�ର�p�g: " + + System.out.println("轉為小寫: " + text.toLowerCase()); } } \ No newline at end of file diff --git a/example/CH6/UsePatternMatcher.java b/example/CH6/UsePatternMatcher.java index cfc0e13..c2b496b 100644 --- a/example/CH6/UsePatternMatcher.java +++ b/example/CH6/UsePatternMatcher.java @@ -3,8 +3,8 @@ public class UsePatternMatcher { public static void main(String[] args) { String phones1 = - "Justin ��������X�G0939-100391\n" + - "momor ��������X�G0939-666888\n"; + "Justin 的手機號碼:0939-100391\n" + + "momor 的手機號碼:0939-666888\n"; Pattern pattern = Pattern.compile(".*0939-\\d{6}"); Matcher matcher = pattern.matcher(phones1); @@ -14,8 +14,8 @@ public static void main(String[] args) { } String phones2 = - "caterpillar ��������X�G0952-600391\n" + - "bush ��������X�G0939-550391"; + "caterpillar 的手機號碼:0952-600391\n" + + "bush 的手機號碼:0939-550391"; matcher = pattern.matcher(phones2); diff --git a/example/CH6/UseRegularExpression.java b/example/CH6/UseRegularExpression.java index 199f3b0..74e6dda 100644 --- a/example/CH6/UseRegularExpression.java +++ b/example/CH6/UseRegularExpression.java @@ -14,30 +14,30 @@ public static void main(String args[]) String emailEL = "^[_a-z0-9-]+(.[_a-z0-9-]+)*" + "@[a-z0-9-]+(.[a-z0-9-]+)*$"; - System.out.print("��J������X: "); + System.out.print("輸入手機號碼: "); String input = reader.readLine(); if(input.matches(phoneEL)) - System.out.println("�榡���T"); + System.out.println("格式正確"); else - System.out.println("�榡���~"); + System.out.println("格式錯誤"); - System.out.print("��Jhref����: "); + System.out.print("輸入href標籤: "); input = reader.readLine(); - // ����href���� + // 驗證href標籤 if(input.matches(urlEL)) - System.out.println("�榡���T"); + System.out.println("格式正確"); else - System.out.println("�榡���~"); + System.out.println("格式錯誤"); - System.out.print("��J�q�l�l��: "); + System.out.print("輸入電子郵件: "); input = reader.readLine(); - // ���ҹq�l�l��榡 + // 驗證電子郵件格式 if(input.matches(emailEL)) - System.out.println("�榡���T"); + System.out.println("格式正確"); else - System.out.println("�榡���~"); + System.out.println("格式錯誤"); } } \ No newline at end of file diff --git a/example/CH7/AccountDemo.java b/example/CH7/AccountDemo.java index 0fb256e..73ceb4a 100644 --- a/example/CH7/AccountDemo.java +++ b/example/CH7/AccountDemo.java @@ -1,12 +1,12 @@ public class AccountDemo { public static void main(String[] args) { Account account = new Account(); - System.out.println("�b��: " + account.getAccountNumber()); - System.out.println("�l�B: " + account.getBalance()); + System.out.println("帳戶: " + account.getAccountNumber()); + System.out.println("餘額: " + account.getBalance()); account = new Account("123-4567", 100.0); account.deposit(1000.0); - System.out.println("�b��: " + account.getAccountNumber()); - System.out.println("�l�B: " + account.getBalance()); + System.out.println("帳戶: " + account.getAccountNumber()); + System.out.println("餘額: " + account.getBalance()); } } diff --git a/example/CH7/GcTest.java b/example/CH7/GcTest.java index 58a8656..c880c1e 100644 --- a/example/CH7/GcTest.java +++ b/example/CH7/GcTest.java @@ -3,11 +3,11 @@ public class GcTest { public GcTest(String name) { this.name = name; - System.out.println(name + "�إ�"); + System.out.println(name + "建立"); } - // ����^���e���� + // 物件回收前執行 protected void finalize() { - System.out.println(name + "�Q�^��"); + System.out.println(name + "被回收"); } } \ No newline at end of file diff --git a/example/CH7/MathTool.java b/example/CH7/MathTool.java index 0ea3695..4dee91a 100644 --- a/example/CH7/MathTool.java +++ b/example/CH7/MathTool.java @@ -1,5 +1,5 @@ public class MathTool { - public static int sum(int... nums) { // �ϥ�...�ŧi�Ѽ� + public static int sum(int... nums) { // 使用...宣告參數 int sum = 0; for(int num : nums) { sum += num; diff --git a/example/CH7/MethodMember.java b/example/CH7/MethodMember.java index cf53f44..54dffbb 100644 --- a/example/CH7/MethodMember.java +++ b/example/CH7/MethodMember.java @@ -2,10 +2,10 @@ public class MethodMember { public static void main(String[] args) { MethodDemo methodDemo = new MethodDemo(); - methodDemo.scopeDemo(); // ��data field���|���v�T + methodDemo.scopeDemo(); // 對data field不會有影響 System.out.println(methodDemo.getData()); - methodDemo.setData(100); // ��data field���|���v�T + methodDemo.setData(100); // 對data field不會有影響 System.out.println(methodDemo.getData()); } } @@ -22,8 +22,8 @@ public int getData() { } public void setData(int data) { - data = data; // �o�˼g�O�S�Ϊ� - // �g�U���o�Ӥ~���� + data = data; // 這樣寫是沒用的 + // 寫下面這個才有用 // this.data = data; } } diff --git a/example/CH7/OverloadTest.java b/example/CH7/OverloadTest.java index b072831..69c25b4 100644 --- a/example/CH7/OverloadTest.java +++ b/example/CH7/OverloadTest.java @@ -4,10 +4,10 @@ public static void main(String[] args) { } public static void someMethod(int i) { - System.out.println("int �����Q�I�s"); + System.out.println("int 版本被呼叫"); } public static void someMethod(Integer integer) { - System.out.println("Integer �����Q�I�s"); + System.out.println("Integer 版本被呼叫"); } } \ No newline at end of file diff --git a/example/CH7/SafeArray.java b/example/CH7/SafeArray.java index bea0cc9..86d2e9d 100644 --- a/example/CH7/SafeArray.java +++ b/example/CH7/SafeArray.java @@ -2,7 +2,7 @@ public class SafeArray { private int[] arr; public SafeArray() { - this(10); // �w�] 10 �Ӥ��� + this(10); // 預設 10 個元素 } public SafeArray(int length) { @@ -17,7 +17,7 @@ public void showElement() { public int getElement(int i) { if(i >= arr.length || i < 0) { - System.err.println("���޿��~"); + System.err.println("索引錯誤"); return 0; } @@ -30,7 +30,7 @@ public int getLength() { public void setElement(int i, int data) { if(i >= arr.length || i < 0) { - System.err.println("���޿��~"); + System.err.println("索引錯誤"); return; } diff --git a/example/CH7/SafeArrayDemo.java b/example/CH7/SafeArrayDemo.java index 109b38a..849d495 100644 --- a/example/CH7/SafeArrayDemo.java +++ b/example/CH7/SafeArrayDemo.java @@ -1,8 +1,8 @@ public class SafeArrayDemo { public static void main(String[] args) { - // �w�]10�Ӥ��� + // 預設10個元素 SafeArray arr1 = new SafeArray(); - // ���w�t�m 5 �Ӥ��� + // 指定配置 5 個元素 SafeArray arr2 = new SafeArray(5); for(int i = 0; i < arr1.getLength(); i++) diff --git a/example/CH7/SomeClass.java b/example/CH7/SomeClass.java index 9a74d4f..821340d 100644 --- a/example/CH7/SomeClass.java +++ b/example/CH7/SomeClass.java @@ -1,5 +1,5 @@ public class SomeClass { static { - System.out.println("���O�Q���J"); + System.out.println("類別被載入"); } } \ No newline at end of file diff --git a/example/CH7/StaticDemo.java b/example/CH7/StaticDemo.java index 161c396..07472d1 100644 --- a/example/CH7/StaticDemo.java +++ b/example/CH7/StaticDemo.java @@ -1,6 +1,6 @@ public class StaticDemo { public static void sayHello() { - System.out.println("���o�I"); + System.out.println("哈囉!"); } public static void main(String[] args) { diff --git a/example/CH7/UseGC.java b/example/CH7/UseGC.java index d18e772..d01edb1 100644 --- a/example/CH7/UseGC.java +++ b/example/CH7/UseGC.java @@ -1,19 +1,19 @@ public class UseGC { public static void main(String[] args) { - System.out.println("�Ы�Ctrl + C�פ�{��........"); + System.out.println("請按Ctrl + C終止程式........"); GcTest obj1 = new GcTest("object1"); GcTest obj2 = new GcTest("object2"); GcTest obj3 = new GcTest("object3"); - // �O�W�٤��ѦҦܪ��� + // 令名稱不參考至物件 obj1 = null; obj2 = null; obj3 = null; - // ��ij�^������ + // 建議回收物件 System.gc(); - while(true); // ���_����{�� + while(true); // 不斷執行程式 } } \ No newline at end of file diff --git a/example/CH7/UseRecursion.java b/example/CH7/UseRecursion.java index 6af64a3..ab4d646 100644 --- a/example/CH7/UseRecursion.java +++ b/example/CH7/UseRecursion.java @@ -4,7 +4,7 @@ public class UseRecursion { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); - System.out.println("��J���:"); + System.out.println("輸入兩數:"); System.out.print("m = "); int m = scanner.nextInt(); diff --git a/example/CH8/AbstractGuessGame.java b/example/CH8/AbstractGuessGame.java index 643e1b5..ec7dc99 100644 --- a/example/CH8/AbstractGuessGame.java +++ b/example/CH8/AbstractGuessGame.java @@ -6,19 +6,19 @@ public void setNumber(int number) { } public void start() { - showMessage("�w��"); + showMessage("歡迎"); int guess = 0; do { guess = getUserInput(); if(guess > number) { - showMessage("��J���Ʀr���j"); + showMessage("輸入的數字較大"); } else if(guess < number) { - showMessage("��J���Ʀr���p"); + showMessage("輸入的數字較小"); } else { - showMessage("�q���F"); + showMessage("猜中了"); } } while(guess != number); } diff --git a/example/CH8/Bird.java b/example/CH8/Bird.java index 7fda155..c4be20f 100644 --- a/example/CH8/Bird.java +++ b/example/CH8/Bird.java @@ -9,7 +9,7 @@ public Bird(String name) { } public void walk() { - System.out.println("����"); + System.out.println("走路"); } public String getName() { diff --git a/example/CH8/Chicken.java b/example/CH8/Chicken.java index 9a9ddd9..23198bb 100644 --- a/example/CH8/Chicken.java +++ b/example/CH8/Chicken.java @@ -1,17 +1,17 @@ -public class Chicken extends Bird { // �X�RBird���O - private String crest; // �s�W�p�������A���a�y�z +public class Chicken extends Bird { // 擴充Bird類別 + private String crest; // 新增私有成員,雞冠描述 public Chicken() { super(); } - // �w�q�غc��k + // 定義建構方法 public Chicken(String name, String crest) { super(name); this.crest = crest; } - // �s�W��k + // 新增方法 public void setCrest(String crest) { this.crest = crest; } @@ -21,6 +21,6 @@ public String getCrest() { } public void wu() { - System.out.println("�B�B�s�K"); + System.out.println("咕咕叫…"); } } \ No newline at end of file diff --git a/example/CH8/CloneDemo.java b/example/CH8/CloneDemo.java index a000c2a..af2e65c 100644 --- a/example/CH8/CloneDemo.java +++ b/example/CH8/CloneDemo.java @@ -8,18 +8,18 @@ public static void main(String[] args) Table clonedTable = (Table) table.clone(); Point clonedCenter = clonedTable.getCenter(); - System.out.printf("��Ӫ�Table���ߡG(%d, %d)\n", + System.out.printf("原來的Table中心:(%d, %d)\n", originalCenter.getX(), originalCenter.getY()); - System.out.printf("�ƻs��Table���ߡG(%d, %d)\n", + System.out.printf("複製的Table中心:(%d, %d)\n", clonedCenter.getX(), clonedCenter.getY()); clonedCenter.setX(10); clonedCenter.setY(10); - // ���ܽƻs�~�����e�A���Ӫ����󤣷|���v�T - System.out.printf("��Ӫ�Table���ߡG(%d, %d)\n", + // 改變複製品的內容,對原來的物件不會有影響 + System.out.printf("原來的Table中心:(%d, %d)\n", originalCenter.getX(), originalCenter.getY()); - System.out.printf("�ƻs��Table���ߡG(%d, %d)\n", + System.out.printf("複製的Table中心:(%d, %d)\n", clonedCenter.getX(), clonedCenter.getY()); } } \ No newline at end of file diff --git a/example/CH8/ConcreteCircle.java b/example/CH8/ConcreteCircle.java index b78cab6..23697e3 100644 --- a/example/CH8/ConcreteCircle.java +++ b/example/CH8/ConcreteCircle.java @@ -6,6 +6,6 @@ public ConcreteCircle(double radius) { } public void render() { - System.out.printf("�e�@�ӥb�| %f ����߶�\n", getRadius()); + System.out.printf("畫一個半徑 %f 的實心圓\n", getRadius()); } } \ No newline at end of file diff --git a/example/CH8/Cubic.java b/example/CH8/Cubic.java index 553f328..f53ecc8 100644 --- a/example/CH8/Cubic.java +++ b/example/CH8/Cubic.java @@ -20,7 +20,7 @@ public Cubic(int x, int y, int z, public int getLength() { return length; } public int getVolumn() { - // �i�H�����ϥΤ����O����width�Bheight���� + // 可以直接使用父類別中的width、height成員 return length*width*height; } } \ No newline at end of file diff --git a/example/CH8/ExtendDemo.java b/example/CH8/ExtendDemo.java index 6cfcaf1..0ac914b 100644 --- a/example/CH8/ExtendDemo.java +++ b/example/CH8/ExtendDemo.java @@ -1,13 +1,13 @@ public class ExtendDemo { public static void main(String[] args) { - Chicken chicken1 = new Chicken("�p�J", "����p���a"); + Chicken chicken1 = new Chicken("小克", "紅色小雞冠"); Chicken chicken2 = new Chicken(); - System.out.printf("�p��1 - �W�� %s, ���a�O %s�C \n", + System.out.printf("小雞1 - 名稱 %s, 雞冠是 %s。 \n", chicken1.getName(), chicken1.getCrest()); chicken1.wu(); - System.out.printf("�p��2 - �W�� %s, ���a�O %s�C \n", + System.out.printf("小雞2 - 名稱 %s, 雞冠是 %s。 \n", chicken2.getName(), chicken2.getCrest()); chicken2.wu(); } diff --git a/example/CH8/Foo1.java b/example/CH8/Foo1.java index 6b62965..76b60d8 100644 --- a/example/CH8/Foo1.java +++ b/example/CH8/Foo1.java @@ -6,6 +6,6 @@ public Foo1(String name) { } public void showName() { - System.out.println("foo1 �W�١G" + name); + System.out.println("foo1 名稱:" + name); } } \ No newline at end of file diff --git a/example/CH8/Foo2.java b/example/CH8/Foo2.java index 1d39a95..8b3ee75 100644 --- a/example/CH8/Foo2.java +++ b/example/CH8/Foo2.java @@ -6,6 +6,6 @@ public Foo2(String name) { } public void showName() { - System.out.println("foo2 �W�١G" + name); + System.out.println("foo2 名稱:" + name); } } \ No newline at end of file diff --git a/example/CH8/HelloRequest.java b/example/CH8/HelloRequest.java index 36cb901..2915010 100644 --- a/example/CH8/HelloRequest.java +++ b/example/CH8/HelloRequest.java @@ -6,6 +6,6 @@ public HelloRequest(String name) { } public void execute() { - System.out.printf("���o %s�I%n", name); + System.out.printf("哈囉 %s!%n", name); } } \ No newline at end of file diff --git a/example/CH8/HollowCircle.java b/example/CH8/HollowCircle.java index c8cd174..579bc9a 100644 --- a/example/CH8/HollowCircle.java +++ b/example/CH8/HollowCircle.java @@ -6,6 +6,6 @@ public HollowCircle(double radius) { } public void render() { - System.out.printf("�e�@�ӥb�| %f ���Ť߶�\n", getRadius()); + System.out.printf("畫一個半徑 %f 的空心圓\n", getRadius()); } } \ No newline at end of file diff --git a/example/CH8/Point.java b/example/CH8/Point.java index 961c9d8..3e74f52 100644 --- a/example/CH8/Point.java +++ b/example/CH8/Point.java @@ -15,7 +15,7 @@ public Point(int x, int y) { public int getY() { return y; } public Object clone() throws CloneNotSupportedException { - // �I�s�����O��clone()�Ӷi��ƻs + // 呼叫父類別的clone()來進行複製 return super.clone(); } } \ No newline at end of file diff --git a/example/CH8/Rectangle.java b/example/CH8/Rectangle.java index 73752e0..5677aed 100644 --- a/example/CH8/Rectangle.java +++ b/example/CH8/Rectangle.java @@ -1,5 +1,5 @@ public class Rectangle { - // ���O�@��member + // 受保護的member protected int x; protected int y; protected int width; diff --git a/example/CH8/RequestDemo.java b/example/CH8/RequestDemo.java index 2c614ff..5fca808 100644 --- a/example/CH8/RequestDemo.java +++ b/example/CH8/RequestDemo.java @@ -5,10 +5,10 @@ public static void main(String[] args) { switch (n) { case 0: doRequest( - new HelloRequest("�}����")); + new HelloRequest("良葛格")); break; case 1: - doRequest(new WelcomeRequest("Wiki ����")); + doRequest(new WelcomeRequest("Wiki 網站")); } } } diff --git a/example/CH8/SimpleCollection.java b/example/CH8/SimpleCollection.java index 0aa25a2..fe7bd7e 100644 --- a/example/CH8/SimpleCollection.java +++ b/example/CH8/SimpleCollection.java @@ -3,7 +3,7 @@ public class SimpleCollection { private int index = 0; public SimpleCollection() { - // �w�]10�Ӫ���Ŷ� + // 預設10個物件空間 objArr = new Object[10]; } diff --git a/example/CH8/SimpleCollectionDemo.java b/example/CH8/SimpleCollectionDemo.java index 0aa662e..def8c3e 100644 --- a/example/CH8/SimpleCollectionDemo.java +++ b/example/CH8/SimpleCollectionDemo.java @@ -3,8 +3,8 @@ public static void main(String[] args) { SimpleCollection simpleCollection = new SimpleCollection(); - simpleCollection.add(new Foo1("�@�� Foo1")); - simpleCollection.add(new Foo2("�@�� Foo2")); + simpleCollection.add(new Foo1("一號 Foo1")); + simpleCollection.add(new Foo2("一號 Foo2")); Foo1 f1 = (Foo1) simpleCollection.get(0); f1.showName(); diff --git a/example/CH8/Table.java b/example/CH8/Table.java index 917a522..1a36f5b 100644 --- a/example/CH8/Table.java +++ b/example/CH8/Table.java @@ -10,11 +10,11 @@ public Point getCenter() { public Object clone () throws CloneNotSupportedException { - // �I�s������clone()�ӽƻs + // 呼叫父類的clone()來複製 Table table = (Table) super.clone(); if(this.center != null) { - // �ƻsPoint��������Ʀ��� + // 複製Point類型的資料成員 table.center = (Point) center.clone(); } diff --git a/example/CH8/TextModeGame.java b/example/CH8/TextModeGame.java index dc489fe..d39ecbc 100644 --- a/example/CH8/TextModeGame.java +++ b/example/CH8/TextModeGame.java @@ -18,7 +18,7 @@ protected void showMessage(String message) { } protected int getUserInput() { - System.out.print("\n��J�Ʀr�G"); + System.out.print("\n輸入數字:"); return scanner.nextInt(); } } \ No newline at end of file diff --git a/example/CH8/WelcomeRequest.java b/example/CH8/WelcomeRequest.java index 71dd77a..b6e75e7 100644 --- a/example/CH8/WelcomeRequest.java +++ b/example/CH8/WelcomeRequest.java @@ -6,6 +6,6 @@ public WelcomeRequest(String place) { } public void execute() { - System.out.printf("�w��Ө� %s�I%n", place); + System.out.printf("歡迎來到 %s!%n", place); } } \ No newline at end of file diff --git a/example/CH9/AnonymousClassDemo.java b/example/CH9/AnonymousClassDemo.java index ff4b82f..54fb899 100644 --- a/example/CH9/AnonymousClassDemo.java +++ b/example/CH9/AnonymousClassDemo.java @@ -2,8 +2,8 @@ public class AnonymousClassDemo { public static void main(String[] args) { Object obj = new Object() { - public String toString() { // ���s�w�qtoString() - return "�ΦW���O����"; + public String toString() { // 重新定義toString() + return "匿名類別物件"; } }; diff --git a/example/CH9/PointDemo.java b/example/CH9/PointDemo.java index bcd6716..5d895b4 100644 --- a/example/CH9/PointDemo.java +++ b/example/CH9/PointDemo.java @@ -1,5 +1,5 @@ public class PointDemo { - // �������O + // 內部類別 private class Point { private int x, y;