Java® Programming ® for Android Developers 2nd edition by Barry Burd Java® Programming for Android® Developers For Dummies®, 2nd Edition Published by: John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, www.wiley.com Copyright © 2017 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. Android is a registered trademark of Google, 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 https://hub.wiley.com/community/support/dummies. 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: 2016954409 ISBN: 978-1-119-30108-0; 978-1-119-30109-7 (ebk); 978-1-119-30112-7 (ebk) Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 Contents at a Glance Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Part 1: Getting Started with Java Programming for Android Developers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 CHAPTER 1: All about Java and Android . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 CHAPTER 2: Getting the Tools That You Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 CHAPTER 3: Creating and Running an Android App . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Part 2: Writing Your Own Java Programs . . . . . . . . . . . . . . . . . . . . . 95 CHAPTER 4: An Ode to Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 CHAPTER 5: Java’s Building Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 CHAPTER 6: Working with Java Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 CHAPTER 7: Though These Be Methods, Yet There Is Madness in’t . . . . . . . . . . . . . . 169 CHAPTER 8: What Java Does (and When) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 Part 3: Working with the Big Picture: Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 CHAPTER 9: Why Object-Oriented Programming Is Like Selling Cheese . . . . . . . . . . 217 CHAPTER 10: Saving Time and Money: Reusing Existing Code . . . . . . . . . . . . . . . . . . . 267 Part 4: Powering Android with Java Code . . . . . . . . . . . . . . . . . . . 295 CHAPTER 11: The Inside Story . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 CHAPTER 12: Dealing with a Bunch of Things at a Time . . . . . . . . . . . . . . . . . . . . . . . . . 317 CHAPTER 13: An Android Social Media App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 CHAPTER 14: Hungry Burds: A Simple Android Game . . . . . . . . . . . . . . . . . . . . . . . . . . 381 Part 5: The Part of Tens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407 CHAPTER 15: Ten Ways to Avoid Mistakes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409 CHAPTER 16: Ten Websites for Developers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417 Table of Contents INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 How to Use This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Conventions Used in This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 What You Don’t Have to Read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Foolish Assumptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 How This Book Is Organized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Part 1: Getting Started with Java Programming for Android Developers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Part 2: Writing Your Own Java Programs . . . . . . . . . . . . . . . . . . . . . . . 5 Part 3: Working with the Big Picture: Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Part 4: Powering Android with Java Code . . . . . . . . . . . . . . . . . . . . . . 5 Part 5: The Part of Tens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 More on the web! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Icons Used in This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Beyond the Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Where to Go from Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 PART 1: GETTING STARTED WITH JAVA PROGRAMMING FOR ANDROID DEVELOPERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 CHAPTER 1: All about Java and Android . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 The Consumer Perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 The Many Faces of Android . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 The Developer Perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 From Development to Execution with Java . . . . . . . . . . . . . . . . . . . . . . . 20 What is a compiler? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 What is a virtual machine? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Java, Android, and Horticulture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 CHAPTER 2: Getting the Tools That You Need . . . . . . . . . . . . . . . . . . . . . 27 The Stuff You Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 If You Don’t Like to Read the Instructions . . . . . . . . . . . . . . . . . . . . . . . . 29 Getting This Book’s Sample Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Setting Up Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Setting Up Android Studio and the Android SDK . . . . . . . . . . . . . . . . . . 37 Launching the Android Studio IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Opening One of This Book’s Sample Programs . . . . . . . . . . . . . . . . . . . 40 Table of Contents v Using Android Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Starting up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 The main window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Things You Might Eventually Have to Do . . . . . . . . . . . . . . . . . . . . . . . . . 48 Installing new versions (and older versions) of Android . . . . . . . . . 49 Creating an Android virtual device . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 CHAPTER 3: Creating and Running an Android App . . . . . . . . . . . . . . 55 Creating Your First App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 First things first . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Launching your first app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .61 If the Emulator Doesn’t Behave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Running third-party emulators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Testing apps on a physical device . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 The Project Tool Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 The app/manifests branch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 The app/java branch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 The app/res branches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 The Gradle scripts branch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Dragging, Dropping, and Otherwise Tweaking an App . . . . . . . . . . . . . 70 Creating the “look” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Coding the behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 What All That Java Code Does . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Finding the EditText and TextView components . . . . . . . . . . . . . . . . 88 Responding to a button click . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 The rest of the code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Going Pro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 PART 2: WRITING YOUR OWN JAVA PROGRAMS . . . . . . . . . . . 95 CHAPTER 4: An Ode to Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Hello, Android! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 The Java Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 The names of classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Why Java Methods Are Like Meals at a Restaurant . . . . . . . . . . . . . . . 105 What does Mom’s Restaurant have to do with Java? . . . . . . . . . . . 106 Method declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Method call . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Method parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 The chicken or the egg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 How many parameters? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .109 Method declarations and method calls in an Android program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 vi Java Programming for Android Developers For Dummies Punctuating Your Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 Comments are your friends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 What’s Barry’s excuse? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 All About Android Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 Extending a class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 Overriding methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 An activity’s workhorse methods . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 CHAPTER 5: Java’s Building Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Info Is As Info Does . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Variable names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Type names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Assignments and initializations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Expressions and literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 How to string characters together . . . . . . . . . . . . . . . . . . . . . . . . . . 139 Java’s primitive types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .140 Things You Can Do with Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Add letters to numbers (Huh?) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 Java’s exotic assignment operators . . . . . . . . . . . . . . . . . . . . . . . . . . 146 True bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 Java isn’t like a game of horseshoes . . . . . . . . . . . . . . . . . . . . . . . . . 148 Use Java’s logical operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 Parenthetically speaking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .155 CHAPTER 6: Working with Java Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Working with Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Going from primitive types to strings . . . . . . . . . . . . . . . . . . . . . . . . 158 Going from strings to primitive types . . . . . . . . . . . . . . . . . . . . . . . . 159 Getting input from the user . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 Practice Safe Typing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Widening is good; narrowing is bad . . . . . . . . . . . . . . . . . . . . . . . . .165 Incompatible types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 Using a hammer to bang a peg into a hole . . . . . . . . . . . . . . . . . . .167 Though These Be Methods, Yet There CHAPTER 7: Is Madness in’t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 Minding Your Types When You Call a Method . . . . . . . . . . . . . . . . . . . 170 Method parameters and Java types . . . . . . . . . . . . . . . . . . . . . . . . . 173 If at first you don’t succeed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Return types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .174 The great void . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 Displaying numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 Primitive Types and Pass-by Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 What’s a developer to do? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 A final word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 Table of Contents vii CHAPTER 8: What Java Does (and When) . . . . . . . . . . . . . . . . . . . . . . . . . . 187 Making Decisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .187 Java if statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 Choosing among many alternatives . . . . . . . . . . . . . . . . . . . . . . . . . 191 Some formalities concerning Java switch statements . . . . . . . . . . 198 Repeating Instructions Over and Over Again . . . . . . . . . . . . . . . . . . . . 199 Check, and then repeat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .200 Repeat, and then check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 Count, count, count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 What’s Next? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 PART 3: WORKING WITH THE BIG PICTURE: OBJECT-ORIENTED PROGRAMMING . . . . . . . . . . . . . . . . . . . . . . . . . 215 Why Object-Oriented Programming CHAPTER 9: Is Like Selling Cheese . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 Classes and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 What is a class, really? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 What is an object? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 Creating objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 Reusing names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 Calling a constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 More About Classes and Objects (Adding Methods to the Mix) . . . . . 232 Constructors with parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .235 The default constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 This is it! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 Giving an object more responsibility . . . . . . . . . . . . . . . . . . . . . . . . 242 Members of a class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 Reference types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 Pass by reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 Java’s Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 Public classes and default-access classes . . . . . . . . . . . . . . . . . . . . 251 Access for fields and methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 Using getters and setters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 What does static mean? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 To dot, or not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 A bad example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .264 What’s Next? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 Saving Time and Money: Reusing CHAPTER 10: Existing Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 The Last Word on Employees — Or Is It? . . . . . . . . . . . . . . . . . . . . . . . . 268 Extending a class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 Overriding methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 viii Java Programming for Android Developers For Dummies