Java 程序设计

出版时间:2010-1  出版社:清华大学出版社  作者:潘祥春  页数:291  
Tag标签:无  

前言

  Who Should Read This Book  This book teaches Java programming with a focus on object-oriented programming using the Java programming language. Designed for readers with no prior knowledge in computer programming, this book is unassuming and is most suitable for teaching Java at the undergraduate level. Complete source code is provided in every example and where applicable, screen-shots are used to as an added help for readers in their practical exercises.  Topic Covered in This Book  Topics covered include: the Java programming environment; the Java language components which include variables; data structures; data types and their declaration; expressions, statements, and operators; program flow control mechanisms; arrays; methods; inputs and outputs; class and objects; file handling; single class inheritance; encapsulation; polymorphism; abstract class, abstract method, inner class, method overriding, multiple class inheritance and interface. This book also covers the Java Application Programming Interface (API)-a rich Java class library.  How This Book Is Organized  This book is organized into fourteen chapters with each chapter building on what have been covered in the previous chapters. Each chapter is designed workshops and exercises. Workshops are practices with complete solutions provided while exercises are intended for readers to try out writing object-oriented programs in Java on their own.  Chapter 1: The Java Programming Environment  This chapter prepares the readers for Java programming with instructions on how to set up the Java programming environment.  Chapter 2: The Java Language Components  This chapter defines the vocabulary of the Java language and explains how the words and symbols can be put together to form the basic program structure in Java.  Chapter 3: Expressions and Statements  Preface Java Programming This chapter explains the structure of a Java expression and how it can be used in conjunction with a semi-colon to form statements, the basic executable component of Java.  Chapter 4: Program Flow Controls  This chapter explains how to add program flow control mechanisms in a Java program. Statements can be put together and executed sequentially using the Sequence construct, selectively using the Selection construct, and repetitively using the Iteration construct.  Chapter 5: Arrays  This chapter explains the concept of an array as a data structure for storing and manipulating data of the same type as a collection. Details on how to manipulate a one-dimensional and two-dimensional array are included in this chapter.  Chapter 6: Methods  This chapter explains how a Java program can be more structured with the use of method-a collection of data and statements for performing a task.  Chapter 7: Class and Objects  Java is an object-oriented programming language. This chapter explains the concept of class and object and how to write Java programs using the object-oriented programming paradigm.

内容概要

  This book teaches the fundamentals of Java and object-oriented programmingusing the programming language Java. Designed for readers with no priorknowledge in computer programming, this book is unassuming and is most suitablefor teaching Java and object-oriented programming in a progressive manner. It is abook crafted with the novice in mind. Complete source code is provided in everyexample. Where applicable, screen-shots showing the development of applicationprograms are included to help readers in their practices. If you have no knowledgein writing computer programs and would like a book to guide you in theprogramming process, then this book is right for you!  Topics covered include: the Java programming environment; the Javalanguage components which include variables; data structures; data types and theirdeclaration; expressions, statements, and operators; program flow controlmechanisms; arrays; methods; inputs and outputs; file handling; object-orientedprogramming concepts such as inheritance encapsulation, and polymorphism;interface; and sort, search and recursion techniques. The book also covers the JavaApplication Programming Interface (API) - a rich Java class library.

作者简介

  Dr. Danny Poo graduated with a BSc (Hons), MSc and PhDin Computer Science from the University of Manchester Institute ofScience and Technology (UMIST), England. He is currently atenured Associate Professor in Me Department of Information Sys-tems, National University of Singapore. He has taught courses inSystems Analysis and Design, Enterprise Systems Development,Object-Oriented Software Engineering, and Information TechnologyProject Management. He is a Steering Committee Member of the Asia-Pacific Soft-ware Engineering Conference and founder and director of CicadaCube Pte Ltd, an NUS spin-off company specializing in Enterprise-level Search and RetrievalSolutions. A well-known speaker in seminars, he has conducted numerous in-house trainingand consultancy for organizations both locally and regionally. Dr. Poo is the author of 5 books: " Object-Oriented Programming andJava", 2nd edition, Springer-Verlag, 2007; "Developing Systems Using J2EE ",PrenticeHall, 2004, "Learn To Program Java", 4th edition, Cengage Learning, 2009 ;"Learn To Program Java User Interface", Thomson Learning, 2006 ; and "Learn ToProgram Enterprise JavaBeans 3.0", 3rd edition, Cengage Learning, 2009.

书籍目录

CHAPTER 1 The Java Programming Environment1.1 History of Java21.2 Preparing to Write Java Programs21.3 A Simple Java Program31.4 How to Run a Java Program?41.5 Commonly Encountered Problems5Workshops5Workshop 1.1: Preparing the Environment for Java Programming5Workshop 1.2: How to Run a Java Program?10Workshop 1.3: How to Compile and Run a Java Program in DOS Prompt?12Exercises13CHAPTER 2 The Java Language Components2.1 Print2Numbers Java Program172.2 The Java Vocabulary and Character Sets192.3 Primitive Data Types192.3.1 Boolean202.3.2 Characters202.3.3 Integers212.3.4 Floating Point222.3.5 Object References222.3.6 String222.4 Identifiers222.5 Reserved Words232.6 Comments242.7 Basic Program Structure25Workshops26Workshop 2.1: Understanding the Sequence of Program Execution26Exercises28CHAPTER 3 Expressions, Statements and Operators3.1 Expression Statements313.1.1 Types of Expressions313.1.2 Assignment Expression Statements313.1.3 Prefix or Postfix Forms of "++" and "——" Statements323.1.4 Method Call Statements323.1.5 Object Creation Statements323.2 Declaration Statements333.3 Operators333.3.1 Arithmetic Operators343.3.2 Auto-Increment and Auto-Decrement Operators353.3.3 Logical Operators353.3.4 Relational Operators373.3.5 Bitwise Operators393.3.6 The Conditional Operator "?:" 403.3.7 Assignment Operators413.3.8 "+" Operator433.3.9 "." Operator443.3.10 Precedence and Associativity44Workshops47Workshop 3.1: Entering Data for Program Execution47Exercises53CHAPTER 4 Program Flow Controls4.1 Sequence564.2 Selection574.2.1 Block574.2.2 Types of Selection Statements594.3 Iteration644.3.1 The while Statement644.3.2 The do-while Statement664.3.3 The for Statement674.3.4 The Enhanced‘for’ Statement704.4 Labels704.5 The break Statement714.6 The continue Statement71Exercises71CHAPTER 5 Arrays5.1 Array755.1.1 Declaring and Creating an Array755.1.2 Initializing an Array775.1.3 Using Arrays775.2 Two-dimensional Arrays795.2.1 One-dimensional Array Approach795.2.2 Two-dimensional Array Approach805.2.3 Populating Two-dimensional Arrays825.3 Applying the Enhanced‘for’ Statement in Arrays835.4 An Application: Printing Numbers Divisible by 3845.4.1 Using Label and break Statement855.4.2 Using continue Statement88Workshops90Workshop 5.1: Copying Arrays90Exercises96CHAPTER 6 Methods6.1 Defining a Problem986.2 A Problem Solving Approach996.3 Improving the Problem-Solving Approach1036.3.1 Advantage of Using Methods1076.3.2 Walking Through readInputValues() Method1076.3.3 Walking Through convertMarksToGrades() Method1076.3.4 Walking Through printDetails() Method1076.4 Block Structure and Scope1086.4.1 Local Variables1086.4.2 Global Variables1096.4.3 Determining Scope of Variables across Methods1106.4.4 Distinguishing Local Variables from Global Variables1116.4.5 Scope of Identifier Declaration1126.5 Parameters1136.5.1 Actual and Formal Parameters1136.5.2 Value Parameters1176.6 Methods that Return Values1196.6.1 Returning Values1196.6.2 The return Statement121Workshops121Workshop 6.1: Using Methods121Exercises125CHAPTER 7 Class and Objects7.1 Class and Objects1287.2 Constructing Objects1287.2.1 Constructors1297.2.2 Multiple Constructor Method Definition1317.2.3 Constructor Method Invocation1337.3 Instance and Class Variables1347.4 Instance and Class Methods1357.4.1 Instance Methods1357.4.2 Class Methods1367.5 Constants1387.6 The this Keyword1397.6.1 Using this Keyword in Instance Method1407.6.2 Using this Keyword in Constructor1417.7 Inner Class1417.7.1 Compiling an Inner Class1427.7.2 Static Inner Class1437.7.3 Creating Inner Class Objects1437.8 Class Hierarchy1437.8.1 Superclass and Subclass1447.8.2 Inheritance146Workshops148Workshop 7.1: Implementing Class and Objects148Exercises153CHAPTER 8 The Java Application Programming Interface (API)8.1 Java Package1578.1.1 The ‘package’ Keyword1588.1.2 The ‘import’ Keyword1598.1.3 File Name of a Public Class1618.2 The Java?TM Platform Standard Edition 1628.3 The Java API 1628.3.1 The Java API Documentation1638.3.2 The Java API Packages1648.3.3 Directory Structure of Java API Packages1678.3.4 The java.lang, java.io, and java.util Packages1688.3.5 Reading the Java API Documentation1688.3.6 Using the Java API1698.4 The Ubiquitous System.out.println() Method1708.4.1 The System Class1708.4.2 The PrintStream Class1718.5 String Tokenizers1738.5.1 The java.util.StringTokenizer Class 1738.5.2 Delimiter Characters 175Exercises176CHAPTER 9 Inputs and Outputs9.1 Input and Output Streams1789.1.1 Screen Outputs1789.1.2 Keyboard Inputs1799.1.3 Reading and Displaying Texts 1809.2 Exception Handling1819.2.1 Java Exception Handling 1819.2.2 Explicit Exception Handling 1829.3 The Scanner Class1859.3.1 Creating a Scanner Object1869.3.2 Handling Numerical Data Types1869.3.3 Handling String Values1869.3.4 Handling Boolean Values1869.3.5 Exceptions and Delimiters1879.3.6 A Scanner Class Application188Exercises190CHAPTER 10 File Handling10.1 Text Files19310.1.1 Writing to a Text File 19310.1.2 Appending Texts to a File 19510.1.3 Reading from a File 19510.2 Binary Files196Exercises198CHAPTER 11 Inheritance11.1 The Inheritance Mechanism19911.1.1 Subclass and Superclass19911.1.2 java.lang.Object Class20011.1.3 Downward Property Propagation20011.2 Demonstrating Inheritance20011.3 The super Keyword20211.3.1 Syntax20211.3.2 Constructor Chaining20311.3.3 Calling Superclass Methods20511.4 Method Overriding205Exercises207CHAPTER 12 Encapsulation12.1 Access Modifiers: public, protected, private21612.1.1 Using Access Modifiers21612.1.2 Accessibility Effects21712.2 Data Field Encapsulation21812.3 Class Abstraction 21912.4 Class Encapsulation22012.4.1 Encapsulating a Class22012.4.2 Enhanced Maintainability22212.4.3 Bundling and Information Hiding225Exercises226CHAPTER 13 Polymorphism13.1 Illustrating Polymorphism with Geometric Shapes22913.1.1 The Triangle Class23013.1.2 The Rectangle Class23113.1.3 The GeometricShape Class23313.1.4 The User Class: GeometricShapeMain Class23413.2 Abstract Class 23513.3 Dynamic Binding236Exercises237CHAPTER 14 Interface14.1 The Interface Construct23914.2 Interface Definition23914.2.1 Interface Declaration and Interface Body24014.2.2 Compilation of Interface24114.2.3 Implementing Interface24114.3 Understanding the Use of Interface24314.4 What and How in the Use of Interface24414.5 Application of Interface24514.5.1 Sales Person Application24514.5.2 SalesPerson and Employee Class24714.5.3 Sort by Age: The main() Method 124814.5.4 Sort by Name: The main() Method 225014.5.5 Sort by Wage: The main() Method 325114.5.6 The Output25114.6 The Serializable Interface25214.7 Interface and Abstract Class25714.8 Changes in Interface25714.9 Uses of Interface258Exercises258CHAPTER 15 Sorting, Searching, and Recursion15.1 Sorting26415.1.1 Selection Sort26415.1.2 Bubble Sort26715.1.3 A Sorting Application26915.2 Searching27315.2.1 Linear Search27315.2.2 Binary Search27415.2.3 A Searching Application27615.3 Recursion28015.3.1 Recursive Method28115.3.2 Writing a Recursive Method28415.3.3 The Ubiquitous Factorial28415.3.4 Applying Recursion285

章节摘录

  The Java Application Programming Interface (API)  Java is a very small language with only 46 reserved keywords but it is extended with a library of Java Application Programming Interfaces (Java APIs). It is from the Java APIs that the power of Java is felt. This chapter introduces the Java API and its accompanying documentation and explains how the Java API can be used to solve complicated problems in Java.  Chapter 9: Inputs and Outputs  This chapter explains how data input and output can be carried out in Java.  Chapter 10: File Handling  This chapter discusses how to read and write data from text and binary files.  Chapter 11: Inheritance  Inheritance is an object-oriented mechanism for realizing software reuse. A subclass in single class inheritance can inherit properties from a superclass. When a subclass inherits properties from more than one superclass, we have multiple class inheritance. This chapter discusses concepts related to single class inheritance.  Chapter 12: Encapsulation  Encapsulation is the bringing together of data fields and methods into an object definition with the effect of hiding the internal workings of the data fields and methods from the users of the object. Any direct access and updates to the object’s constituents is not permissible and changes to the data fields can only be carried out indirectly via a set of publicly available methods. This chapter focuses on data field encapsulation and class encapsulation.  Chapter 13: Polymorphism  The ability of objects of different subclass definition to respond to the same message is polymorphism. Polymorphism is only possible with dynamic binding-the capability of determining which method implementation to use for a method at runtime. This chapter explains the concept of polymorphism and its peripheral object-oreinted programming concepts.  Chapter 14: Interface  Sometimes it is necessary to derive a subclass from several classes but the Java extends keyword does not allow for more than one parent class. With interfaces, multiple class inheritance is possible. This chapter explains and shows how to use the Java interface construct to realize multiple class inheritance.  Chapter 15: Sorting, Searching and Recursion  This chapter discusses three topics commonly found in Java programming. They include: Sorting, Searching, and Recursion.  Enjoy!

图书封面

图书标签Tags

评论、评分、阅读与下载


    Java 程序设计 PDF格式下载


用户评论 (总计0条)

 
 

 

250万本中文图书简介、评论、评分,PDF格式免费下载。 第一图书网 手机版

京ICP备13047387号-7