The Art of Java 2003, ebook, programowanie, nowy katalog

[ Pobierz całość w formacie PDF ]
The Art of Java
Herbert Schildt, James Holmes
McGraw-Hill
/Osborne
New York Chicago San Francisco
Lisbon London Madrid Mexico City Milan
New Delhi San Juan Seoul Singapore Sydney Toronto
McGraw-Hill
/Osborne
2100 Powell Street, 10
th
Floor
Emeryville, California 94608
U.S.A.
To arrange bulk purchase discounts for sales promotions, premiums, or fund-raisers, please contact
McGraw-Hill/Osborne at the above address. For information on translations or book distributors
outside the U.S.A., please see the International Contact Information page immediately following the
index of this book.
The Art of Java
Copyright © 2003 by The McGraw-Hill Companies. All rights reserved. Printed in the United States
of America. Except as permitted under the Copyright Act of 1976, no part of this publication may be
reproduced or distributed in any form or by any means, or stored in a database or retrieval system,
without the prior written permission of publisher, with the exception that the program listings may be
entered, stored, and executed in a computer system, but they may not be reproduced for publication.
1234567890 FGR FGR 019876543
ISBN 0-07-222971-3
Publisher
Brandon A. Nordin
Vice President & Associate Publisher
Scott Rogers
Editorial Director
Wendy Rinaldi
Project Editor
Jennifer Malnick
Acquisitions Coordinator
Athena Honore
Technical Editor
James Holmes
Copy Editor
Emily Rader
Proofreader
Emily Hsuan
Indexer
Sheryl Schildt
Composition
Tara A. Davis, Lucie Ericksen
Illustrators
Kathleen Fay Edwards, Melinda Moore Lytle, Lyssa Wald
Series Designer
Roberta Steele
Cover Designer
Jeff Weeks
This book was composed with Corel VENTURAâ„¢ Publisher.
Information has been obtained by McGraw-Hill/Osborne from sources believed to be reliable. However, because of the possibility of
human or mechanical error by our sources, McGraw-Hill/Osborne, or others, McGraw-Hill/Osborne does not guarantee the accuracy,
adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained from the use
of such information.
Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ix
Chapter 1
The Genius of Java
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
Simple Types and Objects: The Right Balance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
Memory Management Through Garbage Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
A Wonderfully Simple Multithreading Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
Fully Integrated Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5
Streamlined Support for Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5
Portability and Security Through Bytecode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6
The Richness of the Java API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6
The Applet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
The Continuing Revolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8
Chapter 2
A Recursive-Descent Expression Parser
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10
Parsing Expressions: The Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11
Parsing an Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12
Dissecting an Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13
A Simple Expression Parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17
Understanding the Parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
24
Adding Variables to the Parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
25
Syntax Checking in a Recursive-Descent Parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
35
A Calculator Applet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
36
Some Things to Try . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
38
Chapter 3
Implementing Language Interpreters in Java
. . . . . . . . . . . . . . . . . . . . . . . . . .
39
What Computer Language to Interpret? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
40
An Overview of the Interpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
42
The Small BASIC Interpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
42
The Small BASIC Expression Parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
64
Small BASIC Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
64
Small BASIC Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
65
The Interpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
70
The InterpreterException Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
70
The SBasic Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
70
iii
iv
The Art of Java
The Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
72
The run( ) Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
73
The sbInterp( ) Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
74
Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
75
The PRINT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
76
The INPUT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
78
The GOTO Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
79
The IF Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
82
The FOR Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
82
The GOSUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
85
The END Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
87
Using Small BASIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
87
More Small BASIC Sample Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
88
Enhancing and Expanding the Interpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
90
Creating Your Own Computer Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
90
Chapter 4
Creating a Download Manager in Java
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
91
Understanding Internet Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
92
An Overview of the Download Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
93
The Download Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
94
The Download Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
98
The Download Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
98
The download( ) Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
98
The run( ) Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
99
The stateChanged( ) Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
102
Action and Accessor Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
103
The ProgressRenderer Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
103
The DownloadsTableModel Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
104
The addDownload( ) Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
106
The clearDownload( ) Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
107
The getColumnClass( ) Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
107
The getValueAt( ) Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
108
The update( ) Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
108
The DownloadManager Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
109
The DownloadManager Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
115
The DownloadManager Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
115
The verifyUrl( ) Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
116
The tableSelectionChanged( ) Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
117
The updateButtons( ) Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
117
Handling Action Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
119
Compiling and Running the Download Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
119
Enhancing the Download Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
120
[ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • ministranci-w.keep.pl