Preface

Writing the Third Edition

The exam for the Sun Certified Programmer for Java Platform, Standard Edition 6, has changed considerably since the second edition of this book was published. The most noticeable change in the current version of the Sun Certified Java Programmer (SCJP) 1.6 exam is the inclusion of the features of Java 5, and the shifting of emphasis towards analyzing code scenarios, rather than individual language constructs. In our opinion, the new exam demands an even greater understanding and actual experience of the language, rather than mere recitation of facts. Proficiency in the language is the key to success.

Since the emphasis of the SCJP 1.6 exam is on the core features of Java, the third edition provides even greater in-depth coverage of the relevant topics. The book covers not just the exam objectives, but also supplementary topics that aid in mastering the exam topics.

The third edition is still a one-source guide for the SCJP 1.6 exam: it provides a mixture of theory and practice for the exam. Use the book to learn Java, pass the SCJP 1.6 exam, and afterwards, use it as a handy language guide. The book also has an appendix devoted to the SCJP 1.6 Upgrade exam.

We have taken into consideration the feedback we have received from readers. The many hours spent in handling the deluge of e-mail have not been in vain. Every single e-mail is appreciated and is hereby acknowledged.

Preparing the third edition dispelled our illusions about newer editions being, to put it colloquially, a piece of cake. Every sentence from the second edition has been weighed carefully, and not many paragraphs have escaped rewriting. UML (Unified Modeling Language) is also extensively employed in this edition. Numerous new review questions have been added. In covering the new topics and expanding the existing ones, new examples, figures, and tables were also specifically created for the third edition.

About This Book

This book provides extensive coverage of the Java programming language and its core Application Programming Interfaces (APIs), with particular emphasis on its syntax and usage. The book is primarily intended for professionals who want to prepare for the SCJP 1.6 exam, but it is readily accessible to any programmer who wants to master the language. For both purposes, it provides in-depth coverage of essential features of the language and its core APIs.

There is a great and increasing demand for certified Java programmers. Sun Microsystems has defined the SCJP 1.6 exam as one that professionals can take to validate their skills. The certification provides the IT industry with a standard to use for hiring such professionals, and allows the professionals to turn their Java skills into credentials that are important for career advancement.

The book provides extensive coverage of all the objectives defined for the exam by Sun. But the exam objectives are selective and do not include many of the essential features of Java. This book covers many additional topics that every Java programmer should master in order to be proficient. In this regard, the book is a comprehensive primer for learning the Java programming language. After mastering the language by working through this book, the reader can confidently sit for the exam.

This book is not a complete reference for Java, as it does not attempt to list every member of every class from the Java Development Kit (JDK) API documentation. The purpose is not to document the JDK APIs. This book does not teach programming techniques. The emphasis is on the Java programming language features, their syntax and correct usage through code examples.

The book assumes little background in programming. We believe the exam is accessible to any programmer who works through the book. A Java programmer can easily skip over material that is well understood and concentrate on parts that need reinforcing, whereas a programmer new to Java will find the concepts explained from basic principles.

Each topic is explained and discussed thoroughly with examples, and backed by review questions and exercises to reinforce the concepts. The book is not biased toward any particular platform, but provides platform-specific details where necessary.

Using the Book

The reader can choose a linear or a non-linear route through the book, depending on her programming background. Non-Java programmers wishing to migrate to Java can read Chapter 1, which provides a short introduction to object-oriented programming concepts, and the procedure for compiling and running Java applications. For those preparing for the SCJP 1.6 exam, the book has a separate appendix providing all the pertinent information on taking the exam.

The table of contents; listings of tables, examples, and figures; and a comprehensive index facilitate locating topics discussed in the book.

In particular, we draw attention to the following features:

Review Questions

Review Questions

Review questions are provided after every major topic, in order to test and reinforce the material. These review questions reflect the kinds of questions that can be asked on the actual exam. Annotated answers to the review questions are provided in a separate appendix.

Example 0.1 Example Source Code

We encourage experimenting with the code examples in order to reinforce the material from the book. These can be downloaded from the book Web site (see p. xli).

Java code is written in a mono-spaced font. Lines of code in the examples or in code snippets are referenced in the text by a number, which is specified by using a single-line comment in the code. For example, in the following code snippet, the call to the method doSomethingInteresting() hopefully does something interesting at (1).

<a id="page_xl/">// ...
doSomethingInteresting();                                      // (1)
// ...

Names of classes and interfaces start with an uppercase letter. Names of packages, variables, and methods start with a lowercase letter. Constants are all in uppercase letters. Interface names begin with the prefix 'I'. Coding conventions are followed, except when we have had to deviate in the interest of space or clarity.

Chapter Summary

Chapter Summary

Each chapter concludes with a summary of the topics, pointing out the major concepts discussed in the chapter.

Programming Exercises

Programming Exercises

Programming exercises at the end of each chapter provide the opportunity to put concepts into practice. Solutions to the programming exercises are provided in a separate appendix.

Mock Exam

A complete mock exam is provided in a separate appendix, which the reader can try when she is ready.

Java SE API Documentation

A vertical gray bar is used to highlight methods and fields found in the classes of the core Java APIs.

Any explanation following the API information is also similarly highlighted.

In order to obtain optimal benefit from using this book in preparing for the SCJP 1.6 exam, we strongly recommend installing the latest version (1.6 or newer) of the JDK and its accompanying API documentation. The book focuses solely on Java, and does not acknowledge previous versions.

Java Platform Upgrade Exam

For those who have taken the Sun Certified Programmer for Java Platform 1.5 Exam, and would like to prepare for the Sun Certified Programmer for Java Platform 1.6 Upgrade Exam, we have provided an appendix with details of the upgrade exam. The appendix contains the upgrade exam objectives, and for each section of the syllabus, references are included to point the reader to topics essential for the upgrade exam.

Book Web Site

This book is backed by a Web site providing auxiliary material:

http://www.ii.uib.no/~khalid/pgjc3e/

The contents of the Web site include the following:

• source code for all the examples and programming exercises in the book

• mock exam engine

• errata

• links to miscellaneous Java resources (certification, discussion groups, tools, etc.)

Information about the Java Standard Edition and its documentation can be found at the following Web site:

http://java.sun.com/javase/

The current authoritative technical reference for the Java programming language, The Java Language Specification, Third Edition (also published by Addison-Wesley), can be found at this Web site:

http://java.sun.com/docs/books/jls/

Request for Feedback

Considerable effort has been made to ensure the accuracy of the contents of this book. Several Java professionals have proofread the manuscript. All code examples (including code fragments) have been compiled and tested on various platforms. In the final analysis, any errors remaining are the sole responsibility of the authors.

Any questions, comments, suggestions, and corrections are welcome. Let us know whether the book was helpful or detrimental for your purposes. Any feedback is valuable. The authors can be reached by the following e-mail alias:

[email protected]

About the Authors

Khalid A. Mughal

Khalid A. Mughal is an Associate Professor at the Department of Informatics at the University of Bergen, Norway. Professor Mughal is responsible for designing and implementing various courses, which use Java, at the Department of Informatics. Over the years, he has taught Programming Languages (Java, C/C++, Pascal), Software Engineering (Object-Oriented System Development), Databases (Data Modeling and Database Management Systems), and Compiler Techniques. He has also given numerous courses and seminars at various levels in object-oriented programming and system development, using Java and Java-related technology, both at the University and for the IT industry. He is the principal author of the book, responsible for writing the material covering the Java topics.

Professor Mughal is also the principal author of an introductory Norwegian textbook on programming in Java (Java som første programmeringsspråk/Java as First Programming Language, Third Edition, Cappelen Akademisk Forlag, ISBN-10: 82-02-24554-0, 2006), which he co-authored with Torill Hamre and Rolf W. Rasmussen. Together they have also published another textbook for a 2-semester course in programming (Java Actually: A Comprehensive Primer in Programming, Cengage Learning, ISBN-10: 1844809331, 2008).

His current work involves applying Object Technology in the development of content management systems for publication on the Web, and security issues related to web applications. For the past seven years he has been responsible for developing and running web-based programming courses in Java, which are offered to off-campus students.

He is also a member of the Association for Computing Machinery (ACM).

Rolf W. Rasmussen

Rolf W. Rasmussen is the System Development Manager at vizrt, a company that develops solutions for the TV broadcast industry, including real-time 3D graphic renderers, and content and control systems.

Rasmussen works mainly on control and automation systems, video processing, typography, and real-time visualization. He has worked on clean room implementations of the Java class libraries in the past, and is a contributor to the Free Software Foundation.

Over the years, Rasmussen has worked both academically and professionally with numerous programming languages, including Java. He is primarily responsible for developing the review questions and answers, the programming exercises and their solutions, the mock exam, and all the practical aspects related to taking the SCJP exam presented in this book.

As mentioned above, he is also a co-author of two introductory textbooks on programming in Java.

Acknowledgments (First Edition)

A small application for drawing simple shapes is used in the book to illustrate various aspects of GUI building. The idea for this application, as far as we know, first appeared in Appendix D of Data Structures and Problem Solving Using Java (M.A. Weiss, Addison-Wesley, 1998).

At Addison-Wesley-Longman (AWL), we would like to thank Emma Mitchell for the support and the guidance she provided us right from the start of this project, Martin Klopstock at AWL for accommodating the non-standard procedure involved in getting the book to the printing press, Clive Birks at CRB Associates for providing the professional look to the contents of this book, and finally, Sally Mortimore at AWL for seeing us over the finishing line. The efforts of other professionals behind the scenes at AWL are also acknowledged.

Many reviewers have been involved during the course of writing this book. First of all, we would like to thank the five anonymous reviewers commissioned by AWL to review the initial draft. Their input was useful in the subsequent writing of this book.

Several people have provided us with feedback on different parts of the material at various stages: Jon Christian Lønningdal, Tord Kålsrud, Kjetil Iversen, Roy Oma, and Arne Løkketangen. Their help is hereby sincerely acknowledged.

We are also very grateful to Laurence Vanhelsuwé, Kris Laporte, Anita Jacob, and Torill Hamre for taking on the daunting task of reviewing the final draft, and providing us with extensive feedback at such short notice. We would like to thank Marit Mughal for reading the manuscript with the trained eye of a veteran English schoolteacher.

We now understand why family members are invariably mentioned in a preface. Without our families’ love, support, and understanding this book would have remained a virtual commodity. Khalid would like to thank Marit, Nina, and Laila for their love, and for being his pillars of support, during the writing of this book. Thanks also to the folks in Birmingham for cheering us on. Rolf would like to thank Liv, Rolf V., Knut, and Elisabeth for enduring the strange working hours producing this book has entailed. A special thanks to Marit for providing us with scrumptious dinners for consumption at the midnight hour.

Acknowledgments (Second Edition)

Feedback from many readers helped us to improve the first edition. We would like to thank the following readers for their input in this effort:

Michael F. Adolf, Tony Alicea, Kåre Auglænd, Jorge L. Barroso, Andre Beland, Darren Bruning, Paul Campbell, Roger Chang, Joanna Chappel, Laurian M Chirica, Arkadi Choufrine, Barry Colston, John Cotter, Frédéric Demers, Arthur De Souza, djc, William Ekiel, Darryl Failla, John Finlay, Christopher R. Gardner, Marco Garcia, Peter Gieser, George, Paul Graf, Shyamsundar Gururaj, Ray Ho, Leonardo Holanda, Zhu Hongjun, Kara Van Horn, Peter Horst, Nain Hwu, Kent Johnson, Samir Kanparia, Oleksiy Karpenko, Jeffrey Kenyon, Young Jin Kim, Kenneth Kisser, Billy Kutulas, Yi-Ming Lai, Robert M. Languedoc, Steve Lasley, Winser Lo, Naga Madipalli, Craig Main, Avinash Mandsaurwale, Thomas Mathai, S. Mehra, Yuan Meng, Simon Miller, William Moore, Anders Morch, George A. Murakami, Sandy Nemecek, Chun Pan, Abigail García Patiño, Anil Philip, Alfred Raouf, Peter Rorden, Christian Seifert, Gurpreet Singh, Christopher Stanwood, Swaminathan Subramanian, Siva Sundaram, Manju Swamy, John Sweeney, Harmon Taylor, Andrew Tolopko, Ravi Verma, Per J. Walstrøm, Chun Wang, James Ward, Winky, Chun Wang, Jimmy Yang, Jennie Yip, Yanqu Zhou, and Yingting Zhou.

At the UK office of Addison-Wesley/Pearson Education, we would like to thank our former editor Simon Plumtree for his unceasing support and patience while we slogged on with the second edition. We would also like to acknowledge the help and support of the following professionals, past and present, at the London office: Alison Birtwell, Sally Carter, Karen Sellwood and Katherin Ekstrom. A special thanks to Karen Mosman (who has since moved on to another job) for her encouragement and advice.

During the last lap of getting the book to the printing press, we were in the capable hands of Ann Sellers at the US office of Addison-Wesley/Pearson Education. We would like to acknowledge her efforts and that of other professionals—in particular, Greg Doench, Jacquelyn Doucette, Amy Fleischer, Michael Mullen, and Dianne Russell—who helped to get this book through the door and on to the bookshelf. Thanks also to Mike Hendrickson for always lending an ear when we met at the OOPSLA conferences, and pointing us in the right direction with our book plans.

We would like to thank the folks at Whizlabs Software for their collaboration in producing the contents for the CD accompanying this book. Those guys certainly know the business of developing exam simulators for certification in Java technology.

We were fortunate in having two Java gurus—Laurence Vanhelsuwé and Marcus Green—to do the technical review of the second edition. As he did for the first edition, Laurence came through and provided us with invaluable feedback, from the minutiae of writing technical books to many technical issues relating to the Java programming language. Marcus put the manuscript through his severe certification scrutiny regarding the specifics of the SCJP exam. We are sorry to have upset their plans for Easter holidays, and hasten to thank them most profusely for taking on the task.

We cannot thank enough our own in-house, private copy-editor: Marit Seljeflot Mughal. She diligently and relentlessly read numerous drafts of the manuscript, usually at very short notice. Marit claims that if she understood what we had written, then a computer-literate person should have no problem whatsoever. This claim remains to be substantiated. If any commas are not used correctly, then it is entirely our fault, in spite of being repeatedly shown how to use them.

We are also indebted to many Java-enabled individuals for providing us valuable feedback on parts of the manuscript for the second edition. This includes Pradeep Chopra, Seema R., and Gaurav Kohli at Whizlabs Software. Unfortunately for us, they only had time to read part of the manuscript. Thanks also to Torill Hamre at the Nansen Environmental and Remote Sensing Center, Bergen, for her useful comments and suggestions. We also thank the following Master students at the Department of Informatics, University of Bergen, for providing useful feedback: Mikal Carlsen, Yngve Espelid, Yngve A. Aas, Sigmund Nysæter, Torkel Holm, and Eskil Saatvedt.

Family support saw us through this writing project as well. Our families have put up with our odd and long working hours, endured our preoccupation and our absence at the dining table. Khalid would like to acknowledge the love and support of his wife, Marit, and daughters, Nina and Laila, while working on this book. Rolf would like to thank Liv, Rolf V., Knut, and Elisabeth for their love, patience and support.

Acknowledgments (Third Edition)

Many readers have sent us e-mails testifying that the Programmer’s Guide contributed toward their success on the exam. That is the best advertisement we can hope for. The feedback we have received since the publication of the second edition has had an impact on improving the third edition. In particular, we would like to thank the following diligent readers for their contributions:

Bret ABMac, Einar Andresen, Brian Bradshaw, Nicola Cammillini, Juan Carlos Castro, Sweta Doshi, David Featherstone, Danish Halim, Niels Harremoës, John Holcroft, Leong Jern-Kuan, Rajesh Kesarwani, Ken Kisser, Shampa Kumar, Tony LaPaso, Kaydell Leavitt, Luba Leyzerenok, Adam Lorentzon, Chuck Meier, Philip Mitchell, Sigmund Nysæter, Pat Owens, Sanket Reddy, Raul Saavedra, Oliver Schoettler, Wayne Schroeter, Mark Sullivan, Myoung Son, Bob Souther, Anthony Tang, Frederik Uyttersprot.

Erik Ernst was kind enough to review the chapter on Java generics, for which we are very grateful. The generics chapter was also reviewed by Erik Andreas Brand-stadmoen and Kristian Berg. Our sincere thanks to all of you. The pages of feedback we received helped to clarify many subtleties, and made us realize that some dark corners of Java generics are best avoided by mere mortals.

Selected chapters for the third edition were also vetted by the following Java developers in the Bergen area: Olve Hansen, David J.M. Karlsen and Lars Søraas. Many thanks for taking time out from your busy schedule to provide us with your feedback. Our thanks also to Helge W. Johnsen and Amund Trovåg for feedback on review questions regarding new features in Java 1.5.

Our award for Reviewer Par Excellence goes to Jennie Yip. The meticulous notes she provided for the ten chapters of the second edition have had a profound effect on shaping the third edition. Any chance that the feat can be repeated with the third edition? Please name your price.

This time around we were again fortunate enough to have Marcus Green as our technical reviewer. We have heeded his feedback that has kept us, we hope, on the straight and narrow as far as the exam is concerned, and curbed our enthusiasm for including every Java topic that we fancied. Our sincere thanks for the review you provided us.

At Pearson, we would like to thank Greg Doench and Michelle Housley for managing the publication of this edition. We are also grateful to the people behind the scenes at Pearson who helped get the book to the printing press.

Khalid would like to thank the Computer Science Department at Cornell University, where he spent a significant part of his sabbatical (Fall 2007/Spring 2008) working on the third edition. A better place for such an endeavour would be hard to come by.

We cannot thank enough Marit Seljeflot Mughal who has been our personal quality controller, acting as an amalgamated draft reader, copy editor, and proofreader. What she sanctioned we could confidently allow to be seen by the light of day, saving us many embarrassing mistakes, both technical and non-technical. We don’t know if it is for us or for the love of Java that you scrutinize the endless drafts that we lay in your path.

Any mistakes or errors remaining are an oversight on our part. Rest assured that every possible effort has been made to get the facts straight.

Without family support this edition would still be wishful thinking. Khalid would like to thank Marit, Laila, Nina and Kenneth for their love, support and understanding—particularly, while working on this book.

—Khalid A. Mughal

Rolf W. Rasmussen

September 2008
Ithaca, New York, USA
Bergen, Norway

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.252.87