Senior Acquisitions Editor: Jeff Kellum
Development Editor: Kathi Duggan
Technical Editors: Dr. Ernest J. Friedman-Hill and Paul Nahay
Production Editor: Christine O’Connor
Copy Editor: Judy Flynn
Editorial Manager: Pete Gaughan
Production Manager: Tim Tate
Vice President and Executive Group Publisher: Richard Swadley
Vice President and Publisher: Neil Edde
Book Designer: Happenstance Type-O-Rama
Compositors: Cody Gates, Craig Johnson, and Kate Kaminski, Happenstance Type-O-Rama
Proofreader: Candace English
Indexer: Nancy Guenther
Project Coordinator, Cover: Katherine Crocker
Cover Designer: Ryan Sneed
Cover Image: © nullplus / iStockPhoto
Copyright © 2013 by John Wiley & Sons, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-1-118-35910-5
ISBN: 978-1-118-46385-7 (ebk.)
ISBN: 978-1-118-41695-2 (ebk.)
ISBN: 978-1-118-43409-3 (ebk.)
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 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.
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 Web site 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 Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites 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 or to obtain technical support, 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.
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: 2012947685
TRADEMARKS: Wiley, the Wiley logo, and the Sybex logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, 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. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.
10 9 8 7 6 5 4 3 2 1
Dear Reader,
Thank you for choosing Java SE 7 Programming Essentials. This book is part of a family of premium-quality Sybex books, all of which are written by outstanding authors who combine practical experience with a gift for teaching.
Sybex was founded in 1976. More than 30 years later, we’re still committed to producing consistently exceptional books. With each of our titles, we’re working hard to set a new standard for the industry. From the paper we print on, to the authors we work with, our goal is to bring you the best books available.
I hope you see all that reflected in these pages. I’d be very interested to hear your comments and get your feedback on how we’re doing. Feel free to let me know what you think about this or any other Sybex book by sending me an email at [email protected]. If you think you’ve found a technical error in this book, please visit http://sybex.custhelp.com. Customer feedback is critical to our efforts at Sybex.
Best regards,
Neil Edde
Vice President and Publisher
Sybex, an Imprint of Wiley
To Jocelyn, my love
Just hours before this writing, I received an email from Kathryn Duggan, this book’s development editor, saying the last chapter had now entered the pitiless, gaping maw of production. Let the grinding and forging begin. For this part of the process, I have to listen at a distance and make sense of the whirs and groans this material might force from the machine. I have to wonder what rough edges I missed that will now be cast in bronze, buffed into a high relief, and given prominence. What best parts will end up in some corner shadow or made to rest against the wall? I don’t know. The wait is almost as hard as the writing.
What we’ve put into this book, though, is our combined best effort to oil that machine, a result of collaboration, faith, rerevising, and just a little lip biting. As this book goes into the mill, I am proud to have worked with every one of its contributors.
Kathi guided this project with an unfailingly positive spirit and saw it through more than one rough patch, all the while having to pick up and move several hundred miles, then find a house. Without her diligence, kind words, and tolerance for my sprint-and-coma style of submitting chapters, I am not sure I’d have gotten this far, at least not in 2012. Thank you, Kathi; no one can expect the level of effort and encouragement you put into this book.
Ernest Friedman-Hill served as my technical editor, checking both the code and the rationale of the narrative for accuracy and consistency. You, good reader, will never again see such a bargain struck for a book of this sort. Ernest is an accomplished computer scientist, a professional of talents and abilities beyond my ken, an author in his own right, and a JavaRanch colleague whose work and contributions I have admired for over a decade. This book could have become a pale farce without his attention, his advice, and his drive on improving, well, everything. Yes, everything, right down to creating an alternate cover (which was ignored, sadly). I owe him big-time. I pledge here to pay his generosity forward. When you come across a section you think is especially sharp, I’d be pleased if you remembered Ernest for it (too). Paul Nahay reviewed the manuscript and, so far as I could tell, observed each punctuation mark with suspicion. He uncovered error after error we somehow missed. These are errors an author might forgive as understandable lapses, but errors that a disinterested eye might view as a sign of wavering competence. It can be a thankless role, and Paul did it fearlessly. Thank you, Paul.
Jeff Kellum, the acquisitions editor, might have had to vouch for me more than once. Several of my first drafts came in like a New Year’s Eve walk home: late, unintelligible, and in dire need of more solids. Thank you, Jeff, for this opportunity and for your faith. I hope the work here adds to your credit.
Pete Gaughan, the editorial manager, watched this process throughout and kept me grounded in the demands of publishing, He reminded me, tactfully and more than once, one must feed Production properly. He threw a lot of rules at me, sure, of the sort I accept with quiet grudging and irritation. He did it without apology, however, and I can’t say how much I appreciate that. Thanks, Pete, for holding the line and keeping me honest.
Many people play a part in getting a book to print, and I’m sorry I haven’t met the people who worked to make this book handsome and well-lit. The people at Sybex I did talk to made me feel it was all in good hands. I’d do this again with them. On a practical note, their attention to detail, from comma splices to color schemes, impressed me. I’d have had better luck throwing pork chops past a wolf. Thank you to production editor Christine O’Connor, copyeditor Judy Flynn, and compositors Cody Gates, Craig Johnson, and Kate Kaminski at Happenstance Type-O-Rama.
What was possible here, however, begins with my students and colleagues. I taught my first Java course in 1995. Today, I wonder how I ever got the nerve. For everyone who said you learned a concept or a technique from me that still pays off, or just told me I added something to the good, thank you. You’re the reason I still teach this subject and why I thought some written words might help a few more people on their way.
Michael Ernest entered the world of Java programming the way many people do. He spent three years as a bank teller, operated a forklift, earned a degree in English at an aggie college, spent four years as a firefighter, earned an advanced degree in English literature, sold baseball cards and comic books, began doctoral studies at Claremont Graduate School, and taught night classes. He then took an entry-level job in data processing at Bank of America, followed by a job at a global chemical-manufacturing concern and then jobs at Access Graphics, Lockheed Martin, General Electric, Synergistic Computer Solutions, and FusionStorm. He still has all the never-quite-vested retirement plans and darling little 401(k) accounts to prove it.
In that time, Ernest was once left alone for three weeks with a shelf of abandoned O’Reilly books and a SPARC IPX computer. One entire 435 MB drive and 48 whole MB of RAM! He discovered a passion for Sun Microsystems technology to add to his passion for adult learning and has enjoyed teaching computing courses ever since.
Ernest started his own subject matter–expert group, Inkling Research, in 1999. He currently consults, teaches, writes, and speaks on several topics, including Solaris-based technologies such as ZFS, Containers, and DTrace; Java SE/EE programming; software architecture; fault analysis; and performance management. He writes and maintains his own courses in several technologies and products, including DTrace, Solaris 11, GlassFish, Tomcat, ActiveMQ, and ServiceMix. He has written some standard courses for Sun and Oracle and served as an adviser and reviewer for a few more.
Often asked to speak on minor topics of limited appeal at the last minute, Ernest has spoken at JavaOne, TheServerSide Java Symposium, and Oracle OpenWorld. He very nearly spoke to five people at a conference session in 2011, but then they announced snacks over the loudspeaker.
Ernest lives in the San Francisco Bay Area with his wife, Jocelyn; a teenage daughter who loves marching band; and a son who will attend a college you’ve never heard of in the fall of 2012. Ernest studies Kung Jung Mu Sul and tai chi and claims the record for the least possible aptitude for the guitar among people who won’t give up. His first and only 500 GB hard drive is holding steady at one-third full.
13.58.120.57