Sachvui com beginning programming with java for dummies 4th edition

483 3 0
Sachvui com beginning programming with java for dummies 4th edition

Đ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

Computers/Programming Languages/Java sier!™ a E g in th ry e v E g Makin Fully updated to reflect the new features of Java 8! • Get started — dive into the overall programming experience, from finding out what programming is all about to getting your computer ready for writing and testing programs • Jump into Java — discover the basic building blocks in any Java program, and get up to speed on how to represent data and get new values from existing values • Go with the flow — find out how to look at your program as a mansion, and learn to make your computer navigate from one room to another • One byte at a time — learn the best ways to break complex programming problems into small pieces and create solutions to solve them Open the book and find: • How to identify the words in a Java program • Plain-English explanations of Java statements and methods • The scoop on programming with windows, buttons, and other graphical items • Java troubleshooting tips • Ways to write several kinds of decision-making statements • How to diagnose loop problems • Tips, resources, and all kinds of interesting goodies Beginning Programming with Java® If you’re a new programmer, or want to be, this unintimidating guide gets you on your way toward Java mastery It explores what goes into creating a program, how to put the pieces together, debugging, and making it all work Even if you’ve never written a line of code, this book will have you ordering your computer around in no time 4th Edition Cover image: ©iStockphoto.com/Spanic Barry Burd, PhD, is a professor of mathematics and computer science at Drew University He is the author of Android Application Development All-in-One For Dummies and Java Programming for Android Developers For Dummies g n i m m a r g o r P g n i n n i g e B a v a J h t i w đ Learn to: ã The write stuff get access to all-important documents that no good Java programmer should be without • Use basic development concepts and techniques with Java • Debug Java programs and create useful code Go to Dummies.comđ ã Work with files on your computer’s hard drive for videos, step-by-step examples, how-to articles, or to shop! • Work with the latest features of Java $29.99 USA / $35.99 CAN / £21.99 UK ISBN 978-1-118-40781-3 52999 781118 407813 Burd 4th Edition Barry Burd, PhD Author of Java For Dummies® Get More and Do More at Dummies.com® Start with FREE Cheat Sheets Cheat Sheets include • Checklists • Charts • Common Instructions • And Other Good Stuff! At home, at work, or on the go, Dummies is here to help you go digital! To access the Cheat Sheet created specifically for this book, go to www.dummies.com/cheatsheet/beginningprogrammingwithjava 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 From eLearning to e-books, test prep to test banks, language learning to video training, mobile apps, and more, Dummies makes learning easier www.facebook.com/fordummies www.twitter.com/fordummies Beginning Programming with Java® 4th Edition Beginning Programming with Java® 4th Edition by Barry Burd Author of Java For Dummies Beginning Programming with Java® For Dummies®, 4th Edition Published by: John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, www.wiley.com Copyright © 2014 by John Wiley & Sons, Inc., Hoboken, New Jersey 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 permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the Publisher 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, For Dummies, the Dummies Man logo, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc 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 John Wiley & Sons, 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 WITHOUT 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 FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION 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 publishes in a variety of print and electronic formats and by print-on-demand Some material included with standard print versions of this book may not be included in e-books or in print-on-demand If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com For more information about Wiley products, visit www.wiley.com Library of Congress Control Number: 2013954218 ISBN: 978-1-118-40781-3 (pbk); ISBN 978-1-118-41756-0 (ebk); ISBN 978-1-118-46106-8 (ebk) Manufactured in the United States of America 10 Contents at a Glance Introduction Part I: Getting Started with Java Programming Chapter 1: Getting Started 11 Chapter 2: Setting Up Your Computer 23 Chapter 3: Running Programs 53 Part II: Writing Your Own Java Programs 75 Chapter 4: Exploring the Parts of a Program 77 Chapter 5: Composing a Program 97 Chapter 6: Using the Building Blocks: Variables, Values, and Types 121 Chapter 7: Numbers and Types 135 Chapter 8: Numbers? Who Needs Numbers? 153 Part III: Controlling the Flow 175 Chapter 9: Forks in the Road 177 Chapter 10: Which Way Did He Go? 193 Chapter 11: How to Flick a Virtual Switch 217 Chapter 12: Around and Around It Goes 233 Chapter 13: Piles of Files: Dealing with Information Overload 253 Chapter 14: Creating Loops within Loops 273 Chapter 15: The Old Runaround 285 Part IV: Using Program Units 309 Chapter 16: Using Loops and Arrays 311 Chapter 17: Programming with Objects and Classes 333 Chapter 18: Using Methods and Variables from a Java Class 347 Chapter 19: Creating New Java Methods 371 Chapter 20: Oooey GUI Was a Worm 393 Part V: The Part of Tens 423 Chapter 21: Ten Websites for Java 425 Chapter 22: Ten Useful Classes in the Java API 427 Index 431 Table of Contents Introduction About This Book How to Use This Book Conventions Used in This Book What You Don’t Have to Read Foolish Assumptions How This Book Is Organized Part I: Getting Started with Java Programming Part II: Writing Your Own Java Programs Part III: Controlling the Flow Part IV: Using Program Units Part V: The Part of Tens Icons Used in This Book Beyond the Book Where to Go from Here Part I: Getting Started with Java Programming Chapter 1: Getting Started 11 What’s It All About? 11 Telling a computer what to do 12 Pick your poison 13 From Your Mind to the Computer’s Processor 14 Translating your code 14 Running code 15 Code you can use 20 Your Java Programming Toolset 21 What’s already on your hard drive? 22 Eclipse 22 Chapter 2: Setting Up Your Computer 23 If You Don’t Like Reading Instructions . .  24 Getting This Book’s Sample Programs 26 Setting Up Java 27 Finding Java on your computer 32 Setting Up the Eclipse Integrated Development Environment 38 Downloading Eclipse 39 Installing Eclipse 40 Running Eclipse for the first time 41 What’s Next? 51 viii Beginning Programming with Java For Dummies, 4th Edition Chapter 3: Running Programs 53 Running a Canned Java Program 53 Typing and Running Your Own Code 58 Separating your programs from mine 59 Writing and running your program 60 What’s All That Stuff in Eclipse’s Window? 68 Understanding the big picture 69 Views, editors, and other stuff 70 What’s inside a view or an editor? 72 Returning to the big picture 74 Part II: Writing Your Own Java Programs 75 Chapter 4: Exploring the Parts of a Program 77 Checking Out Java Code for the First Time 77 Behold! A program! 78 What the program’s lines say 79 The Elements in a Java Program 80 Keywords 81 Identifiers that you or I can define 83 Identifiers with agreed-upon meanings 83 Literals 84 Punctuation 85 Comments 87 Understanding a Simple Java Program 88 What is a method? 88 The main method in a program 91 How you finally tell the computer to do something 92 The Java class 95 Chapter 5: Composing a Program 97 Computers Are Stupid 98 A Program to Echo Keyboard Input 98 Typing and running a program 100 How the EchoLine program works 103 Getting numbers, words, and other things 104 Type three lines of code and don’t look back 105 Expecting the Unexpected 107 Diagnosing a problem 108 What problem? I don’t see a problem 118 Index whole numbers reading from the keyboard, 137–138 remainder and, 143 types of, 151 using, 135–136 WhoWins type, 212–216 Wilson, Alan, 187 windows declaratively describing, 406–407 displaying on computer screen, 395–398 Eclipse, 69 jumping among, 21 Windows, Microsoft installing Eclipse, 40–41 JRE Home field, 45 Windows (XP and newer) checking Java installation on, 33 filename extensions in, 25 Windows checking Java installation on, 33 filename extensions in, 25 Windows checking Java installation on, 32 filename extensions in, 25 Windows environment, 19 Windows Notepad, 262, 313 Windows XP checking Java installation on, 33 filename extensions in, 25 word lengths, 30–32 word processing, 20 word-processing programs, editor and, 21 workbench, Eclipse See also specific parts Console view disk files and, 256 displaying text in, 254 NumberFormatException message in, 58 overview, 74 println method and, 84 display of this book’s Java projects, 50 launching Eclipse and, 25 overview, 69 running Eclipse for the first time, 42, 43 working directory, 329 workspace, Eclipse place on your hard drive for, 410 switching to a different, 59 Workspace Launcher dialog, Eclipse, 42, 54, 55, 59 wrapping displayed lines, 125 Write Once, Run Anywhere model of computing, 19 writing, to disk files, 268–271 •X• XML (eXtensible Markup Language), 406–408 •Y• yearlyInterest variable, 390 yellow marker, Eclipse editor, 68, 403 Young, Margaret Levine, 370 •Z• zeros and ones, 14–17, 126 zip files, 26, 41, 49 453 Notes Notes Notes About the Author Dr Barry Burd has an M.S in Computer Science from Rutgers University and a Ph.D in Mathematics from the University of Illinois As a teaching assistant in Champaign-Urbana, Illinois, he was elected five 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 professional 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 Java For Dummies and Android Application Development All-in-One For Dummies, both published by John Wiley & Sons, Inc Dr Burd lives in Madison, New Jersey with his wife and two kids (both in their twenties, and mostly on their own) As an avid indoor enthusiast, Dr. Burd enjoys sleeping, talking, and eating Dedication For Harriet, Sam and Jennie, Sam and Ruth, Abram and Katie, Benjamin and Jennie Author’s Acknowledgments Author’s To-Do List, February 13, 2014: Item: Send chocolates to Paul Levesque (the book’s project editor) and Melba Hopper (the book’s copy editor) As anyone who reads Chapter 4 learns, chocolate is one of the most precious commodities on earth So when I give chocolate, I give it thoughtfully and intentionally Item: Have a plaque erected in honor of Connie Santisteban, your acquisitions editor at Wiley While you worked on other projects, Connie kept on insisting that you write this book’s fourth edition (Sure, you wanted a long vacation instead of another book project, but who cares? She was right; you were wrong.) Item: Send a thank-you note to tech editor Russ Mullen who helped polish your original work and, miraculously, didn’t make a lot of extra work for you Item: Visit Frank Thornton, Bonnie Averbach, and Herbert Putz at Temple University Thank them for steering you to a career as a professor In any other career, you’d have no time left to write (And by the way, while you’re in Philly, don’t forget to stop for a cheesesteak.) Item: Send e-mail to Gaisi Takeuti at the University of Illinois, and to William Wisdom and Hughes LeBlanc at Temple University Thank them for teaching you about Symbolic Logic It’s made your life as a computer scientist and mathematician much richer Item: Spend more time with your family (Remind them that you’re the guy who wandered around the house before you started writing books.) Renew your pledge to clean up after yourself Don’t be so high-strung and finish each sentence that you start Remember that you can never fully return the love they’ve given you, but you should always keep trying Publisher’s Acknowledgments Senior Acquisitions Editor: Constance Santisteban Senior Project Editor: Paul Levesque Copy Editor: Melba Hopper Technical Editor: Russ Mullen Editorial Assistant: Annie Sullivan Sr Editorial Assistant: Cherie Case Project Coordinator: Erin Zeltner Cover Image: Spanic/iStockphoto Get More and Do More at Dummies.com® Start with FREE Cheat Sheets Cheat Sheets include • Checklists • Charts • Common Instructions • And Other Good Stuff! At home, at work, or on the go, Dummies is here to help you go digital! To access the Cheat Sheet created specifically for this book, go to www.dummies.com/cheatsheet/beginningprogrammingwithjava 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 From eLearning to e-books, test prep to test banks, language learning to video training, mobile apps, and more, Dummies makes learning easier www.facebook.com/fordummies www.twitter.com/fordummies

Ngày đăng: 01/05/2021, 15:37

Mục lục

  • Contents at a Glance

  • Table of Contents

  • Introduction

    • About This Book

    • 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

    • Beyond the Book

    • Where to Go from Here

    • Part I: Getting Started with Java Programming

      • Chapter 1: Getting Started

        • What’s It All About?

        • From Your Mind to the Computer’s Processor

        • Your Java Programming Toolset

        • Chapter 2: Setting Up Your Computer

          • If You Don’t Like Reading Instructions . .

          • Getting This Book’s Sample Programs

          • Setting Up Java

          • Setting Up the Eclipse Integrated Development Environment

          • What’s Next?

          • Chapter 3: Running Programs

            • Running a Canned Java Program

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan