前言

This book uses the fundamentals-first approach and teaches programming concepts and tech- niques in a problem-driven way.
The fundamentals-first approach introduces basic programming concepts and techniques before objects and classes. My own experience, confirmed by the experiences of many colleagues, demonstrates that new programmers in order to succeed must learn basic logic and fundamental programming techniques such as loops and stepwise refinement. The fundamentai concepts and techniques of loops, methods, and arrays are the foundation for programming. Building the foundation prepares students to learn object-oriented programming, GUI, database, and Web programming.
Problem-driven means focused on problem solving rather than syntax. We make introductory programming interesting by using interesting problems. The central thread of early chapters is on problem solving. Appropriate syntax and library are introduced to support the writing of a program for solving the problems. To support the teaching of programming in a problemdriven way, the book provides a wide variety of problems at various levels of difficulty to motivate students. In order to appeal to students in all majors, the problems cover many application areas in math, science, business, financials, gaming, animation, and multimedia.
Two Versions
This comprehensive version covers fundamentals of programming, object-oriented programming, GUI programming, algorithms and data structures, concurrency, networking, internationalization, advanced GUI, database, and Web programming. It is designed to prepare students to become proficient Java progranuners. A brief version (Introduction to Java Programming, Brief Version, Eighth Edition) is available for a first course on programming, commonly known as CS1. The brief version contains the first 20 chapters of the comprehensive version.
What's New in This Edition?
This edition substantially improves Introduction to Java Programming, Seventh Edition. The major improvements are as follows:
This edition is completely revised in every detail to enhance clarity, presentation, content, examples, and exercises.
In the examples and exercises, which are provided to motivate and stimulate student inter est in programming, one-fifth of the problems are new.
In the previous edition, console input was covered at the end of Chapter 2. The new edition introduces console input early in Chapter 2 so that students can write interactive programs early.
The hand trace box is added for many programs to help novice students to read and trace programs.
Single-dimensional arrays and multidimensional arrays are covered in two chapters to give instructors the flexibility to cover multidimensional arrays later.
The case study for the Sudokn problem has been moved to the Companion Website. A more pedagogically effective simple version of the Sudoku problem is presented instead.
The design of the API for Java GUI programming is an excellent example of how the object-oriented principle is applied. Students learn better with concrete and visual examples.
So, basic GUI now precedes the introduction of abstract classes and interfaces. The instructor, however, can still choose to cover abstract classes and interfaces before GUI.
Exception handling is covered before abstract classes and interfaces so that students can build robust programs early. The instructor can still choose to cover exception handling later.
Chapter 12, "Object-Oriented Design and Patterns;' in the previous edition has been replaced by spreading the design guidelines and patterns into several chapters so that these topics can be covered in appropriate context.
The chapter on sorting now follows right after the chapter on algorithm efficiency, so that students can immediately apply algorithm efficiency to sorting algorithms.
A brand-new bonus Chapter 44 covers Java 2D.
The coverage on data structures is expanded with new bonus chapters on AVL trees, splay trees, 2-4 trees, B-trees, and red-black trees, and hashing. So the book can be used for a full data structures course.

. Learning Strategies
A programming course is quite different from other courses. In a programming course, you learn from examples, from practice, and from mistakes. You need to devote a lot of time to writing programs, testing them, and fixing errors.
For first-time programmers, learning Java is like learning any high-level programming language. The fundamental point is to develop the critical skills of formulating programmatic solutions for real problems and translating them into programs using selection statements, loops, methods, and arrays.
nce you acquire the basic skills of writing programs using loops, methods, and arrays, you can begin to learn how to develop large programs and GUI programs using the objectoriented approach.
When you know how to program and you understand the concept of object-oriented programming, learning Java becomes a matter of learning the Java APL The Java API establishes a framework for programmers to develop applications using Java. You have to use the classes and interfaces in the AH and follow their conventions and rules to create applications. The best way to learn the Java API is to imitate examples and do exercises.
Pedagogical Features
The book uses the following elements to get the most from the material:
Objectives list what students should have learned from the chapter. This will help them determine whether they have met the objectives after completing the chapter.
Introduction opens the discussion with representative problems to give the reader an overview of what to expect from the chapter.
Problems carefully chosen and presented in an easy-to-follow style, teach problem solving and programming concepts. The book uses many small, simple, and stimulating examples to demonstrate important ideas.
Chapter Summary reviews the important subjects that students should understand and remember. It helps them reinforce the key concepts they have learned in the chapter.
Review Questions are grouped by sections to help students track their progress and evaluate their learning.
Programming Exercises are grouped by sections to provide students with opportunities to apply on their own the new skills they have learned. The level of difficulty is rated as easy (no asterisk), moderate (*), hard (**), or challenging (***). The trick of learning programming is practice, practice, and practice. To that end, the book provides a great many exercises.
LlveImb is a course assessment and management system. Students can submit programs online. The system automatically grades the programs/multiple-choice quizzes and gives students instant feedback. Instructors can create custom programming exercises and quizzes as well as use the system prebuilt exercises and quizzes.
Notes, Tips, and Cautions are inserted throughout the text to offer valuable advice and insight on important aspects of program development.
Note
Provides additional information on the subject and reinforces important concepts.
Tip
Teaches good programming style and practice.
Caution
Helps students steer away from the pitfalls of programming errors.
Design Guide
Provides the guidelines for designing programs.
Flexible Chapter Orderings
The book is designed to provide flexible chapter orderings to enable GUI, exception handling, recursion, generics, and the Java Collections Framework to be covered earlier or later. The diagram on the next page shows the chapter dependencies.
Organization of the Book
The chapters can be grouped into five parts that, taken together, form a comprehensive introduction to Java programming, data structures and algorithms, and database and Web programming. Because knowledge is cumulative, the early chapters provide the conceptual basis for understanding programming and guide students through simple examples and exercises; subsequent chapters progressively present Java programming in detail, culminating with the development of comprehensive Java applications.
Part I: Fundamentals of Programming (Chapters 1-7)
The first part of the book is a stepping stone, preparing you to embark on the journey of learning Java. You will begin to know Java (Chapter 1) and will learn fundamental programming techniques with primitive data types, variables, constants, assignments, expressions, and operators (Chapter 2), control statements (Chapters 3-4), methods (Chapter 5), and arrays (Chapters 6-7). After Chapter 6, you may jump to Chapter 20 to learn how to write recursive methods for solving inherently recursive problems.
Part II: Object-Oriented Programming (Chapters 8-11, 13-14, 19)
This part introduces object-oriented programming. Java is an object-oriented programming language that uses abstraction, encapsulation, inheritance, and polymorphism to provide great flexibility, modularity, and reusability in developing software. You will learn programming with objects and classes (Chapters 8-10), class inheritance (Chapter 11), polymorphism (Chapter 11), exception handling (Chapter 13), abstract classes (Chapter 14), and interfaces (Chapter 14). Processing strings will be introduced in Chapter 9 along with text I/O. Binary I/O is introduced in Chapter 19.
Part HI: GUI Programming (Chapters 12, 15-18, 32-36, and 44)
This part introduces elementary Java GUI programming in Chapters 12 and 15-18 and advanced Java GUI programming in Chapters 32-36 and 44. Major topics include GUI basics (Chapter 12),drawing shapes (Chapter 15), event-driven programming (Chapter 16), creating graphical user interfaces (Chapter 17), and writing applets (Chapter 18). You will learn the architecture of Java GUI programming and use the GUI components to develop applications and applets from these elementary GUI chapters. The advanced GUI chapters introduce Java GUI programming in more depth and breadth. You will delve into JavaBeans and learn how to develop custom events and source components in Chapter 32, review and explore new containers, layout managers, and borders in Chapter 33, learn how to create GUI with menus, popup menus, toolbars, dialogs, and internal frames in Chapter 34, develop components using the MVC approach and explore the advanced Swing components JSpinner, JList, JComboBox, 3Spinner, and JTable, and 3Tree in Chapters 35 and 36. Bonus Chapter 44 introduces Java 2D.
Part IV: Algorithms and Data Structures (Chapters 20-28, 45-48)
This part introduces the main subjects in a typical data structures course. Chapter 20 introduces recursion to write methods for solving inherently recursive problems. Chapter 21 introduces generics to improve software reliability. Chapter 22 introduces the Java Collection Framework, which defines a set of useful AH for data structures. Chapter 23 introduces measurement of algorithm efficiency in order to choose an appropriate algorithm for applications. Chapter 24 introduces classic sorting algorithms. You will learn how to implement several classic data structures lists, queues, priority queues, binary search trees, AVL trees, splay trees, 2-4 trees, B-trees, and red-black trees in Chapters 25-26 and 45-47. Chapters 27 and 28 introduce graph applications. Chapter 48 introduces hashing.
Part V: Advanced Java Programming (Chapters 29-31, 37-43)
This part of the book is devoted to advanced Java programming. Chapter 29 treats the use of multithreading to make programs more responsive and interactive. Chapter 30 introduces how to write programs that talk with each other from different hosts over the Internet. Chapter 31 covers the use of internationalization support to develop projects for international audiences. Chapter 37 introduces the use of Java to develop database projects, Chapter 38 introduces advanced Java database programming, and Chapters 39 and 40 introduce how to use Java servlets and JSP to generate dynamic contents from Web servers. Chapter 41 introduces rapid Web application development using JavaServer Faces. Chapter 42 introduces Web services. Chapter 43 introduces remote method invocation.
Java Development Tools
You can use a text editor, such as the Windows Notepad or WordPad, to create Java programs and to compile and run the programs from the command window. You can also use a Java development tool, such as TextPad, NetBeans, or Eclipse. These tools support an integrated development environment (IDE) for rapidly developing Java programs. Editing, compiling, building, executing, and debugging programs are integrated in one graphical user interface. Using these tools effectively can greatly increase your programming productivity. TextPad is a primitive IDE tool. NetBeans and Eclipse are more sophisticated, but they are easy to use if you follow the tutorials. Tutorials on TextPad, NetBeans and Eclipse can be found in the sup- plements on the Companion Website.