Sams Teach Yourself Beginning Programming in 24 Hours
Greg Perry Dean Miller
Beginning Programming
Third Edition
Sams Teach Yourself Beginning Programming in 24 Hours, Third Edition
Copyright ? 2014 by Pearson Education
All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein.
ISBN-10: 0-672-33700-2
ISBN-13: 978-0-672-33700-0
Library of Congress Catalog Card Number: 2013951919
Printed in the United States of America
First Printing: December 2013
Trademarks
All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark.
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an "as is" basis. The authors and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book.
Special Sales
For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at corpsales@ or (800) 382-3419.
For government sales inquiries, please contact governmentsales@.
For questions about sales outside the U.S., please contact international@.
Acquisitions Editor Mark Taber
Managing Editor Kristy Hart
Project Editor Elaine Wiley
Indexer Brad Herriman
Proofreader Anne Goebel
Technical Editor Siddhartha Singh
Publishing Coordinator Vanessa Evans
Cover Designer Mark Shirar
Compositor Nonie Ratcliff
Contents at a Glance
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Part I: Start Programming Today HOUR 1 Hands-On Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2 Process and Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3 Designing a Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 4 Getting Input and Displaying Output . . . . . . . . . . . . . . . . . . . . . . . 57 5 Data Processing with Numbers and Words . . . . . . . . . . . . . . . . . . . 75 6 Controlling Your Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 7 Debugging Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Part II: Programming Fundamentals HOUR 8 Structured Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 9 Programming Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 10 Having Fun with Programming . . . . . . . . . . . . . . . . . . . . . . . . . . 173 11 Advanced Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Part III: Object-Oriented Programming with Java HOUR 12 Programming with Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 13 Java's Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 14 Java Has Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 15 Applets and Web Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Part IV: Other Programming Languages HOUR 16 HTML5 and CSS3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 17 JavaScript and AJAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 18 Scripting with PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301 19 Programming with C and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 20 Programming with Visual Basic 2012 . . . . . . . . . . . . . . . . . . . . . . 359 21 C# and the .NET Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
Part V: The Business of Programming
HOUR 22 How Companies Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389 23 Distributing Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407 24 The Future of Programming. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
Table of Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Part I: Start Programming Today
HOUR 1: Hands-On Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Get Ready to Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 What a Computer Program Does . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Common Programming Misconceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Many Programs Already Exist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Programmers Are in Demand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 The Real Value of Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Users Generally Don't Own Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Giving Computers Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Your First Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Clarifying Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Entering Your Own Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Workshop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
HOUR 2: Process and Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Understanding the Need for Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Programs, Programs, Everywhere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Programs as Directions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Workshop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
HOUR 3: Designing a Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 The Need for Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 User-Programmer Agreement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
vi
Sams Teach Yourself Beginning Programming in 24 Hours
Steps to Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Workshop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
HOUR 4: Getting Input and Displaying Output. . . . . . . . . . . . . . . . . . . . . . . . . . 57 Printing to the Screen with JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Storing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Assigning Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Getting Keyboard Data with Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Workshop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
HOUR 5: Data Processing with Numbers and Words . . . . . . . . . . . . . . . . . . . . . 75 Strings Revisited . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Performing Math with JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 How Computers Really Do Math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Using the ASCII Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Overview of Methods. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Workshop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
HOUR 6: Controlling Your Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Comparing Data with if. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Writing the Relational Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Looping Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Workshop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
HOUR 7: Debugging Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 The First Bug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Accuracy Is Everything . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Write Clear Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Contents
vii
Practice Debugging with JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 JavaScript's Console Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Additional Debugging Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Workshop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Part II: Programming Fundamentals
HOUR 8: Structured Techniques. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Structured Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Packaging Your JavaScript Code into Functions . . . . . . . . . . . . . . . . . . . . 137 Testing the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 Profiling Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Getting Back to Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Workshop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
HOUR 9: Programming Algorithms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 Counters and Accumulators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 Array Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Accumulators for Total . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 Swapping Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 Searching Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 Taking Functions Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Nested Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 Workshop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
HOUR 10: Having Fun with Programming. . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Rotating Images on a Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Capturing the Position of the Mouse. . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 Adding a Repeating News Ticker to Your Website . . . . . . . . . . . . . . . . . . 180
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- sams teach yourself java in 24 hours covering java 7 and
- sams teach yourself java in 21 days covering java 7 and
- sams teach yourself c in 21 days gunadarma
- teach yourself java module col106 sem i 2018 19
- teach yourself java 1 2 in 24 hours
- teach yourself java in 21 minutes lth
- sams teach yourself html css javascript web publishing
- sams teach yourself beginning programming in 24 hours
- sams teach yourself javascript in 24 hours
- gr
Related searches
- uber 24 hours customer support
- how to teach yourself java
- less than 24 hours symbol
- 24 hours check cashing locations near me
- autozone 24 hours near me
- uber 24 hours customer support number
- 24 hours check cashing place
- check cashing 24 hours location
- how to teach yourself a language
- starbucks 24 hours near me
- uber 24 hours customer support phone number
- breakfast 24 hours near me