To the Instructor Teaching Strategies There are three popular strategies in teaching Java. The first, known as GUI-first, is to mix Java applets and GUI programming with object-oriented programming concepts. The second, known as object-first, is to introduce object-oriented programming from the start. The third strategy, known as fundamentals-first, is a step-by-step approach, first laying a sound foundation on programming concepts, control statements, methods, and arrays, then introducing object-oriented programming, and then moving on to graphical user interface (GUI), applets, and finally to exception handling, I/O, data structures, multithreading, and multimedia. The GUI-first strategy, starting with GUI and applets, seems attractive, but requires substantial knowledge of object-oriented programming and a good understanding of the Java event-handling model; thus, students may never fully understand what they are doing. The object-first strategy is based on the notion that objects should be introduced first because Java is an object-oriented programming language. This notion, however, overlooks the importance of the fundamental techniques required for writing programs in any programming language. Furthermore, this approach inevitably mixes static and instance variables and methods before students can fully understand classes and objects and use them to develop useful programs. Students are overwhelmed by object-oriented programming and basic rules of programming simultaneously in the early stage of learning Java. This is a common source of frustration for first year students learning object-oriented programming. From my own experience, confirmed by the experiences of many colleagues, I have found that learning basic logic and fundamental programming techniques like loops is a struggle for most first year students. Students who cannot write code in procedural programming are not able to learn object-oriented programming. A good introduction on primitive data types, control statements, methods, and arrays prepares students to learn object-oriented programming. Therefore, this text adopts the fundamentals-first strategy, proceeding at a steady pace through all the necessary and important basic concepts, then moving to object-oriented programming, and then to using the object-oriented approach to build interesting GUI applications and applets with exception handling, I/O, data structures, multithreading, and multimedia as shown in the following diagram. The fundamentals-first approach can reinforce object-oriented programming by demonstrating how procedural solutions can be improved using the object-oriented approach. Students can learn when and how to apply OOP effectively. This book is not simply about how to program, for it teaches, as well, how to solve problems using programs. Applying the concept of abstraction in the design and implementation of software projects is the key to developing software. The overriding objective of the book, therefore, is to teach students to use many levels of abstraction in solving problems and to see problems in small and in large. The examples and exercises throughout the book foster the concept of developing reusable components and using them to create practical projects. Instructor Resources The Instructor's Manual on CD-ROM is available for instructors using this book. It contains the following resources: - Microsoft PowerPoint slides for lectures, with interactive buttons to view syntax-highlighted source code and to run programs without leaving the slides.
- Ten sample exams. In general, each exam has four parts: (I) multiple-choice questions or short answers (most of these are different from the ones in the Self-Test on the Web site); (2) correct programming errors; (3) trace programs; (4) write programs.
- Solutions to all the exercises. Students will have access to the solutions of even-numbered exercises in the book's companion CD-ROM.
- More than forty supplemental exercises and their solutions.
- Suggested syllabi for teaching Java to beginning students, for teaching Java as a second language, and for teaching Java to corporate employees.
To obtain the Instructor's Manual, contact your Prentice-Hall sales representative. Some students have requested the solutions to the odd-numbered programming exercises. Please understand that these are for instructors only. Such requests will not be answered. Microsoft PowerPoint slides are also available at the book's companion Web site at http://www.prenhall.com/liang/. The Web site also contains interactive online self-tests and other supplemental materials. Lab Manual The lab manual for the book was developed by Pete Dobbins of the University of Florida. To bundle it with the book, contact your Prentice-Hall sales representative. Pedagogical Features of the Book The philosophy of the Liang Java Series is teaching by example and learning by doing. Basic features are explained by example so that you can learn by doing. 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 to determine whether they have met the objectives after completing the chapter.
- Introduction opens the discussion with a brief overview of what to expect from the chapter.
- Programming concepts are taught by representative Examples, carefully chosen and presented in an easy-to-follow style. Each example has the problem statement, solution steps, complete source code, sample run, and review. The source code of the examples is contained in the companion CD-ROM.
- Chapter Summary reviews the important subjects that students should understand and remember. It helps them to reinforce the key concepts they have learned in the chapter.
- Review Questions help students to track their progress and evaluate their learning.
- Programming Exercises at the end of each chapter provide students with opportunities to apply the skills on their own. The trick of learning programming is practice, practice, and practice. To that end, the book provides a large number of exercises.
- Interactive Self-Test helps students to test their knowledge interactively online. The Self-Test is accessible from the book's companion Web site at http://www.prenhall.com/liang/. It provides more than six hundred multiple-choice and true/false questions organized by chapters.
- 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.
What's New in This Edition This book improves upon Introduction to Java Programming with JBuilder 4/5/6/7, Second Edition. The major changes are as follows: - The book is updated to JDK 1.4 and JBuilder 8/9. JBuilder 8/9 uses JDK 1.4.
- The new edition tightly integrates JBuilder with Java to exploit many advantages of learning Java with JBuilder. JBuilder is not only an excellent tool for developing Java programs but also helps in learning Java effectively.
- Debugging is introduced early in Chapter 2 and integrated in several chapters so that students can trace the execution of their programs to find logic errors.
- The proprietary MyInput class for getting input from the console is replaced by the standard JOptionPane class. Students don't have to learn the proprietary Mynput class that is not used in the workplace.
- Every chapter is thoroughly revised and improved in terms of content, presentation, examples, and exercises. Twenty percent of the examples and exercises were replaced by new practical applications, such as computing loan payments, taxes, and printing payroll statements.
- Chapter 8, "Class Inheritance and Interfaces," in the second edition has been reorganized into two chapters in this third edition: Chapter 8, "Inheritance and Polymorphism," and Chapter 9, "Abstract Classes and Inheritance." New organization improves the presentation of object-oriented programming.
- Chapter 10 in the second edition has been split into two chapters in this edition: Chapter 11, "Getting Started with GUI Programming," and Chapter 12, "Event-Driven Programming." This change enables Chapter 11 to be covered earlier.
- The new Part V for bonus chapters covers the advanced Java features used in upper-level courses. This part is on CD-ROM only so that the main text is focused on the core subjects. Internationalization and networking have been moved to this part. Three new chapters on database programming, servlets, and JSP were also included in this part.
- Optional materials, such as overview of computer systems, number systems, coding style guidelines, packages, HTML, event adapters, and rapid Java application development, are moved to the supplements. The supplements are contained in the CD-ROM only, so that the book is focused on the core subjects.
To the Student There is nothing more important to the future of computing than the Internet. There is nothing more exciting on the Internet than Java. A revolutionary programming language developed by Sun Microsystems, Java has become the de facto standard for cross-platform applications and programming on the World Wide Web. Java is a full-featured, general-purpose programming language that is capable of developing robust mission-critical applications. In recent years, Java has gained enormous popularity and has quickly become the most popular and successful programming language. Today, it is used not only for Web programming, but also for developing stand-alone applications across platforms on servers, desktops, and mobile devices. Many companies that once considered Java to be more hype than substance are now using it to create distributed applications accessed by customers and partners across the Internet. For every new project being developed today, companies are asking how they can use Java to make their work easier. Java is now taught in every university. This book teaches you how to write Java programs from the beginning. Java's Design and Advantages - Java is an object-oriented programming language. Object-oriented programming is a favored programming approach that has replaced traditional procedure-based programming techniques. An object-oriented language uses abstraction, encapsulation, inheritance, and polymorphism to provide great flexibility, modularity, and reusability for developing software.
- Java is platform-independent. Its programs can run on any platform with a Java Virtual Machine, a software component that interprets Java instructions and carries out associated actions.
- Java is distributed. Networking is inherently built-in. Simultaneous processing can occur on multiple computers on the Internet. Writing network programs is treated as simple data input and output.
- Java is multithreaded. Multithreading is the capability of a program to perform several tasks simultaneously, such as downloading a video file while playing the video at the same time. Multithreading is particularly useful in graphical user interfaces (GUI) and network programming. Multithread programming is smoothly integrated in Java. In other languages, you can only enable multithreading by calling procedures that are specific to the operating system.
- Java is secure. Computers become vulnerable when they are connected to other computers. Viruses and malicious programs can damage your computer. Java is designed with multiple layers of security that ensure proper access to private data and restrict access to disk files.
Java's Versatility Stimulated by the promise of writing programs once and running them anywhere, Java has become the most ubiquitous programming language. Java programs run on full-featured computers, and also on consumer electronics and appliances, such as personal digital assistants and mobile phones. Because of its great potential to unite existing legacy applications written on different platforms so that they can run together, Java is perceived as a universal front-end for the enterprise database. The leading database companies; IBM, Oracle, and Sybase, have extended their commitment to Java by integrating it into their products. Oracle, for example, enables Java applications to run on its server and to deliver a complete set of Java-based development tools supporting the integration of current applications with the Web. Learning Java To first-time programmers, learning Java is like learning any high-level programming language. The fundamental point in learning programming is to develop the critical skills of formulating programmatic solutions for real problems and translating the solutions into programs using selection statements, loops, and methods. Once you acquire the basic skills of writing programs using loops, methods, and arrays, you can start to learn object-oriented programming. You will learn how to develop object-oriented software using class encapsulation and class inheritance. Once you understand the concept of object-oriented programming, learning Java becomes a matter of learning the Java API. The Java API establishes a framework for programmers to develop applications using Java. You have to use these classes and interfaces in the API and follow their conventions and rules to create applications. The best way to learn Java API is to imitate examples and do exercises. Learning lava with Builder You can use Java 2 SDK to write Java programs. Java 2 SDK (formerly known as JDK) consists of a set of separate programs, such as compiler and interpreter, each of which is invoked from a command line. Besides Java 2 SDK, there are more than a dozen Java development tools on the market today, including Borland JBuilder, Sun ONE Studio, IBM Visual Age for Java, and WebGain Visual Cafe. These tools support an integrated development environment (IDE) for rapidly developing Java programs. Editing, compiling, building, debugging, and online help are integrated in one graphical user interface. Using these tools effectively will greatly increase your programming productivity. The overriding objective of this book is to introduce the concepts and practice of Java programming. To facilitate developing and managing Java programs, the book is aided by JBuilder. With a tool like JBuilder, students can not only develop Java programs more productively, but can also learn Java programming more effectively. JBuilder is a premier Java development tool for developing Java programs produced by Borland. Borland products are known to be "best of breed" in the IDE tool market. Over the years, Borland has led the charge in creating visual development tools like Delphi and C++ Builder. Borland is now leading the way in Java development tools with JBuilder. JBuilder is endorsed by major information technology companies like Oracle, which licensed JBuilder 2. JBuilder is easy to learn and easy to use. The JBuilder development team worked hard to simplify the user interface and make it easy to navigate through the programs, projects, classes, packages, and code elements. As a result, JBuilder has fewer windows than other Java IDE tools. This makes JBuilder an ideal tool for beginners and for students who have little programming experience. JBuilder is an indispensable, powerful tool that boosts your programming productivity. It may take a while to become familiar with it, but the time you invest will pay off in the long run. This text takes an incremental approach to facilitate learning JBuilder. Programming with JBuilder is introduced throughout the book to help you gradually adapt to using it. - IMPORTANT NOTE: Students should strictly follow the advice of their instructors or this book to create projects and classes consistently. Not creating projects and classes correctly is a common error that discourages people from using JBuilder.
Organization of the Book This book is divided into four parts that, taken together, form a comprehensive introductory course on Java programming. Because knowledge is cumulative, the early chapters provide the conceptual basis for understanding Java and guide students through simple examples and exercises; subsequent chapters progressively present Java programming in detail, culminating with the development of comprehensive Java applications. The appendixes contain a mixed bag of topics, including an HTML tutorial. Part 1: Fundamentals of Programming The first part of the book is a stepping stone that will prepare you to embark on the journey of learning Java. You will begin to know Java, and will learn how to write simple Java programs with primitive data types, control statements, methods, and arrays. Chapter 1, "Introduction to Java and JBuilder," gives an overview of the major features of Java: object-oriented programming, platform-independence, Java byte-code, security, performance, multithreading, and networking. The chapter introduces JBuilder and uses it to create, compile, and run Java programs. Simple examples of writing applications are provided, along with a brief anatomy of programming structures. Chapter 2, "Primitive Data Types and Operations," introduces primitive data types, operators, and expressions. Important topics include identifiers, variables, constants, assignment statements, assignment expressions, primitive data types, operators, and shortcut operators. Java programming style and documentation are also addressed. You will learn how to get input from an input dialog box, and how to convert a string into numeric values. You will learn how to use the JBuilder debugger. You will also learn how to run Java programs from the command line, and how to get online help from JBuilder. Chapter 3, "Control Statements," introduces decision and repetition statements. Java decision statements include various forms of if statements and the switch statement. Java repetition statements include the white loop, the do-while loop, and the for loop. The keywords break and continue are discussed. Chapter 4, "Methods," introduces method creation, calling methods, passing parameters, returning values, method overloading, scope of local variables, and recursion. Applying the concept of abstraction is the key to developing software. The chapter also introduces the use of method abstraction in problem-solving. The math class for performing basic math operations is introduced. Chapter 5, "Arrays," explores an important structure: arrays for storing a collection of data. You will learn how to declare, initialize, and copy arrays. This chapter also introduces selection sort, linear search, and binary search methods. Part II: Object-Oriented Programming In the book's second part, object-oriented programming is introduced. Java is a class-centric, 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, encapsulation, inheritance, interfaces, polymorphism, and developing software using the object-oriented approach. Chapter 6, "Objects and Classes," begins with objects and classes. The important topics include defining classes, creating objects, using constructors, passing objects to methods, instance and class variables, and instance and class methods, scope of variables in the context of a class, the keyword this, and using the UML graphical notations to describe classes. Several examples are provided to demonstrate the power of the object-oriented programming approach. Students will learn the benefits (abstraction, encapsulation, and modularity) of object-oriented programming from these examples. Chapter 7, "Strings," introduces the classes string, stringsuffer, and stringTokenizer for storing and processing strings. There are more than fifteen hundred predefined Java classes grouped in several packages. Starting with this chapter, students will gradually learn how to use Java classes to develop their own programs. The discussions on strings are fine examples to demonstrate the concept of objects and classes. Chapter 8, "Inheritance and Polymorphism," teaches how an existing class can be extended and modified as needed. Inheritance is an extremely powerful programming technique, further extending software reusability. Java programs are all built by extending predefined Java classes. The major topics include defining subclasses, using the keyword super, using the modifiers protected, final, and the object class. Chapter 9, "Abstract Classes and Interfaces," introduces abstract classes and interfaces, and explores polymorphism and dynamic binding, generic programming, and casting objects. The wrapper classes for primitive data types are also introduced to encapsulate primitive data type values as objects. Chapter 10, "Object-Oriented Modeling," focuses on class modeling and design. You will learn how to analyze relationships among objects and to design classes with the relationships association, aggregation, composition, strong inheritance, and weak inheritance. This chapter gives the guidelines for class design with several examples. Finally, two examples of designing generic classes for matrix operations and linked lists are introduced. Part III: GUI Programming The third part of the book introduces Java GUI programming. Major topics include event-driven programming, creating graphical user interfaces, and writing applets. You will learn the architecture of Java GUI programming API and use the user interface components to develop GUI applications and applets. Chapter 11, "Getting Started with GUI Programming," introduces the concepts of Java GUI programming using Swing components. Topics include the Swing class hierarchy, frames, panels, and simple layout managers (Flomayout, GridLayout, and BorderLayout). The chapter introduces drawing geometric figures in the graphics context. Chapter 12, "Event-Driven Programming," introduces the concepts and techniques for Java event-driven programming. You will learn the Java event model, create listener classes, register listener objects with the source object, and process events in the listener's handlers. Chapter 13, "Creating User Interfaces," introduces the user interface components: buttons, labels, text fields, text areas, combo boxes, lists, check boxes, radio buttons, menus, scrollbars, scroll panes, and tabbed panes. Today's client/server and Web-based applications use a graphical user interface. Java has a rich set of classes to help you build GUIs. Chapter 14, "Applets," takes an in-depth look at applets, discussing applet behavior and the relationship between applets and other Swing classes. Applets are a special kind of Java class that can be executed from the Web browser. Students will learn how to convert applications to applets, and vice versa, and how to run programs both as applications and as applets. You will also learn now to create applets using the JBuilder Applet wizard. Part IV: Developing Comprehensive Projects The book's final part is devoted to several advanced features of Java programming. You will learn how to use these features to develop comprehensive programs; for example, using exception handling and assertions to make your program robust and correct, using input and output to manage and process a large quantity of data, using the classes in the Java Collections Framework to build data structures in Java, using multithreading to make your program more responsive and interactive, and incorporating sound and images to make your program user-friendly. Chapter 15, "Exceptions and Assertions," teaches students how to define exceptions, throw exceptions, and handle exceptions so that their programs can either continue to run or terminate gracefully in the event of runtime errors. The chapter discusses predefined exception classes, and gives examples of creating user-defined exception classes. The chapter also introduces using assertions to help ensure program correctness. Chapter 16, "Input and Output," introduces input and output streams. Students will learn the class structures of I/O streams, byte and character streams, file I/O streams, data I/O streams, print streams, object streams, random file access, delimited I/O, and interactive I/O. Chapter 17 "Java Data Structures," introduces the Java Collections Framework. Students will learn how to use classes and interfaces such as collection, set, Hashset, LinkedHashSet, Treeset, Iterator, List, ArrayList, LinkedList, Vector, Stack, Map, HashMap, LinkedHashMap, TreeMap, Collections, and Arrays to build projects. Chapter 18, "Multithreading," introduces threads, which enable the running of multiple tasks simultaneously in one program. Students will learn how to use the Thread class and the Runnable interface to launch separate threads. The chapter also discusses thread states, thread priority, thread groups, and the synchronization of conflicting threads. Chapter 19, "Multimedia," teaches how to incorporate sound and images to bring live animation to Java applets and applications. Various techniques for smoothing animation are introduced. Part V: Bonus Chapters (On the Companion CD-ROM only) This part contains bonus chapters on internationalization, networking, database programming, servlets, and JavaSetver pages. These topics are usually not covered in introductory courses, but they are valuable for upper-level courses. This part is on the CD-ROM only, so that the main text is focused on the introductory Java subjects. Chapter 20, "Internationalization," introduces the development of Java programs for international audiences. You will learn how to format dates, numbers, currencies, and percentages for different regions, countries, and languages. You will also learn how to use resource bundles to define which images and strings are used by a component depending on the user's locale and preferences. Chapter 21, "Networking," introduces network programming. Students will learn the concept of network communication, stream sockets, client/server programming, and reading data files from the Web server. Chapter 22, "Database Programming," begins with an overview of the database systems, and an introduction to relational database structures, integrity constraints, and the SQL language. You will learn how to use Java to develop database projects. Chapter 23 "Servlets," introduces the technique of creating dynamic HTML contents using Java servlets. You will learn how to write serverside Java programs to access databases. You will also learn the techniques for session tracking and processing images. Chapter 24, "JavaServer Pages," introduces the technique of creating JavaServer pages for Web-based database applications. You will learn JSP constructs, predefined variables, and directives. You will learn how to use JavaBeans in JSP. Appendixes This part of the book covers a mixed bag of topics. Appendix A lists Java keywords. Appendix B gives tables of ASCII characters and their associated codes in decimal and in hex. Appendix C shows the operator precedence. Appendix D summarizes Java modifiers and their usage. Appendix E lists UML Graphical Notations for describing classes and their relationships. Appendix F discusses special floating-point values. Finally, Appendix G provides a glossary of key terms used in the text. Supplements (on the companion CD-ROM) The text covers the core subjects. The supplements extend the text to cover additional topics that might be of interest to readers. The supplements are not included in the text but are provided on the companion CD-ROM. Supplement A gives an overview of computer systems. Supplement B introduces number systems and conversions among binary, decimal, and hex numbers. Bitwise operations are also introduced. Supplement C summarizes Java coding style and guidelines. Supplement D introduces how to configure your computer so that you can compile and run Java from the command window. Supplement E introduces package-naming conventions, creating packages, and using packages. Supplement F gives an HTML tutorial. Supplement G introduces CardLayout, GridBagLayout, and Null Layout. Supplement H discusses Java archive, packaging, and deploying Java projects. Supplement I introduces standard event adapters and anonymous event adapters. Supplement J covers network programming using datagrams. Supplement K demonstrates how to use the JBuilder Application wizard. Finally, Supplement L shows how to use the JBuilder UI designer to create UI. |