Java语言

出版时间:2004-4  出版社:清华大学出版社  作者:萨维特  
Tag标签:无  

前言

This book was designed to be used in a first course in programming and computer science.It covers programming techniques, as well as the basics of the Java programming language. It is suitable for courses as short as one quarter or as long as one full academic year.No previous programming experience is required, nor is any mathematics, other than a little high school algebra. The book can also be used for a course designed to teach Java to students who have already had another programming course, in which case the first few chapters can be assigned as outside reading. (For students who have had previous programming experience in C or C++, there is an appendix that explains some of the differences between Java and C or C++.)All of the code in the book has been tested with Java 2 from Sun Microsystems (version 1.4). To be fully compatible with the material presented, the Java used in your class should be version 1.4 or higher. The coverage of Java was carefully arrived at by class testing and is a concise, accessible introduction for beginners.Changes in This EditionIf you have not used the second edition of this text, you can skip this subsection. If you have used the second edition, this subsection will tell you how this third edition differs from that edition.For instructors, the transition from the second edition of the text to this third edition is easy: You can teach the same course, with basically the same topics presented, in the same order and with only very minor changes in the material covered.

内容概要

《Java语言:计算机科学与程序设计》是由著名作者Walter Savitch编写的,主要介绍了Java 程序设计,对Java语言的主要特点和应用编程进行了全面讲述。《Java语言:计算机科学与程序设计》最显著的特点是,作者采用通俗易懂的方式,结合Java语方,介绍了各种基本编程技术,阐述了面向对象编程技术与计算机科学的各种概念。《Java语言:计算机科学与程序设计》每章后附本章小结,并提供了测试题和答案、编程项止练习,以帮助学生对所学知识的掌握,提高学生的实际编程能力。《Java语言:计算机科学与程序设计》配套光盘包含了范例程序代码和相应软件。
《Java语言:计算机科学与程序设计》可作为计算机科学及相关专业的Java程序设计教材,也是Java开发人员的很好参考书。

作者简介

作者:(美国)萨维特 (Walter Savitch)

书籍目录

CHAPTER 1 Introduction to Computers and JavaObjectivesPrerequisites1.1 Computer BasicsHardware and MemoryProgramsProgramming Languages and CompilersJava Byte-CodeLinking1.2 Designing ProgramsObject-Oriented ProgrammingEncapsulationPolymorphismInheritanceIf You Know Some Other Programming LanguageNgorithmsReusable ComponentsTesting and Debugging6otcha: Coping with "Gotchas"6otcha: Hidden Errors1.3 A Sip of JavaHistory of the Java LanguageAppletsA First Java Application ProgramCompiling a Java Program or ClassRunning a Java ProgramPreview Examples of Applets (Optional)Chapter SummaryAnswers to Self-Test QuestionsProgramming ProjectsCHAPTER 2 Primitive Types, Strings, and Console I/OObjectivesPrerequisites2.1 Primitive Types and ExpressionsVariablesJava Identifiers6otcha: Java Is Case-SensitivePrimitive TypesAssignment StatementsSpecialized Assignment OperatorsSimple Input and OutputNumber ConstantsAssignment CompatibilitiesType CastingJava Tip: Type Casting a Character to an IntegerProgramming Tip: Initialize VariablesGotcha: Imprecision in Floating-Point NumbersArithmetic OperatorsParentheses and Precedence RulesCase Study: Vending Machine ChangeIncrement and Decrement OperatorsMore about the Increment and Decrement Operators2.2 The Class StringString Constants and VariablesConcatenation of StringsClassesString MethodsString ProcessingEscape CharactersThe Unicode Character Set2.3 Keyboard and Screen I/OScreen OutputInput Using SavitchInMore Input MethodsGotcha: readInt and readDoub3 eProgramming Tip: Echo Input2.4 Documentation and StyleProgramming Tip: Use Meaningful Names for VariablesDocumentation and CommentsIndentingNamed ConstantsChapter SummaryAnswers to Self-Test QuestionsProgramming ProjectsCHAPTER 3 Flow of ControlObjectivesPrerequisites3.1 Branching StatementsThe if-else StatementIntroduction to Boolean ExpressionsGotcha: Using==with StringsProgramming Tip: Alphabetical OrderNested Statements and Compound StatementsJava Tip: Matching else and ifMultibranch if-el se StatementsProgramming Example: Assigning Letter GradesThe switch StatementGotcha: Omitting a break StatementThe Conditional Operator (Optional)3.2 Java Loop Statementswhile StatementsJava Tip: A while Loop Can Perform Zero IterationsThe do-while StatementProgramming Example: Bug InfestationGotcha: Infinite LoopsThe for Statementthe Camma in for Statements (Optional)Gotcha: Extra Semicolon in a Loop StatementJava Tip: Choosing a Loop StatementThe break Statement in LoopsGotcha: Misuse of break StatementsThe exit Method3.3 Programming with LoopsThe Loop BodyInitializing StatementsEnding a LoopProgramming Example: Nested LoopsProgramming Tip: Avoid Declaring Variables in a Loop BodyLoop BugsTracing Variables3.4 The Type booleanBoolean Expressions and Boolean VariablesProgramming Tip: Naming Boolean VariablesPrecedence RulesInput and Output of Boolean ValuesCase Study: Using a Boolean Variable to End a LoopChapter SummaryAnswers to Self-Test QuestionsProgramming ProjectsCHAPTER 4 Defining Classes and MethodsObjectivesPrerequisites4.1 Class and Method DefinitionsClass Files and Separate CompilationInstance VariablesUsing Methodsvoid Method DefinitionsMethods That Return a ValueJava Tip: Use of return in void MethodsThe this ParameterLocal VariablesBlocksGotcha:Variables Declared in a BlockJava Tip: Declaring Variables in a for StatementParameters of a Primitive TypeGotcha: Use of the Terms Parameter and ArgumentSummary of Class and Method Definition Syntax4.2 Information Hiding and EncapsulationInformation HidingProgramming Tip: Parameter Names Are Local to the MethodPrecondition and Postcondition CommentsJava Tip: Assertion ChecksThe publ i c and private ModifiersProgramming Tip: Instance Variables Should Be privateProgramming Example: A Purchase ClassEncapsulationAutomatic Documentation with javadocUML Class Diagrams4.3 Objects and ReferenceVariables of a Class Type and ObjectsGotcha: Use of = and == with Variables of a Class TypeJava Tip: Define an equal s Method for Your ClassesProgramming Example: A Species ClassBoolean-Valued MethodsClass ParametersComparing Class Parameters and Primitive-Type ParametersChapter SummaryAnswers to Self-Test QuestionsProgramming ProjectsCHAPTER 5 More About Objects and MethodsObjectivesPrerequisites5.1 Programming with MethodsMethods Calling MethodsProgramming Tip: Make Helping Methods PrivateJava Tip: Make the compiler HappyGotcha: Null Pointer Exception5.2 Static Methods and Static VariablesStatic MethodsGotcha: Invoking a Nonstatic Method Within a Static MethodJava Tip: You Can Put a main in Any ClassStatic Variables (Optional)The Math ClassInteger, Double, and Other Wrapper Classes5.3 Designing MethodsCase Study: Formatting OutputTop-Down DesignTesting Methods5.4 OverloadingOverloading BasicsProgramming Example: A Pet ClassGotcha: Overloading and Automatic Type ConversionGotcha: You Cannot Overload on the Basis of the Returned TypeProgramming Example: A Class for Money5.5 ConstructorsDefining ConstructorsProgramming Tip: You Can Use Other Methods in a ConstructorGotcha: Omitting the Default ConstructorGotcha: Many Wrapper Classes Have No Default Constructor5.6 Information Hiding RevisitedGotcha: Privacy Leaks5.7 PackagesPackages and importingPackage Names and DirectodesGotcha: Not Including the Current Directory in Your Class PathName ClashesChapter SummaryAnswers to Self-Test QuestionsProgramming ProjectsCHAPTER 6 ArraysObjectivesPrerequisites6.1 Array BasicsCreating and Accessing ArraysArray DetailsProgramming Tip: Use Singular Array NamesThe length Instance VariableJava Tip: Array Indices Start with ZeroProgramming Tip: Use a for Loop to Step Through an ArrayGotcha: Array Index Out of BoundsInitializing Arrays6.2 Arrays in Classes and MethodsCase Study: Sales ReportIndexed Vadablas as Method ArgumentsEntire Arrays as Method ArgumentsArguments for the Method mai nGotcha: Use of = and == with ArraysMethods That Return Arrays6.3 Progrannning with Arrays and ClassesProgramming Example: A Specialized List ClassPartially Filled ArraysSearching an ArrayGotcha: Returning an Array Instance Variable6.4 Sorting ArraysSelection SortOther Sorting Algorithms6.5 Multidimensional ArraysMultidimensional-Array BasicsMultidimensional-Array Parameters and Returned ValuesImplementation of Multidimensional ArraysBagged Arrays (OpUonal)Programming Example: Employee Time RecordsChapter SummaryAnswers to Self-Test QuestionsProgramming ProjectsCHAPTER 7 InheritanceObjectivesPrerequisites7.1 Inheritance BasicsProgramming Example: A Person ClassDerived ClassesOverriding Method DefinitionsOverriding Versus OverloadingThe final ModifierGotcha: Use of Private Instance Variables from the Base ClassProgramming Tip: Assume That Your Coworkers Are MaliciousGotcha: Private Methods Are Not InheritedUML Inheritance Diagrams7.2 Programming with InheritanceConstructors in Derived ClassesThe this Method (OpUonal)Call to an Overridden MethodProgramming Example: Multilevel Derived ClassesA Subtle Point About Overloading and Overriding (Optional)Java Tip: You Cannot Use Multiple supersProgramming Tip: An Object Can Have More than One TypeProgramming Tip: "Is a" and "Has a" RelationsThe Class ObjectCase Study: Character GraphicsAbstract ClassesInterlaces (Optional)7.3 Dynamic Binding and PolymorphismDynamic BindingType Checking and Dynamic BindingDynamic Binding with toStringPolymorphismJava Tip: A Better equal s Method (Optional)Chapter SummaryAnswers to Self-Test QuestionsProgramming ProjectsCHAPTER 8 Exception HandlingObjectivesPrerequisites8.1 Basic Exception HandlingExceptions in JavaPredefined Exception ClassesArrayIndexOutOfBoundsException (Alternative Ordering)8.2 Defining Exception ClassesDefining Your Own Exception ClassesJava Tip: Preserve getMessage When You Define Exception ClassesProgramming Tip: When to Define an Exception Class8.3 Using Exception ClassesDeclaring Exceptions (Passing the Buck)Exceptions That De Not Need To Be CaughtThe Assertion Error Class (Optional)Multiple Throws and CatchesJava Tip: Catch the More Specific Exception FirstProgramming Tip: Exception Handling and Information HidingGotcha: Overuse of ExceptionsProgramming Tip: When to Throw an ExceptionGotcha: Nested try-catch BlocksThe finally Block (Optional)Rethrowing an Exception (Optional)Case Study' A Line-Oriented CalculatorChapter SummaryAnswers to Self-Test QuestionsProgramming ProjectsCHAPTER 9 Streams and File I/OObjectivesPrerequisites9.1 An Overview of Streams and File I/OThe Concept of a StreamWhy Use Files for I/O?Differences between Text Files and Binary Files9.2 Text-File I/OText-File Output with PrintWriterGotcha: A try Block Is a BlockGotcha: Overwriting a FileJava Tip: Appending To a Text FileJava Tip: Use toString for Text-File OutputText-File Input with BufferedReaderProgramming Example: Reading a File Name from the KeyboardJava Tip: Using Path NamesThe StringTokeni zer ClassJava Tip: Testing for the End of a Text FileThe Classes FileReader and FileOutputStreamUnwrapping the Class Savi tchIn9.3 The File ClassUsing the File Class9.4 Basic Binary-File I/OOutput to Binary Files, Using ObjectOutputStreamSome Details about writeUTF (Optional)Reading Input from a Binary File, Using ObjectInputStreamGotcha: Using ObjectInputStream with a Text FileGotcha: Defining a Method to Open a StreamThe EOFExcepti on ClassGotcha: Forgetting to Check for the End of a FileGotcha: Checking for the End of a File in the Wrong WayThe Classes Fi I eInputSt ream and File0utputStreamProgramming Example: Processing a File of Binary Data9.5 Object I/O with Object StreamsBinary I/0 of Class ObjectsGotcha: Exceptions, Exceptions, ExceptionsThe Serializable InterfaceGotcha: Mixing Class Types in the Same FileArray Objects in Binary FilesChapter SummaryAnswers to Self-Test QuestionsProgramming ProjectsCHAPTER 10 Dynamic Data StructuresObjectivesPrerequisites10.1 VectorsUsing VectorsProgramming Tip: Adding to a VectorGotcha: Vector Elements Are of Type ObjectComparing Vectors and ArraysGotcha: Using capacity Instead of sizeJava Tip: Use trimToSize to Save MemoryGotcha: Using the Method cloneJava Tip: Newer Collection Classes (Optional)10.2 Linked Data StructuresLinked ListsGotcha: Null Pointer ExceptionGotcha: Privacy LeaksInner ClassesNode Inner ClassesIteratorsProgramming Tip: Internal and External IteratorsException Handling with Linked ListsVariations on a Linked ListOther Linked Data StructuresChapter SummaryAnswers to Self-Test QuestionsProgramming ProjectsCHAPTER 11 RecursionObjectivesPrerequisites11.1 The Basics of RecursionCase Study: Digits to WordsHow Recursion WorksGotcha: Infinite RecursionRecursive versus Iterative DefinItionsRecursive Methods That Return a Value11.2 Programming with RecursionProgramming Tip: Ask Until the User Gets It RightCase Study: Binary SearchProgramming Tip: Generalize the ProblemProgramming Example: Merge Sort——A Recursive Sorting MethodChapter SummaryAnswers to Self-Test QuestionsProgramming ProjectsCHAPTER 12 Window Interfaces Using SwingObjectivesPrerequisites12.1 BackgroundGUIs——-Graphical User InterfacesEvent-Driven Programming12.2 Basic Swing DetailsGotcha: Save All Your Work before Running a Swing ProgramProgramming Example: A Simple WindowJava Tip: Ending a Swing ProgramGotcha: Forgetting to Program the Close-Window ButtonGotcha: Forgetting to Use getContentPaneMore about Window ListenersSize Units for Screen ObjectsMore on setVisibleProgramming Example: A Better Version of Our First Swing ProgramProgramming Example: A Window with ColorSome Methods of the Class JFrameLayout Managers12.3 Buttons and Action ListenersProgramming Example: Adding ButtonsButtonsAction Listeners and Action EventsGotcha: Changing the Parameter List for actionPerformedInterfacesJava Tip: Code a GUI's Look and Actions SeparatelyThe Model-View——Controller PatternJava Tip: Use the Method setActionCommand12.4 Container ClassesThe JPanel ClassThe Eontainer ClassJava Tip: Guide for Creating Simple Window Interfaces12.5 Text I/O for GUIsText Areas and Text FieldsProgramming Example: Labeling a Text FieldInputting and Outputting NumbersProgramming Example: A GUI Adding MachineCatching a NumberFormatExcepti onChapter SummaryAnswers to Self-Test QuestionsProgramming ProjectsCHAPTER 13 Applets and HTMLCHAPTER 14 More Swing

章节摘录

插图:

编辑推荐

《Java语言:计算机科学与程序设计(第3版)》是由清华大学出版社出版的。

图书封面

图书标签Tags

评论、评分、阅读与下载


    Java语言 PDF格式下载


用户评论 (总计0条)

 
 

 

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

京ICP备13047387号-7