logo资料库

Java For Dummies 5TH Edition.pdf

第1页 / 共435页
第2页 / 共435页
第3页 / 共435页
第4页 / 共435页
第5页 / 共435页
第6页 / 共435页
第7页 / 共435页
第8页 / 共435页
资料共435页,剩余部分请下载后查看
Java For Dummies, 5th Edition
About the Author
Dedication
Author’s Acknowledgments
Table of Contents
Introduction
How to Use This Book
Conventions Used in This Book
What You Don’t Have to Read
Foolish Assumptions
How This Book Is Organized
Icons Used in This Book
Where to Go from Here
Part I: Getting Started
Chapter 1: All about Java
What You Can Do with Java
Why You Should Use Java
Getting Perspective: Where Java Fits In
Object-Oriented Programming (OOP)
What’s Next?
Chapter 2: All about Software
Quick-Start Instructions
What You Install on Your Computer
Chapter 3: Using the Basic Building Blocks
Speaking the Java Language
Checking Out Java Code for the First Time
Understanding a Simple Java Program
And Now, a Few Comments
Part II: Writing Your Own Java Programs
Chapter 4: Making the Most of Variables and Their Values
Varying a Variable
Assignment Statements
Understanding the Types of Values That Variables May Have
Displaying Text
Numbers without Decimal Points
Combining Declarations and Initializing Variables
The Atoms: Java’s Primitive Types
The Molecules and Compounds: Reference Types
An Import Declaration
Creating New Values by Applying Operators
Chapter 5: Controlling Program Flow with Decision-Making Statements
Making Decisions (Java if Statements)
Forming Conditions with Comparisons and Logical Operators
Building a Nest
Choosing among Many Alternatives (Java switch Statements)
Chapter 6: Controlling Program Flow with Loops
Repeating Instructions Over and Over Again (Java while Statements)
Repeating a Certain Number of Times (Java for Statements)
Repeating Until You Get What You Want (Java do Statements)
Part III: Working with the Big Picture: Object-Oriented Programming
Chapter 7: Thinking in Terms of Classes and Objects
Defining a Class (What It Means to Be an Account)
Defining a Method within a Class (Displaying an Account)
Sending Values to and from Methods (Calculating Interest)
Making Numbers Look Good
Hiding Details with Accessor Methods (Why You Shouldn’t Micromanage a Bank Teller)
Chapter 8: Saving Time and Money: Reusing Existing Code
Defining a Class (What It Means to Be an Employee)
Working with Disk Files (A Brief Detour)
Defining Subclasses (What It Means to Be a Full-Time or Part-Time Employee)
Using Subclasses
Overriding Existing Methods (Changing the Payments for Some of Your Employees)
Chapter 9: Constructing New Objects
Defining Constructors (What It Means to Be a Temperature)
More Subclasses (Doing Something about the Weather)
A Constructor That Does More
Part IV: Savvy Java Techniques
Chapter 10: Putting Variables and Methods Where They Belong
Defining a Class (What It Means to Be a Baseball Player)
Making Static (Finding the Team Average)
Experiments with Variables
Passing Parameters
Chapter 11: Using Arrays and Collections to Juggle Values
Getting Your Ducks All in a Row
Arrays of Objects
Command Line Arguments
Using Java Collections
Chapter 12: Looking Good When Things Take Unexpected Turns
Handling Exceptions
Handle an Exception or Pass the Buck
Finishing the Job with a finally Clause
Close Those Files!
Chapter 13: Sharing Names among the Parts of a Java Program
Access Modifiers
Classes, Access, and Multipart Programs
Sneaking Away from the Original Code
Protected Access
Access Modifiers for Java Classes
Chapter 14: Responding to Keystrokes and Mouse Clicks
Go On . . . Click That Button
Responding to Things Other Than Button Clicks
Creating Inner Classes
Chapter 15: Writing Java Applets
Applets 101
Making Things Move
Responding to Events in an Applet
Chapter 16: Using Java Database Connectivity
JDBC and Java DB
Creating Data
Retrieving Data
Part V: The Part of Tens
Chapter 17: Ten Ways to Avoid Mistakes
Putting Capital Letters Where They Belong
Breaking Out of a switch Statement
Comparing Values with a Double Equal Sign
Adding Components to a GUI
Adding Listeners to Handle Events
Defining the Required Constructors
Fixing Non-Static References
Staying within Bounds in an Array
Anticipating Null Pointers
Helping Java Find Its Files
Chapter 18: Ten Websites for Java
This Book’s Website
The Horse’s Mouth
Finding News, Reviews, and Sample Code
Looking for Java Jobs
Everyone’s Favorite Sites
Index
Jumpin’ Java! The bestselling Java beginner’s book is now fully updated for Java 7! Java, the object-oriented programming language that works on almost any computer, is what powers many of those cool multimedia applications. Thousands have learned Java programming from previous editions of this book — now it’s your turn! Whether you’re new to programming or already know a little Visual Basic or C++, you’ll be doing Java in a jiffy. • The Java scoop — get an overview of Java, the enhancements in Java 7, and the software tools you need • Building blocks — learn to work with Java classes and methods and add comments • Get loopy — understand the value of variables and learn to control program flow with loops or decision-making statements • Class it up — explore classes and objects, constructors, and subclasses, and see how to reuse your code • A click ahead — experiment with variables and methods, use arrays and collections to juggle values, and create programs that respond to mouse clicks Programming Languages/Java Open the book and find: • Definitions of the many terms you’ll encounter • The grammar of Java • How to save time by reusing code • All about if, for, switch, and while statements • An overview of object-oriented programming • Hints about handling exceptions • How to write Java applets • Ten ways to avoid mistakes 5th Edition J a v a ® 5th Edition Making Everything Easier!™ Java ® Visit the companion website at www.dummies.com/go/ javafordummies5e for lots of code samples that you can use in your Java programs Go to Dummies.com® for videos, step-by-step examples, how-to articles, or to shop! Barry Burd, PhD, is a professor of mathematics and computer science at Drew University. He frequently contributes to various online technology resources, including JavaBoutique.com, and is the author of Ruby On Rails For Dummies and the previous edition of this book. $29.99 US / $35.99 CN / £21.99 UK ISBN 978-0-470-37173-2 Learn to: • Combine several smaller programs to create a bigger program • Work with new libraries, closure, parallel frameworks, and other new features • Create basic Java objects and reuse code • Handle exceptions and events Barry Burd, PhD Author of Beginning Programming with Java For Dummies Burd www.it-ebooks.info
Get More and Do More at Dummies.com® Start with FREE Cheat Sheets Cheat Sheets include • Checklists • Charts • Common Instructions • And Other Good Stuff! To access the Cheat Sheet created specifically for this book, go to www.dummies.com/cheatsheet/java Mobile Apps Get Smart at Dummies.com Dummies.com makes your life easier with 1,000s of answers on everything from removing wallpaper to using the latest version of Windows. Check out our • Videos • Illustrated Articles • Step-by-Step Instructions Plus, each month you can win valuable prizes by entering our Dummies.com sweepstakes. * Want a weekly dose of Dummies? Sign up for Newsletters on • Digital Photography • Microsoft Windows & Office • Personal Finance & Investing • Health & Wellness • Computing, iPods & Cell Phones • eBay • Internet • Food, Home & Garden Find out “HOW” at Dummies.com *Sweepstakes not currently available in all countries; visit Dummies.com for official rules. www.it-ebooks.info There’s a Dummies App for This and That With more than 200 million books in print and over 1,600 unique titles, Dummies is a global leader in how-to information. Now you can get the same great Dummies information in an App. With topics such as Wine, Spanish, Digital Photography, Certification, and more, you’ll have instant access to the topics you need to know in a format you can trust. To get information on all our Dummies apps, visit the following: www.Dummies.com/go/mobile from your computer. www.Dummies.com/go/iphone/apps from your phone.
Java® FOR DUMmIES‰ 5TH EDITION 01_9780470371732-ffirs.indd i 01_9780470371732-ffirs.indd i 7/6/11 6:57 PM 7/6/11 6:57 PM www.it-ebooks.info
01_9780470371732-ffirs.indd ii 01_9780470371732-ffirs.indd ii 7/6/11 6:57 PM 7/6/11 6:57 PM www.it-ebooks.info
Java® FOR DUMmIES‰ 5TH EDITION by Barry Burd 01_9780470371732-ffirs.indd iii 01_9780470371732-ffirs.indd iii 7/6/11 6:57 PM 7/6/11 6:57 PM www.it-ebooks.info
Java® For Dummies®, 5th Edition Published by Wiley Publishing, Inc. 111 River Street Hoboken, NJ 07030-5774 www.wiley.com Copyright © 2011 by Wiley Publishing, Inc., Indianapolis, Indiana Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permit- ted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http:// www.wiley.com/go/permissions. Trademarks: Wiley, the Wiley Publishing logo, For Dummies, the Dummies Man logo, A Reference for the Rest of Us!, The Dummies Way, Dummies Daily, The Fun and Easy Way, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affi liates in the United States and other countries, and may not be used without written permission. Java is a registered trademark of Oracle America, Inc. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITH- OUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FUR- THER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFOR- MATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. For technical support, please visit www.wiley.com/techsupport. Wiley also publishes its books in a variety of electronic formats and by print-on-demand. Not all content that is available in standard print versions of this book may appear or be packaged in all book formats. If you have purchased a version of this book that did not include media that is referenced by or accom- panies a standard print version, you may request this media by visiting http://booksupport.wiley. com. For more information about Wiley products, visit us www.wiley.com. Library of Congress Control Number: 2011932274 ISBN: 978-0-470-37173-2 (pbk); ISBN: 978-1-118-12830-5 (ebk); ISBN: 978-1-118-12831-2 (ebk); ISBN: 978-1-118-12832-9 (ebk) Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 01_9780470371732-ffirs.indd iv 01_9780470371732-ffirs.indd iv 7/6/11 6:57 PM 7/6/11 6:57 PM www.it-ebooks.info
About the Author Barry Burd received an M.S. degree in Computer Science at Rutgers University and a Ph.D. in Mathematics at the University of Illinois. As a teaching assistant in Champaign-Urbana, Illinois, he was elected fi ve times to the university-wide List of Teachers Ranked as Excellent by their Students. Since 1980, Dr. Burd has been a professor in the Department of Mathematics and Computer Science at Drew University in Madison, New Jersey. When he’s not lecturing at Drew University, Dr. Burd leads training courses for profes- sional programmers in business and industry. He has lectured at conferences in the United States, Europe, Australia, and Asia. He is the author of several articles and books, including Android Application Development All-in-One For Dummies and Beginning Programming with Java For Dummies, both from Wiley Publishing, Inc. Dr. Burd lives in Madison, New Jersey, with his wife and two children. In his spare time, he enjoys being a workaholic. 01_9780470371732-ffirs.indd v 01_9780470371732-ffirs.indd v 7/6/11 6:57 PM 7/6/11 6:57 PM www.it-ebooks.info
01_9780470371732-ffirs.indd vi 01_9780470371732-ffirs.indd vi 7/6/11 6:57 PM 7/6/11 6:57 PM www.it-ebooks.info
分享到:
收藏