Using Your Sybex Electronic Book To realize the full potential of this Sybex electronic book, you must have Adobe Acrobat Reader with Search installed on your computer To find out if you have the correct version of Acrobat Reader, click on the Edit menu—Search should be an option within this menu file If Search is not an option in the Edit menu, please exit this application and install Adobe Acrobat Reader with Search from this CD (doubleclick rp500enu.exe in the Adobe folder) Navigation Navigate through the book by clicking on the headings that appear in the left panel; the corresponding page from the book displays in the right panel Search To search, click the Search Query button on the toolbar or choose Edit >Search > Query to open the Search window In the Adobe Acrobat Search dialog’s text field, type the text you want to find and click Search Use the Search Next button (Control+U) and Search Previous button (Control+Y) to go to other matches in the book The Search command also has powerful tools for limiting and expanding the definition of the term you are searching for Refer to Acrobat's online Help (Help > Plug-In Help > Using Acrobat Search) for more information Click here to begin using your Sybex Elect ronic Book! www.sybex.com Complete Java™ Certification Study Guide Third Edition Philip Heller Simon Roberts San Francisco • London Copyright ©2002 SYBEX, Inc., Alameda, CA www.sybex.com Associate Publisher: Richard Mills Acquisitions and Developmental Editor: Denise Santoro Lincoln Editor: Tiffany Taylor Production Editor: Dennis Fitzgerald Technical Editors: Michael Dailous, Natalie Levi, Kathy Collina, Bryan Basham Book Designer: Bill Gibson Graphic Illustrator: Tony Jonick Electronic Publishing Specialist: Interactive Composition Corporation Proofreaders: Nelson Kim, Dave Nash, Laurie O’Connell, Yariv Rabinovitch, Nancy Riddiough Indexer: Ted Laux CD Coordinator: Dan Mummert CD Technician: Kevin Ly Cover Designer: Archer Design Cover Illustrator/Photographer: John Wang, PhotoDisc Copyright © 2002 SYBEX Inc., 1151 Marina Village Parkway, Alameda, CA 94501 World rights reserved No part of this publication may be stored in a retrieval system, transmitted, or reproduced in any way, including but not limited to photocopy, photograph, magnetic, or other record, without the prior agreement and written permission of the publisher Library of Congress Card Number: 2002101979 ISBN: 0-7821-4077-7 SYBEX and the SYBEX logo are either registered trademarks or trademarks of SYBEX Inc in the United States and/or other countries Screen reproductions produced with Collage Complete Collage Complete is a trademark of Inner Media Inc TRADEMARKS: SYBEX has attempted throughout this book to distinguish proprietary trademarks from descriptive terms by following the capitalization style used by the manufacturer The author and publisher have made their best efforts to prepare this book, and the content is based upon final release software whenever possible Portions of the manuscript may be based upon pre-release versions supplied by software manufacturer(s) The author and the publisher make no representation or warranties of any kind with regard to the completeness or accuracy of the contents herein and accept no liability of any kind including but not limited to performance, merchantability, fitness for any particular purpose, or any losses or damages of any kind caused or alleged to be caused directly or indirectly from this book Manufactured in the United States of America 10 Copyright ©2002 SYBEX, Inc., Alameda, CA www.sybex.com To our valued readers, The success of Sun’s Java certification program has surpassed all expectations; it is now widely recognized as the hottest programmer certification Java is now a first-class citizen in the world of programming languages and increasing use of the Java Platform for enterprise-class applications has fueled demand for the certifications Sybex is proud to have helped thousands of candidates for the Programmer and Developer certifications prepare for these challenging exams since the publication of the first edition of Complete Java Certification Study Guide in 1997 Authors Philip Heller and Simon Roberts have played a major role over the years in developing these exams for Sun, and their best-selling book has established a strong reputation as the exam preparation guide of choice The authors and editors have worked hard to ensure that the new edition you hold in your hands is comprehensive, in-depth, and pedagogically sound We’re confident that this book will exceed the demanding standards of the certification marketplace and help you succeed in your endeavors As always, your feedback is important to us Please send comments, questions, or suggestions to support@sybex.com At Sybex we’re continually striving to meet the needs of individuals preparing for IT certification exams Good luck in pursuit of your Java certification! Richard Mills Associate Publisher—Programming Sybex Inc Copyright ©2002 SYBEX, Inc., Alameda, CA www.sybex.com Software License Agreement: Terms and Conditions The media and/or any online materials accompanying this book that are available now or in the future contain programs and/or text files (the “Software”) to be used in connection with the book SYBEX hereby grants to you a license to use the Software, subject to the terms that follow Your purchase, acceptance, or use of the Software will constitute your acceptance of such terms The Software compilation is the property of SYBEX unless otherwise indicated and is protected by copyright to SYBEX or other copyright owner(s) as indicated in the media files (the “Owner(s)”) You are hereby granted a single-user license to use the Software for your personal, noncommercial use only You may not reproduce, sell, distribute, publish, circulate, or commercially exploit the Software, or any portion thereof, without the written consent of SYBEX and the specific copyright owner(s) of any component software included on this media In the event that the Software or components include specific license requirements or end-user agreements, statements of condition, disclaimers, limitations or warranties (“End-User License”), those End-User Licenses supersede the terms and conditions herein as to that particular Software component Your purchase, acceptance, or use of the Software will constitute your acceptance of such End-User Licenses By purchase, use or acceptance of the Software you further agree to comply with all export laws and regulations of the United States as such laws and regulations may exist from time to time Software Support Components of the supplemental Software and any offers associated with them may be supported by the specific Owner(s) of that material, but they are not supported by SYBEX Information regarding any available support may be obtained from the Owner(s) using the information provided in the appropriate read.me files or listed elsewhere on the media Should the manufacturer(s) or other Owner(s) cease to offer support or decline to honor any offer, SYBEX bears no responsibility This notice concerning support for the Software is provided for your information only SYBEX is not the agent or principal of the Owner(s), and SYBEX is in no way responsible for providing any support for the Software, nor is it liable or responsible for any support provided, or not provided, by the Owner(s) Warranty SYBEX warrants the enclosed media to be free of physical defects for a period of ninety (90) days after purchase The Software is not available from SYBEX in any other form or media than that enclosed herein or posted to www.sybex.com If you discover a defect in the media during this warranty period, you may obtain a replacement of identical format at no charge by sending the defective media, postage prepaid, with proof of purchase to: SYBEX Inc Product Support Department 1151 Marina Village Parkway Alameda, CA 94501 Web: http://www.sybex.com After the 90-day period, you can obtain replacement media of identical format by sending us the defective disk, proof of purchase, and a check or money order for $10, payable to SYBEX Disclaimer SYBEX makes no warranty or representation, either expressed or implied, with respect to the Software or its contents, quality, performance, merchantability, or fitness for a particular purpose In no event will SYBEX, its distributors, or dealers be liable to you or any other party for direct, indirect, special, incidental, consequential, or other damages arising out of the use of or inability to use the Software or its contents even if advised of the possibility of such damage In the event that the Software includes an online update feature, SYBEX further disclaims any obligation to provide this feature for any specific duration other than the initial posting The exclusion of implied warranties is not permitted by some states Therefore, the above exclusion may not apply to you This warranty provides you with specific legal rights; there may be other rights that you may have that vary from state to state The pricing of the book with the Software by SYBEX reflects the allocation of risk and limitations on liability contained in this agreement of Terms and Conditions Shareware Distribution This Software may contain various programs that are distributed as shareware Copyright laws apply to both shareware and ordinary commercial software, and the copyright Owner(s) retains all rights If you try a shareware program and continue using it, you are expected to register it Individual programs differ on details of trial periods, registration, and payment Please observe the requirements stated in appropriate files Copy Protection The Software in whole or in part may or may not be copyprotected or encrypted However, in all cases, reselling or redistributing these files without authorization is expressly forbidden except as specifically provided for by the Owner(s) therein Copyright ©2002 SYBEX, Inc., Alameda, CA www.sybex.com To Richard Philip Gross, 1903–2002: a man of his century, and so much more —Philip For my children, Emily and Bethan —Simon Copyright ©2002 SYBEX, Inc., Alameda, CA www.sybex.com Acknowledgments Thanks to Ginni for all the radiance Thanks to Michelle and Ricardo for keeping me on my toes Thank you to Natalie Levi, Bryan Basham and Kathy Collina —Philip Heller The authors would like to thank the people at Sybex: Richard Mills, Denise Santoro Lincoln, Dennis Fitzgerald, Tiffany Taylor, Ted Laux, Dan Mummert Copyright ©2002 SYBEX, Inc., Alameda, CA www.sybex.com Introduction Hello! Come in, sit down, and make yourself at home Please get comfortable; there are a lot of topics to cover in this book You have come here because you are ready Ready to get ready, at least, which is practically the same thing Now all that’s left to is the work And there is a lot of work to be done Probably you have heard that the Programmer’s and Developer’s Exams are difficult, and it’s true Not everybody passes, even on repeated attempts We want to change these statistics by offering you a little help About the Authors This is, after all, the introduction, so allow us to introduce ourselves: We are Phil and Simon (We used to be Simon and Phil, but we’re trading off in this edition and now Phil is the lead author The only difference it makes is that you probably found this book under under “H” instead of “R”.) Now that we’ve met, you might wonder why you should trust a couple of guys you just met, who claim to know about the certification exams Very good question A lot of people are writing study guides and websites Who should you trust? We hope you will choose us We have the best background of any team around Simon led the group that wrote all the questions for the exams He continues to be the driving force behind exam development Phil is an ongoing consultant for development of the exams, is one of the assessors for the Developer’s Exam, and wrote the technical proposal for the new revision of the Developer’s Exam; so, he also has an inside view Our unique relationship with Sun (Simon as an employee, Phil as a consultant) places a few restrictions on us We can’t give away any answers to the questions on the exams (We wouldn’t want to that anyway; we want you to pass because you’re good at Java, not because we slipped you a crib.) We had to make sure the sample questions did not accidentally match any of the real test questions It took a bit more work, but we think the benefit to you is tremendous: Everything in this book is here for a very good reason If it’s here, then we know you need to know about it We understand that buying a book like this costs you money, reading it costs you time, and absorbing it costs you effort We appreciate your investment, and we believe it will pay off Copyright ©2002 SYBEX, Inc., Alameda, CA www.sybex.com xxiv Introduction If you read this book, absorb it, solve the practice questions at the end of each chapter, and work through the practice exam on the CD-ROM, you will be in the best possible position when you walk through the doors of your local testing center The Importance of Certification How important is certification? Importance is a tricky concept, and it has a lot to with opinion and subjective experience Of course we believe certification is very important, because we spent all this time writing a book about it But what does the rest of the world believe? It would be useful if we could just quote the statistics for you: This many people take the exams each month, this many pass; the curves grow at this rate, have this second derivative, predict this trend Unfortunately we’re not allowed to that Sun treats all such information as confidential Not just wink-nudge confidential, but really confidential Don’t trust any statistics anybody tries to give you We can’t give you the raw numbers, but we can give you four pieces of anecdotal evidence that show the world is taking Java certification very seriously: Sales of the previous editions of this book have been, well, gratifying We would like to express our sincere gratitude to all the readers who have previously bought the book, read it, and used it to gain their certification Other publishers are deciding that Java certification is big enough that they should get in the game We have even seen at least one book that is as close as it can legally come to being a shameless imitation of ours The sincerest form of flattery! We still believe we can give you the best information, because we designed the Programmer’s and Developer’s exams and continue to maintain them Attendance at Phil’s “Fast-Path Java Platform Certification” seminar is strong despite the downturn in the tech economy and the shrinking of the tradeshow and technical education sectors The fourth bit of evidence is a program that was announced at the June 1999 JavaOne conference Four impressive companies—IBM, Oracle, Novell, and Netscape—joined with Sun in an initiative to endorse Java certification The endorsements took the form of action, not just words and press releases (You can read about the details of this initiative and its current member companies in Appendix D, “The Copyright ©2002 SYBEX, Inc., Alameda, CA www.sybex.com Introduction xxv Certification Initiative for Enterprise Development.”) The big idea is that the member companies, along with Sun, are throwing their considerable weight behind the proposition that people who claim to know how to program in Java should be able to prove it This is in marked contrast to a hiring philosophy that was prevalent a few years ago when the economy was ridiculously strong The old hiring criterion was to see if the candidate’s resume said “Java” on it somewhere If the candidate passed this test, a cold mirror was held in front of the candidate’s mouth Misty condensation on the mirror meant “hire”; no condensation meant “don’t hire, this one isn’t breathing.” Friends in the medical profession assure me that even a person in a coma can fog a mirror But they can’t write good code, and the certification initiative is out to replace the mirror test with much more difficult exams Everybody who worked on this book is extremely pleased with how it turned out We hope you enjoy reading it, enjoy taking the exams, greatly enjoy being told that you have passed, and boundlessly enjoy the career freedom that certification brings What’s New in This Edition? We have kept the basic organization of the original book, but we have gone over the content with a fine tooth comb We have also added some new material that we think you’ll really like: We added over 100 questions to the CD-ROM These, in addition to the 150 that were already on the CD-ROM, the questions at the end of each chapter, and the 50-question “Programmer’s Final Exam,” should get you good and ready We updated our coverage of the Programmer’s Exam to reflect the new revision, which covers the J2SE 1.4 revision of Java We updated our coverage of the Developer’s Exam to reflect the new revision We added an appendix that describes Sun’s other Java exams Taking the Exam You can take the Java Certification Exam whenever you like, by making an appointment with Sun Educational Services Sun contracts with third-party test centers throughout the world, so hopefully you won’t have to travel far The cost of taking the exam is $150 Copyright ©2002 SYBEX, Inc., Alameda, CA www.sybex.com ... Copyright 20 02 SYBEX, Inc., Alameda, CA www .sybex. com To Richard Philip Gross, 1903 20 02: a man of his century, and so much more —Philip For my children, Emily and Bethan —Simon Copyright 20 02 SYBEX, ... begin Copyright 20 02 SYBEX, Inc., Alameda, CA www .sybex. com The Programmer’s Exam Copyright 20 02 SYBEX, Inc., Alameda, CA PART I www .sybex. com Chapter Language Fundamentals JAVA CERTIFICATION. .. bits 27 27 − short 16 bits 21 5 21 5 − int 32 bits 23 1 23 1 − long 64 bits 26 3 26 3 − The char type is integral but unsigned The range of a variable of type char is from through 21 6 − Java characters