Schildt - The Art of Java (McGraw, 2003).pdf

(3284 KB) Pobierz
19074858 UNPDF
19074858.005.png
19074858.006.png
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
19074858.007.png 19074858.008.png
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.
19074858.001.png 19074858.002.png
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
19074858.003.png 19074858.004.png
Zgłoś jeśli naruszono regulamin