To the Instructor Java 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, and methods, then introducing object-oriented programming, and finally moving on to graphical user interface (GUI), applets, internationalization, multithreading, multimedia, I/O, and networking. 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 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 of learning object-oriented programming for freshman. 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 freshmen. 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, first 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, internationalization, multithreading, multimedia, I/O, networking, and data structures. Selection of Java Subjects Many introductory Java texts lack sufficient breadth and do not cover all the core Java knowledge that is needed to develop useful projects. Some authors over ambitiously mix too many topics, such as Java database programming, Remote Method Invocation, JavaBeans and Rapid Application Development, servlets, and JSP, into one introductory Java text. With this approach the coverage of programming principles tends to lose coherence. What is the basis for deciding that one approach is too light and the other too heavy? I believe that the best yardstick is the Level 1 Java Certification Exam (http://www.jcert.org/level1.html) initiated by a consortium of leading IT companies, including Sun Microsystems, IBM, Oracle, Hewlett-Packard, BEA Systems, and Sybase. The Level 1 Certification Exam tests core Java knowledge and fundamental programming skill. This book gives a comprehensive introduction on the fundamentals of programming in Chapters 1-5, an in-depth treatment of object-oriented programming in Chapters 6-9, extensive examples of GUI programming in Chapters 10-12, and appropriate coverage of advanced Java topics in Chapters 13-19. The book covers all the subjects required for the Level 1 Java Certification Exam. Audience of This Book The book is suited for both beginning and advanced students, depending on how it is used. It has been used in two-semester freshman programming courses and one-semester courses in Java as a second language. It has also been used in short training courses for experienced programmers. Computer science departments, engineering departments, and management information systems departments around the world have used this book at various levels. For students with no programming experience, an entire semester of four credit hours could be spent just on the first five chapters of the book, as we do for the first programming course at Armstrong Atlantic State University. Key Features of the Book - The book is aided by Sun ONE Studio (formerly known as Forte for Java) to facilitate developing and managing Java programs. Forte is introduced throughout the book rather than clustered in one or two chapters. This incremental approach makes learning Forte easy, because its new features are covered in relation to the topics in each chapter.
- The book covers all subjects required in the Level 1 Java Certification Exam. It covers fundamentals of programming (including primitive data types, control statements, methods, and arrays), object-oriented programming, GUI programming, exception handling, internalization, multithreading, multimedia, I/O, networking, and Java data structures. Students gain core Java knowledge that is needed to develop useful projects.
- The book first introduces fundamentals of programming and problem solving techniques on primitive data types, loops, methods, and arrays. This approach helps prepare students to learn object-oriented program.
- The book provides an in-depth and thorough introduction to object-oriented programming and design. Students learn the concept of classes, objects, and use them to develop useful and reusable components.
- UML graphical notations are used to describe classes and their relationships throughout the book. UML has become a standard methodology for class design. The use of UML enhances the treatment of object-oriented design and programming.
- The book is organized to provide flexible ordering of chapters so that instructors can easily customize the book. Arrays are covered in Chapter 5, but can be taught after Chapter 8. Input and Output are covered in Chapter 17, but they can be taught right after Chapter 13, "Exception Handling." Java Data Structures are explained in Chapter 19, but can be taught after Chapter 9, "Object-Oriented Software Development." See the Chapter Dependency Chart for other possible sequences.
- The comprehensive companion Web site contains many supplemental materials and an interactive self-test for each chapter at www.prenhall.com/liang/introft.html. There are over 600 questions in the self-test.
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.
- Twelve sample exams. In general, each exam has four parts: (1) multiple-choice questions or short questions; (2) correct programming errors; (3) trace programs; (4) write programs.
- Solutions to all exercises: Students will have access to the solutions of even-numbered exercises in the book's companion CD-ROM.
- Supplemental exercises and their solutions.
- Suggested syllabi for teaching Java to freshman, for teaching Java as a second language, and for teaching Java to corporate employees.
- Lecture notes. A number of suggested teaching strategies and activities are presented to help you in the delivery of the course.
To obtain the Instructor's Manual, contact your Prentice-Hall sales representative. Some students have requested for the materials such as the solutions to the odd-numbered programming exercises. Please understand these are for instructors only. Such requests will not be answered. Microsoft PowerPoint slides are also available at the book's Web site at www.prenhall.com/liang/introft.html. The Web site also contains interactive online self-tests and other supplemental materials. Pedagogical Features of the Book The philosophy of 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 out of 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 is described, and includes the source code, a sample run, and an example review. The source code of the examples is contained in the companion CD-ROM.
Each program is complete and ready to be compiled and executed. The sample run of the program is captured from the screen to give students a live presentation of the example. Reading these examples is much like entering and running them on a computer.
- 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.
- 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.
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 the last three 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 standalone 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 with 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 Palm 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 to develop software using class encapsulation and class inheritance. Applying the concept of abstraction in the design and implementation of software projects is the key to developing software. The overriding objective of this 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 projects. Students with no programming experience should take a slow-paced approach in Part I of the book. I recommend that you complete all the exercises in Part I before moving to Chapter 6. Students new to object-oriented programming may need some time to become familiar with the concept of objects and classes. Once the principles are mastered, programming in Java is easy and productive. Students who know object-oriented programming languages such as C++ and Smalltalk will find it easier to learn Java. In fact, Java is simpler than C++ and Smalltalk in many aspects. Learning Java with Sun ONE Studio 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 Sun ONE Studio (Forte), Borland JBuilder, IBM Visual Age for Java, Microsoft Visual J++, 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 Sun ONE Studio. With a tool like Sun ONE Studio, students can not only develop Java programs more productively, but can also learn Java programming more effectively. Sun ONE Studio 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 Sun ONE Studio. Programming with Sun ONE Studio is introduced throughout the book to help you gradually adapt to using it. - NOTE: Sun renamed Forte for Java to Sun ONE Studio. For convenience, this book will use Forte and Sun ONE Studio interchangeably.
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 I: 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 Forte," gives an overview of the major features of Java: object-oriented programming, platform-independence, Java bytecode, security, performance, multithreading, and networking. The chapter also introduces Forte and uses it to create, compile, and run Java programs. 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 run Java programs from the command line, and how to get online help from Forte. 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 while loop, the do-while loop, and the for loop. The keywords break and continue are discussed. You will learn how to customize Forte IDE options. 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. Various Forte commands in the File, Edit, View, Project, and Build menus are discussed. Chapter 5, "Arrays," explores an important structure: arrays for processing data in lists and tables. You will learn how to declare, initialize, and copy arrays. Examples of using two-dimensional arrays for matrix operations are provided. This chapter also introduces popular search and sorting methods. You will also learn how to use the Forte debugger. 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, class 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, StringBuffer, and StringTokenizer for storing and processing strings. There are more than 1500 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 classes on strings are fine examples to demonstrate the concept of objects and classes. Chapter 8, "Class Inheritance and Interfaces," 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 abstract, polymorphism and dynamic binding, and casting objects. This chapter introduces the object class, which is the root of all Java classes. You will also learn how to use abstract classes and interfaces. Chapter 9, "Object-Oriented Software Development," focuses on class design. You will learn how to analyze relationships among objects, and design classes with the relationships association, aggregation, composition, strong inheritance, and weak inheritance. This chapter gives the guidelines for class design with several examples. The wrapper classes for primitive data types are introduced to encapsulate primitive data type values as objects. 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 graphics 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 10, "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 (F1owLayout, GridLayout, and BorderLayout). The chapter introduces drawing geometric figures in the graphics context. The concept and techniques for Java event-driven programming are presented. Chapter 11, "Creating User Interfaces," introduces the user interface components: buttons, labels, text fields, text areas, combo boxes, lists, check boxes, radio buttons, menus, scrollbars, and scroll 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 12, "Applets and Advanced GUI," 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. The chapter also introduces two advanced layout mangers (CardLayout and GridBagLayout) and the use of no layout. Advanced examples of handling mouse and keyboard events are provided. 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 to make your program robust, using multithreading to make your program more responsive and interactive, incorporating sound and images to make your program user-friendly, using input and output to manage and process a large quantity of data, creating client/server applications with Java networking support, and using the classes in the Java Collections Framework to build data structures in Java. Chapter 13, "Exception Handling," 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. Chapter 14, "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 15, "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 16, "Multimedia," teaches how to incorporate sound and images to bring live animation to Java applets and applications. Various techniques for smoothing animation are introduced. Chapter 17, "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 18, "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 19, "Java Data Structures," introduces the Java Collections Framework. Students will learn to use classes and interfaces such as collection, Set, Hashset, TreeSet, Iterator, List, ArrayList, LinkedList, Vector, Stack, Map, HashMap, TreeMap, Collections, and Arrays to build projects. |