1. Trang chủ
  2. » Công Nghệ Thông Tin

Sybex ground up java nov 2003 ISBN 0782141900

761 149 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 761
Dung lượng 4,63 MB

Nội dung

Ground-Up Java ISBN:0782141900 by Philip Heller Sybex © 2003 (488 pages) In addition to learning the core Java language, you will also acquire a broad understanding of vital programming concepts, including variables, control, memory, indirection, compilation, and calling Table of Contents Ground-Up Java Introduction An Introduction to Chapter 1 - Computers That Will Actually Help You in Life Chapter 2 - Data Chapter 3 - Operations Chapter 4 - Methods Chapter 5 - Conditionals and Loops Chapter 6 - Arrays Chapter 7 - Introduction to Objects Chapter 8 - Inheritance Chapter 9 - Packages and Access Chapter 10 - Interfaces Chapter 11 - Exceptions Chapter 12 - The Core Java Packages and Classes Chapter 13 - File Input and Output Chapter 14 - Painting Chapter 15 - Components Chapter 16 - Events Chapter 17 - Final Project Downloading and Appendix A Installing Java Appendix B - Solutions to the Exercises Glossary Index List of Figures List of Tables Back Cover This is the first effective Java book for true beginners Sure, books before now focused on basic concepts and key techniques, and some even provided working examples on CD Still, they lacked the power to transform someone with no programming experience into someone who sees, who really “gets it.” Working with Ground-Up Java, you will definitely get it This is due to the clarity of Phil Heller’s explanations, and the smoothly flowing organization of his instruction He’s one of the best Java trainers around But what’s really revolutionary are his more than 30 animated illustrations Each of these small programs, visual and interactive in nature, vividly demonstrates how its source code works You can modify it in different ways, distinctly altering the behavior of the program As you experiment with these tools—and you can play with them for hours—you’ll gain both the skills and the fundamental understanding needed to complete each chapter’s exercises, which steadily increase in sophistication No other beginning Java book can take you so far, so quickly, and none will be half as much fun About the Author Philip Heller is a consultant, author, educator, and novelist He is the lead author for Sybex’s best selling Java Certification Study Guide and Java Exam Notes as well as a leading educator for Java University and a well-known speaker on Java topics Phil helped create the Java programmer and developer exams for Sun and is their leading certification trainer Phil is currently writing the second volume in the Grandfather Dragon series Ground-Up Java Philip Heller Associate Publisher: Joel Fugazzotto Acquisitions Editor: Denise Santoro Lincoln, Tom Cirtin Developmental Editor: Tom Cirtin Production Editor: Dennis Fitzgerald Technical Editor: Marcus Cuda Copyeditor: Sean Medlock Compositor: Maureen Forys, Happenstance Type-O-Rama Graphic Illustrator: Jeffrey Wilson, Happenstance Type-O-Rama CD Coordinator: Dan Mummert CD Technician: Kevin Ly Proofreaders: Emily Husan, Laurie O’Connell, Nancy Riddiough Indexer: Ted Laux Cover Designer/Illustrator: Richard Miller, Calyx Deisgns Copyright © 2004 SYBEX Inc., 1151 Marina Village Parkway, Alameda, CA 94501 World rights reserved No part of this publication may be stored in a retrieval system, transmitted, or reproduced in any way, including but not limited to photocopy, photograph, magnetic, or other record, without the prior agreement and written permission of the publisher Library of Congress Card Number: 2003110719 ISBN: 0-7821-4190-0 SYBEX and the SYBEX logo are either registered trademarks or trademarks of SYBEX Inc in the United States and/or other countries Screen reproductions produced with FullShot 99 FullShot 99 © 1991– 1999 Inbit Incorporated All rights reserved FullShot is a trademark of Inbit Incorporated The CD interface was created using Macromedia Director, COPYRIGHT 1994, 1997-1999 Macromedia Inc For more information on Macromedia and Macromedia Director, visit http://www.macromedia.com TRADEMARKS: SYBEX has attempted throughout this book to distinguish proprietary trademarks from descriptive terms by following the capitalization style used by the manufacturer The author and publisher have made their best efforts to prepare this book, and the content is based upon final release software whenever possible Portions of the manuscript may be based upon pre-release versions supplied by software manufacturer(s) The author and the publisher make no representation or warranties of any kind with regard to the completeness or accuracy of the contents herein and accept no liability of any kind including but not limited to performance, merchantability, fitness for any particular purpose, or any losses or damages of any kind caused or alleged to be caused directly or indirectly from this book Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 To Laura, on whose violin Are played the songs of spheres and heroes, Above this world’s mortal din, Above the plane of ones and zeroes Acknowledgements First and foremost gratitude to Denise Santoro Lincoln, Tom Cirtin, and Steve Cavin Thanks to Michelle, Ricardo, and everyone at PB&G Productions for keeping me out dancing when I should have been writing Thanks always to Simon Roberts, Suzanne Blackstock, and Kathy Collina And thanks to all the aces at Sybex: Dennis Fitzgerald, Sean Medlock, Kevin Ly, Dan Mummert, and Maureen Forys and Jeff Wilson at Happenstance Type-O-Rama Introduction Overview This book is unique There’s nothing like it It is the first of its kind It’s important that you understand why, so please read on For a long time I thought it was impossible to write an introductory Java programming book that could be understood by people with no programming experience It would be like a fish writing about water No one has better knowledge of the subject matter, but it takes more than that to introduce a topic to a newcomer Fish are intimately accustomed to water, and they can’t relate to us land mammals, who need to have everything explained and broken down A fish might say, “Wiggle your tail fin to swim forward, and don’t forget to use your gills.” That would be glaringly obvious to another fish, but useless to you and me It’s hard for a fish to imagine what life would be like without tail fins or gills A book about water, even if the wisest fish in the ocean wrote it, would be full of accurate, but useless, information The same is true about Java Programming is a craft, like playing a musical instrument or glassblowing And like any other craft, it has its conventions, jargon, and techniques For practitioners of the craft, those conventions, jargon, and techniques become deeply ingrained habits, household language, and the events of everyday life It’s very difficult to write about one’s own “habitat.” In the 1970’s, a language called C became popular In the 1980’s, C was modified to support object-oriented programming The modified language was called C++ This is an example of craft jargon In C, the symbol “++” means, very broadly speaking, “a bit more.” So C++ means “C and a bit more,” and the meaning is clear to any C programmer The 1990’s saw another evolution C++ is a highly effective language, but it can also be difficult Moreover, it had no innate support for recently invented technologies, such as high-resolution multi-color displays, databases, or the World Wide Web The new evolution was called Java The name isn’t a play on words and it isn’t an abbreviation for anything Java abandoned the parts of C++ that had proved to be more trouble than they were worth, and it added support for modern technologies Sometimes people called it “C++ ++” There’s another symbol, “—”, that roughly means “a bit less.” So “C++ ++” means “C++ and a bit less and then a bit more.” Java caught on like a midsummer bonfire A huge portion of the C and C++ programming population switched at once to Java and never looked back Why were so many programmers able to make the switch so easily? I was one of them I had been earning a living programming in C++ I took a year off to write a novel about some dragons I ran out of money before I finished the novel Luckily, it was a month after Java was introduced Within weeks I considered myself a competent Java programmer, and within months I was teaching it and writing about it The credit goes not to me but to the designers of Java If you know C and C++, Java is easy It’s like learning Portuguese if you already speak Spanish and Italian Like everyone else who learned Java at that time, I had years of experience with the concepts, techniques, and jargon that was needed But what about people who don’t have any programming experience? When I was learning Java, there were two books on the subject Today there are thousands (I’m responsible for a few of them.) Not one of them, except the one that you’re holding right now, does a good job of presenting programming concepts from the ground up The others are accurate for the most part, but they aren’t helpful So I had to ask myself: can I introduce Java from the ground up, concept by concept? Eventually I realized that I could only do it if I could use something more than words and pictures Which brings me to why this book is unique It is unique because … The Illustrations are Alive! I realized that what I really wanted was a magic blackboard Think of a computer as a huge set of boxes, each box containing a number The numbers represent text or colors or data, or whatever else can be modeled by a program The numbers change over time in complicated ways Describing the life cycle of a program is almost impossible if you can only use words and pictures I wanted to create pictures that would change over time And I wanted something beyond animated cartoons that would be the same each time you watched them I wanted living illustrations that would respond to your curiosity I wanted to give you the power to ask “what if …” questions of the illustrations I wanted something that can only be done on a computer The CD-ROM that comes with this book has more than 30 animated illustrations These are programs that you run on your computer The book gives you complete instructions on how to use them The illustration on the next page is an example This is a screenshot of NestedLoopLab, which appears in Chapter 5, “Conditionals and Loops.” The text in the upper-central part of the screen (“int color = 5” and so on) is Java code The swirly image at the bottom is the result of running the code The various controls let you vary the code, experimenting with different values until you get a feel for what the program is doing Chapter 14: Painting Figure 14.1: A frame with boring contents Figure 14.2: Color Lab Figure 14.3: Color Lab with a predefined color Figure 14.4: Pixel coordinates Figure 14.5: A black line on a white background Figure 14.6: A rectangle Figure 14.7: Ovals and bounding boxes Figure 14.8: Three ovals Figure 14.9: Filled rectangle and ovals Figure 14.10: Original CenteredOval Figure 14.11: Resized CenteredOval Figure 14.12: The baseline Figure 14.13: Text and baseline in a frame Figure 14.14: Text in a frame Figure 14.15: Font Lab Figure 14.16: Font Lab with an exotic font Figure 14.17: Initial Frame Lab display Figure 14.18: Frame Lab with custom configuration Figure 14.19: The result of Figure 14.18 Chapter 15: Components Figure 15.1: A component sampler Figure 15.2: A button in a frame Figure 15.3: A fancy button Figure 15.4: A simple checkbox Figure 15.5: A checked checkbox Figure 15.6: Three checkboxes and a button Figure 15.7: Checkboxes as radio buttons Figure 15.8: Multiple checkbox groups Figure 15.9: A choice Figure 15.10: An expanded choice Figure 15.11: Two choices Figure 15.12: Choices with labels Figure 15.13: A menu in a menu bar Figure 15.14: A menu with a separator Figure 15.15: Hierarchical menus Figure 15.16: Two text fields Figure 15.17: A text area Figure 15.18: Multiple checkbox groups Figure 15.19: A text area with scroll bars Figure 15.20: A pair of disappointing scrollbars Figure 15.21: Flow layout manager Figure 15.22: Wider Figure 15.23: Narrower Figure 15.24: Left-aligned Figure 15.25: Flow Lab Figure 15.26: Scrollbar at North Figure 15.27: North and South occupied Figure 15.28: North, East, and West occupied Figure 15.29: North, East, West, and Center occupied Figure 15.30: A panel in a frame Figure 15.31: Layout lab Figure 15.32: Layout lab's frame editing dialog Figure 15.33: Layout Lab with an added panel Figure 15.34: A button in a panel in a frame Figure 15.35: Layout Lab makes it so Figure 15.36: No layout manager Chapter 16: Events Figure 16.1: A GUI waiting for events Figure 16.2: A button that sends events Figure 16.3: Simple Event Lab: initial screen Figure 16.4: Simple Event Lab with simulated buttons Figure 16.5: Simple Event Lab with a listener class Figure 16.6: Simple Event Lab with a listener object Figure 16.7: Simple Event Lab continued Figure 16.8: One listener object for many buttons Figure 16.9: Simple Nim GUI Figure 16.10: Nim Lab Figure 16.11: Nim, with output to a text area Figure 16.12: Nim with graphical output Figure 16.13: Nim with graphical output, game in progress Figure 16.14: Enabled and disabled buttons Figure 16.15: Nim with disabled buttons Figure 16.16: Check box and choice Figure 16.17: Receiving events from a check box and a choice Figure 16.18: Event Lab Figure 16.19: Scrollbar and text field Chapter 17: Final Project Figure 17.1: Final Project Figure 17.2: Final Project, with lines Figure 17.3: Menu schematic Figure 17.4: Teting the menu's look Figure 17.5: Window, Frame, and FileDialog Figure 17.6: File dialog box configured for opening Figure 17.7: Too many radio buttons Figure 17.8: Testing color selection Figure 17.9: GUI layout Figure 17.10: Positioning text Appendix A: Downloading and Installing Java Figure A.1: Windows SDK file layout List of Tables Chapter 1: An Introduction to Computers That Will Actually Help You in Life Table 1.1: Opcodes Chapter 2: Data Table 2.1: Java's Integer Data Types Table 2.2: Java's Floating-Point Data Types Table 2.3: Java's Primitive Data Types Table 2.3: Naming Consistency Chapter 3: Operations Table 3.1: Binary Bitwise Operations Table 3.2: Comparison Operators Table 3.3: Compound Assignment Table 3.4: Ranges of Numeric Types Table 3.5: Binary Arithmetic Result Types Table 3.6: Operator Precedence Chapter 8: Inheritance Table 8.1: References, Variables, and Methods Chapter 9: Packages and Access Table 9.1: Legal Access Modes for Overriding Methods Chapter 12: The Core Java Packages and Classes Table 12.1: String Concatenation Conversion Rules Table 12.2: Wrapper Class Names Chapter 13: File Input and Output Table 13.1: Byte -1 vs Int -1 Chapter 14: Painting Table 14.1: Combining Additive Primary Colors ... He is the lead author for Sybex s best selling Java Certification Study Guide and Java Exam Notes as well as a leading educator for Java University and a well-known speaker on Java topics Phil helped create the Java programmer and developer exams for Sun... publisher Library of Congress Card Number: 20031 10719 ISBN: 0-7821-4190-0 SYBEX and the SYBEX logo are either registered trademarks or trademarks of SYBEX Inc in the United States and/or other countries... presenting programming concepts from the ground up The others are accurate for the most part, but they aren’t helpful So I had to ask myself: can I introduce Java from the ground up, concept by concept? Eventually I realized that I could only do it if I could use

Ngày đăng: 26/03/2019, 17:06