• No results found

Computers, Objects, and Java p. 1 Welcome p. 2 What Is a Computer? p. 2 Networks, the Internet, and the World Wide Web p. 3 Why Study Programming? p.

N/A
N/A
Protected

Academic year: 2021

Share "Computers, Objects, and Java p. 1 Welcome p. 2 What Is a Computer? p. 2 Networks, the Internet, and the World Wide Web p. 3 Why Study Programming? p."

Copied!
6
0
0

Loading.... (view fulltext now)

Full text

(1)

Preface p. xiii

Computers, Objects, and Java p. 1

Welcome p. 2

What Is a Computer? p. 2

Networks, the Internet, and the World Wide Web p. 3

Why Study Programming? p. 6

Programming Languages p. 6

Why Java? p. 8

What Is Object-Oriented Programming? p. 10

Chapter Summary p. 18

Exercises p. 20

Java Program Design and Development p. 23

Introduction p. 24

Designing Good Programs p. 24

Designing a Riddle Program p. 26

Java Language Elements p. 33

Editing, Compiling, and Running a Java Program p. 48

From the Java Library: System and PrintStream p. 52

Chapter Summary p. 54

Solutions to Self-Study Exercises p. 56

Exercises p. 57

Objects: Using, Creating, and Defining p. 63

Introduction p. 64

Using String Objects p. 64

Drawing Shapes with a Graphics Object (Optional) p. 68

Class Definition p. 73

CASE STUDY: Simulating a Two-Person Game p. 78

From the Java Library: java.util.Scanner p. 91

Chapter Summary p. 95

Solutions to Self-Study Exercises p. 96

Exercises p. 97

Methods: Communicating with Objects p. 103

Introduction p. 104

Passing Information to an Object p. 104

Constructor Methods p. 111

Retrieving Information from an Object p. 115

Passing a Value and Passing a Reference p. 118

Flow of Control: Control Structures p. 121

Testing an Improved OneRowNim p. 129

From the Java Library: java.lang.Object p. 133

(2)

Drawing Lines and Defining Graphical Methods (Optional) p. 136

Chapter Summary p. 139

Solutions to Self-Study Exercises p. 140

Exercises p. 142

Input/Output: Designing the User Interface p. 149

Introduction p. 150

The Use Interface p. 150

A Command-Line Interface p. 151

A Graphical User Interface (GUI) p. 159

CASE STUDY: The One-Row Nim Game p. 175

From the Java Library: java.io.File and File Input (Optional) p. 183

Chapter Summary p. 186

Solutions to Self-Study Exercises p. 188

Exercises p. 190

Java Data and Operators p. 195

Introduction p. 196

Boolean Data and Operators p. 197

Numeric Data and Operators p. 204

From the Java Library: java.lang.Math p. 215

Numeric Processing Examples p. 216

From the Java Library: java.text.NumberFormat p. 228

Character Data and Operators p. 230

Example: Character Conversions p. 233

Problem Solving = Representation + Action p. 236

Chapter Summary p. 236

Solutions to Self-Study Exercises p. 238

Exercises p. 242

Control Structures p. 249

Introduction p. 250

Flow of Control: Repetition Structures p. 250

Counting Loops p. 251

Example: Car Loan p. 260

Graphics Example: Drawing a Checkerboard p. 262

Conditional Loops p. 266

Example: Computing Averages p. 272

Example: Data Validation p. 275

Principles of Loop Design p. 277

The switch Multiway Selection Structure p. 278

Object-Oriented Design: Structured Programming p. 282

Chapter Summary p. 290

(3)

Exercises p. 298

Strings and String Processing p. 305

Introduction p. 306

String Basics p. 306

Finding Things within a String p. 313

Example: Keyword Search p. 315

From the Java Library: java.lang.StringBuffer p. 317

Retrieving Parts of Strings p. 320

Example: Processing Names and Passwords p. 322

Processing Each Character in a String p. 323

Comparing Strings p. 326

From the Java Library: java.util.StringTokenizer p. 332

Handling Text in a Graphics Context (Optional) p. 334

Chapter Summary p. 340

Solutions to Self-Study Exercises p. 341

Exercises p. 344

Inheritance and Polymorphism p. 349

Introduction p. 350

Java's Inheritance Mechanism p. 350

Abstract Classes, Interfaces, and Polymorphism p. 359

Example: A Toggle Button p. 365

Example: The Cipher Class Hierarchy p. 368

CASE STUDY: A Two-Player Game Hierarchy p. 375

Principles of Object-Oriented Design p. 396

Chapter Summary p. 397

Solutions to Self-Study Exercises p. 398

Exercises p. 400

Arrays and Array Processing p. 405

Introduction p. 406

One-Dimensional Arrays p. 406

Simple Array Examples p. 413

Example: Counting Frequencies of Letters p. 416

Array Algorithms: Sorting p. 420

Array Algorithms: Searching p. 426

Two-Dimensional Arrays p. 430

Multidimensional Arrays (Optional) p. 437

Object-Oriented Design: Polymorphic Sorting (Optional) p. 439

From the Java Library: java. lang. Vector p. 443

CASE STUDY: An N-Player Computer Game p. 444

A GUI-Based Game (Optional Graphics) p. 452

(4)

Solutions to Self-Study Exercises p. 460

Exercises p. 465

Exceptions: When Things Go Wrong p. 471

Introduction p. 472

Handling Exceptional Conditions p. 472

Java's Exception Hierarchy p. 474

Handling Exceptions within a Program p. 478

Error Handling and Robust Program Design p. 488

Creating and Throwing Your Own Exceptions p. 497

From the Java Library: javax.swing.JOptionPane p. 501

Chapter Summary p. 503

Solutions to Self-Study Exercises p. 505

Exercises p. 507

Files and Streams: Input/Output Techniques p. 511

Introduction p. 512

Streams and Files p. 512

CASE STUDY: Reading and Writing Text Files p. 518

The File Class p. 530

Example: Reading and Writing Binary Files p. 533

Object Serialization: Reading and Writing Objects p. 542

From the Java Library: javax.swing.JFileChooser p. 547

Using File Data in Programs p. 548

Chapter Summary p. 551

Solutions to Self-Study Exercises p. 552

Exercises p. 553

Recursive Problem Solving p. 557

Introduction p. 558

Recursive Definition p. 561

Recursive String Methods p. 564

Recursive Array Processing p. 574

Example: Drawing (Recursive) Fractals p. 580

Object-Oriented Design: Tail Recursion p. 584

Object-Oriented Design: Recursion or Iteration? p. 586

From the Java Library: javax.swing.JComboBox p. 588

Chapter Summary p. 594

Solutions to Self-Study Exercises p. 595

Exercises p. 599

Graphical User Interfaces p. 603

Introduction p. 604

Java GUIs: From AWT to Swing p. 604

(5)

Object-Oriented Design: Model-View-Controller Architecture p. 607

The Java Event Model p. 609

CASE STUDY: Designing a Basic GUI p. 614

Containers and Layout Managers p. 627

Checkboxes, Radio Buttons, and Borders p. 633

Menus and Scroll Panes p. 641

Chapter Summary p. 650

Solutions to Self-Study Exercises p. 651

Exercises p. 653

Threads and Concurrent Programming p. 657

Introduction p. 658

What Is a Thread? p. 658

From the Java Library: java.lang.Thread p. 662

Thread States and Life Cycle p. 668

Using Threads to Improve Interface Responsiveness p. 670

CASE STUDY: Cooperating Threads p. 678

CASE STUDY: The Game of Pong p. 693

Chapter Summary p. 700

Solutions to Self-Study Exercises p. 702

Exercises p. 704

Sockets and Networking p. 707

Introduction p. 708

An Overview of Networks p. 708

Using Network Resources from an Applet p. 714

From the Java Library: java.net.URL p. 715

The Slide-Show Applet p. 717

Using Network Resources from an Application p. 722

Client/Server Communication via Sockets p. 732

CASE STUDY: Generic Client/Server Classes p. 736

Playing One-Row Nim Over the Network p. 745

Java Network Security Restrictions p. 752

Java Servlets and Java Server Pages p. 753

Chapter Summary p. 762

Solutions to Self-Study Exercises p. 763

Exercises p. 765

Data Structures: Lists, Stacks, and Queues p. 767

Introduction p. 768

The Linked List Data Structure p. 768

Object-Oriented Design: The List Abstract Data Type (ADT) p. 780

The Stack ADT p. 785

(6)

From the Java Library: The Java Collections Framework and Generic Types p. 791

Using the Set and Map Interfaces p. 795

The Binary Search Tree Data Structure p. 799

Chapter Summary p. 801

Solutions to Self-Study Exercises p. 803

Exercises p. 806

Coding Conventions p. 811

The Java Development Kit p. 819

The ASCII and Unicode Character Sets p. 828

Java Keywords p. 829

Operator Precedence Hierarchy p. 830

Java Inner Classes p. 832

Java Autoboxing and Enumeration p. 837

Java and UML Resources p. 841

Index p. 843

References

Related documents

Our proposal is for a study using New Zealand area-level census data, examining the relationship between inter-censal (5-year) migration flows and labour market conditions at

Automating the generation of student models for intelligent tutoring systems p. 701 Supporting learning in games with an open learner

Using the Cross Product to Provide Colour Variation to a Cylinder

Source: http://en wikipedia org/wiki/Traveling salesman problem

Team Smucker Love has been presented with a prompt that required our group to research and present the factors that are of most importance to recent college graduates when choosing

Por su alto contenido de metoxilos y su grado de esterificación, la solución pectica preparada, es adecuada para la preparación de mermeladas, ya que sus

Just as in the early days of object-oriented, Java, and Web application development, many companies attempted to build their own distributed services (load balancing, security,

This genre, and surprisingly COMEDY, contained the most tokens, but only by counting out frequencies can we really see if it had the highest frequency of