Cover image for The Java tutorial: a short course on the basics
The Java tutorial: a short course on the basics
Campione, Mary.
Personal Author:
Third edition.
Publication Information:
Boston : Addison-Wesley, [2001]

Physical Description:
xi, 580 pages : illustrations ; 24 cm. + 1 computer optical disc (4 3/4 in.).
Format :


Call Number
Material Type
Home Location
Item Holds
QA76.73.J38 C365 2001 Book and Software Set Central Closed Stacks

On Order



The world's most widely praised Java tutorial has just been streamlined and updated for v1.3 of the Java Platform Standard Edition (as well as preceding versions as early as JDK 1.1) -- with more practical, step-by-step coverage, new practice questions and exercises, and full coverage of the latest Java 2 enhancements. The Java" Tutorial, Third Edition offers developer-proven coverage of all the key fundamentals developers need to get results. Coverage includes the basic "nuts and bolts" of the Java language; objects and classes, including strings, threads, and I/O; user interface development with the Swing classes; the basics of networking with Java, and much more. The coverage is fully updated for v1.3, and is thoroughly cross-platform, applicable to Java on Solaris, Linux, and Win32. The accompanying CD-ROM includes, includes the latest version of Java 2 Platform, detailed API documentation for each version, and the full contents of all three Java" Tutorial books. For all beginning- to intermediate-level Java programmers.

Author Notes

Mary Campione was formerly a senior technical writer at Sun Microsystems, where she started writing about the Java platform in 1995. Mary graduated from California Polytechnic, San Luis Obispo, with a B.S. in Computer Science and has worked as both a technical writer and programmer. Kathy Walrath is a senior technical writer on the Swing team at Sun Microsystems. After graduating from the University of California, Berkeley, with a B.S. in Electrical Engineering and Computer Science, Kathy wrote extensively about Unix, Mach, and NextStep. Since 1993, Kathy has been writing specifications and how-to guides for the Java platform.

Alison Huml is a technical writer at Sun Microsystems, where she joined The Java Tutorial team in 1997 and also works with the Security team. Alison received her B.A. in English from the University of California, Berkeley, and is currently pursuing her master's degree in Computer Science at Mills College.




Since the release of the Java Development Kit in May of 1995, the engineering team at Sun Microsystems has been hard at work improving and enhancing the Java platform. We have been similarly laboring to update The Java Tutorial to reflect the work of the engineers. From the first page to the last, this edition now documents the APIs in the Java 2 SDK, Standard Edition, v 1.3. We have fully integrated SDK 1.3 updates into the text, plus we've added questions and exercises to help you practice what you learn. To help beginners avoid many common mistakes, an entire chapter is devoted to programming problems and their solutions. Convenient summaries at the end of each section are also new to this edition. Like the first and second editions, this book is based on the online tutorial hosted at Sun Microsystem's Web site for the Java platform. Like the online version, this book reflects the latest advances in Java technology. Unlike the online version, this book solely focuses on the APIs needed by most beginning to intermediate programmers. Once you've mastered the material in this book, you can explore the rest of the Java platform on the Web site. Our intent has always been to create a fun, easy-to-read, task-oriented programmer's guide with lots of practical examples to help people learn to program. Who Should Read This Book? The book is geared towards both novice and experienced programmers. New programmers can benefit most by reading the book from beginning to end, including the step by step instructions for compiling and running your first program in Getting Started (page 1). Programmers experienced with procedural languages such as C may wish start with the material on object-oriented concepts and features of the Java programming language. Experienced object programmers may want to jump feet first into more advanced trails, such as those on applets, essential classes, or user interfaces. No matter what type of programmer you are, you can find a path through this book that fits your learning requirements. How to Use This Book This book is designed so that you can either read it straight through or skip around from topic to topic. Whenever a topic is discussed in another place, you'll see a link to that place in the tutorial. Links are underlined and are followed by page numbers, like this: What Can Java Technology Do? (page 5). All the sample code used in this book is available online and on the accompanying CD. The CD icon in the margin indicates that the code is available. At the end of each chapter there is also a "Code Sample" section with a table that specifies the locations of the examples on the CD and online. We're dedicated to keeping this book up-to-date with the most current information. To learn what's new since this book went to press, visit the following URL: 0201703939P04062001 Excerpted from The Java Tutorial: A Short Course on the Basics by Mary Campione, Kathy Walrath, Alison Huml All rights reserved by the original copyright owners. Excerpts are provided for display purposes only and may not be reproduced, reprinted or distributed without the written permission of the publisher.

Table of Contents

Prefacep. ix
Chapter 1 Getting Startedp. 1
About the Java Technologyp. 2
How Will Java Technology Change My Life?p. 7
First Steps (Win32)p. 8
First Steps (UNIX/Linux)p. 16
First Steps (MacOS)p. 24
A Closer Look at Hello Worldp. 32
Questions and Exercisesp. 41
Code Samplesp. 43
Chapter 2 Object-Oriented Programming Conceptsp. 45
What Is an Object?p. 46
What Is a Message?p. 48
What Is a Class?p. 49
What Is Inheritance?p. 52
What Is an Interface?p. 54
How Do These Concepts Translate into Code?p. 55
Summaryp. 61
Questions and Exercisesp. 62
Code Samplesp. 63
Chapter 3 Language Basicsp. 65
Variablesp. 67
Operatorsp. 76
Expressions, Statements, and Blocksp. 94
Control Flow Statementsp. 99
Code Samplesp. 117
Chapter 4 Object Basics and Simple Data Objectsp. 119
The Life Cycle of an Objectp. 120
Characters and Stringsp. 132
Numbersp. 149
Arraysp. 165
Code Samplesp. 174
Chapter 5 Classes and Inheritancep. 177
Creating Classesp. 178
Managing Inheritancep. 204
Implementing Nested Classesp. 218
Code Samplesp. 224
Chapter 6 Interfaces and Packagesp. 227
Creating and Using Interfacesp. 228
Creating and Using Packagesp. 234
Code Samplesp. 242
Chapter 7 Handling Errors Using Exceptionsp. 243
What Is an Exception?p. 244
The Catch or Specify Requirementp. 245
Catching and Handling Exceptionsp. 246
Specifying the Exceptions Thrown by a Methodp. 255
How to Throw Exceptionsp. 255
Runtime Exceptions--The Controversyp. 260
Advantages of Exceptionsp. 260
Summary of Exceptionsp. 265
Questions and Exercisesp. 266
Code Samplesp. 268
Chapter 8 Threads: Doing Two or More Tasks at Oncep. 269
What Is a Thread?p. 271
Using the Timer and Timer Task Classesp. 273
Customizing a Thread's run Methodp. 277
The Life Cycle of a Threadp. 281
Understanding Thread Priorityp. 286
Synchronizing Threadsp. 291
Grouping Threadsp. 301
Summary of Threadsp. 307
Questions and Exercisesp. 309
Code Samplesp. 310
Chapter 9 I/O: Reading and Writingp. 313
Overview of I/O Streamsp. 314
Using the Streamsp. 318
Object Serializationp. 334
Working with Random Access Filesp. 340
And the Rest...p. 345
Summary of Reading and Writingp. 346
Questions and Exercisesp. 346
Code Samplesp. 348
Chapter 10 User Interfaces That Swingp. 351
Overview of the Swing APIp. 352
Your First Swing Programp. 353
Example Two: SwingApplicationp. 356
Example Three: CelsiusConverterp. 361
Example Four: LunarPhasesp. 364
Example Five: VoteDialogp. 368
Layout Managementp. 375
Threads and Swingp. 378
Visual Index to Swing Componentsp. 381
Summaryp. 387
Questions and Exercisesp. 388
Code Samplesp. 390
Appendix A Common Problems and Their Solutionsp. 391
Getting Started Problemsp. 391
General Programming Problemsp. 396
Applet Problemsp. 397
User Interface Problemsp. 399
Appendix B Internet-Ready Appletsp. 407
Overview of Appletsp. 409
AWT Componentsp. 419
Taking Advantage of the Applet APIp. 423
Practical Considerations of Writing Appletsp. 442
Finishing an Appletp. 454
Swing-Based Appletsp. 457
Code Samplesp. 463
Appendix C Collectionsp. 467
Introductionp. 468
Interfacesp. 470
Implementationsp. 508
Algorithmsp. 515
Custom Implementationsp. 520
Interoperabilityp. 523
Appendix D Deprecated Thread Methodsp. 527
Why Is Thread.stop Deprecated?p. 527
Why Are Thread.suspend and Thread.resume Deprecated?p. 530
What about Thread.destroy?p. 533
Why Is Runtime.runFinalizersOnExit Deprecated?p. 534
Appendix E Referencep. 535
Java Programming Language Keywordsp. 535
Operator Precedencep. 536
The [APPLET] Tagp. 537
POSIX Conventions for Command Line Argumentsp. 539
Integrated Development Environmentsp. 540
Path Helpp. 540
Indexp. 545