0% found this document useful (0 votes)
61 views25 pages

Java Programming From Problem Analysis To Program Design 5th Edition by DS Malik ISBN 1133173357 9781133173359

The document provides links to download various programming textbooks, including titles on Java and C++ by authors such as D.S. Malik and Thomas Wu. It emphasizes the availability of high-quality ebooks and textbooks at ebookball.com. Additionally, it contains copyright information and details about the content and structure of the textbooks.

Uploaded by

nackabashta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views25 pages

Java Programming From Problem Analysis To Program Design 5th Edition by DS Malik ISBN 1133173357 9781133173359

The document provides links to download various programming textbooks, including titles on Java and C++ by authors such as D.S. Malik and Thomas Wu. It emphasizes the availability of high-quality ebooks and textbooks at ebookball.com. Additionally, it contains copyright information and details about the content and structure of the textbooks.

Uploaded by

nackabashta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Download the full version and explore a variety of ebooks

or text books at https://ebookball.com

Java Programming From Problem Analysis to Program


Design 5th Edition by DS Malik ISBN 1133173357
9781133173359

_____ Follow the link below to get your download now _____

https://ebookball.com/product/java-programming-from-problem-
analysis-to-program-design-5th-edition-by-ds-malik-
isbn-1133173357-9781133173359-11552/

Access ebookball.com now to download high-quality


ebooks or textbooks
We have selected some products that you may be interested in
Click the link to download now or visit ebookball.com
for more options!.

C++ Programming From Problem Analysis to Program Design


8th Edition by Malik ISBN 1337102087 9781337102087

https://ebookball.com/product/c-programming-from-problem-analysis-to-
program-design-8th-edition-by-malik-
isbn-1337102087-9781337102087-17114/

C++ Programming Program Design Including Data Structures


5th Edition by Malik ISBN 0538798092 9780538798099

https://ebookball.com/product/c-programming-program-design-including-
data-structures-5th-edition-by-malik-
isbn-0538798092-9780538798099-11554/

An Introduction to Object Oriented Programming with Java


5th Edition by Thomas Wu ISBN 9780073523309 0073523305

https://ebookball.com/product/an-introduction-to-object-oriented-
programming-with-java-5th-edition-by-thomas-wu-
isbn-9780073523309-0073523305-15552/

An Introduction to Object Oriented Programming with Java


5th Edition by Thomas Wu ISBN 0073523305 9780073523309

https://ebookball.com/product/an-introduction-to-object-oriented-
programming-with-java-5th-edition-by-thomas-wu-
isbn-0073523305-9780073523309-16398/
An Introduction to Object Oriented Programming With Java
5th Edition by Thomas Wu 0073523305 9780073523309

https://ebookball.com/product/an-introduction-to-object-oriented-
programming-with-java-5th-edition-by-thomas-
wu-0073523305-9780073523309-17244/

An Introduction to Object Oriented Programming With Java


5th Edition by Thomas Wu 0073523305 9780073523309

https://ebookball.com/product/an-introduction-to-object-oriented-
programming-with-java-5th-edition-by-thomas-
wu-0073523305-9780073523309-15256/

An Introduction to Object Oriented Programming With Java


5th Edition by Thomas Wu 0073523305 9780073523309

https://ebookball.com/product/an-introduction-to-object-oriented-
programming-with-java-5th-edition-by-thomas-
wu-0073523305-9780073523309-15330/

Problem Solving and Program Design in C 3rd Edition by


Jeri Hanly, Elliot Koffman ISBN 0201754908 9780201754902

https://ebookball.com/product/problem-solving-and-program-design-
in-c-3rd-edition-by-jeri-hanly-elliot-koffman-
isbn-0201754908-9780201754902-15530/

Java How to Program 6th Edition by Harvey Deitel


0131483986 978-0131483989

https://ebookball.com/product/java-how-to-program-6th-edition-by-
harvey-deitel-0131483986-978-0131483989-15314/
This is an electronic version of the print textbook. Due to electronic rights restrictions,
some third party content may be suppressed. Editorial review has deemed that any suppressed
content does not materially affect the overall learning experience. The publisher reserves the right
to remove content from this title at any time if subsequent rights restrictions require it. For
valuable information on pricing, previous editions, changes to current editions, and alternate
formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for
materials in your areas of interest.

Copyright
Editorial 2011
review hasCengage Learning.
deemed that All Rightscontent
any suppressed Reserved.
doesMay not be copied,
not materially scanned,
affect or duplicated,
the overall in whole orCengage
learning experience. in part. Due to electronic
Learning reservesrights, some
the right third party
to remove contentcontent
additional may beatsuppressed
any time iffrom the eBook
subsequent and/or
rights eChapter(s).
restrictions require it.
1019763_FM_VOL-I.qxp 9/17/07 4:22 PM Page viii

1
2
3
4
5
6
7
8
9
10
11 This page was intentionally left blank
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
S 50
R 51

1st Pass Pages


Java Programming: From Problem Analysis ª 2012 Course Technology, Cengage Learning
to Program Design, Fifth Edition
ALL RIGHTS RESERVED. No part of this work covered by the
D.S. Malik copyright herein may be reproduced, transmitted, stored or used
Executive Editor: Marie Lee in any form or by any means graphic, electronic, or mechanical,
including but not limited to photocopying, recording, scanning,
Acquisitions Editor: Brandi Shailer digitizing, taping, Web distribution, information networks, or
Senior Product Manager: Alyssa Pratt information storage and retrieval systems, except as permitted
Editorial Assistant: Jacqueline Lacaire under Section 107 or 108 of the 1976 United States Copyright Act,
without the prior written permission of the publisher.
Content Project Manager: Lisa Weidenfeld
Associate Marketing Manager: Shanna For product information and technology assistance, contact us at
Shelton Cengage Learning Customer & Sales Support, 1-800-354-9706
Art Director: Faith Brosnan For permission to use material from this text or product, submit
all requests online at www.cengage.com/permissions
Proofreader: Andrea Schein
Further permissions questions can be emailed to
Indexer: Alexandra Nickerson [email protected]
Print Buyer: Julio Esperas
Cover Designer: Roycroft Design/
www.roycroftdesign.com Library of Congress Control Number: 2010940363
Cover Photo: ª photolibrary/Richard ISBN-13: 978-1-111-53053-2
Cummins ISBN-10: 1-111-53053-x
Compositor: Integra Course Technology
20 Channel Center Street
Boston, MA 02210
Some of the product names and company
USA
names used in this book have been used for
identification purposes only and may be
trademarks or registered trademarks of their Cengage Learning is a leading provider of customized
respective manufacturers and sellers. learning solutions with office locations around the globe,
including Singapore, the United Kingdom, Australia, Mexico,
Any fictional data related to persons or
Brazil and Japan. Locate your local office at:
companies or URLs used throughout this
www.cengage.com/global
book is intended for instructional purposes
only. At the time this book was printed, any Cengage Learning products are represented in Canada by
such data was fictional and not belonging to Nelson Education, Ltd.
any real persons or companies.
To learn more about Course Technology, visit
Course Technology, a part of Cengage www.cengage.com/coursetechnology
Learning, reserves the right to revise this
Purchase any of our products at your local college store
publication and make changes from time to
or at our preferred online store www.cengagebrain.com
time in its content without notice.
The programs in this book are for
instructional purposes only. They have been
tested with care, but are not guaranteed for
any particular intent beyond educational
purposes. The author and the publisher do
not offer any warranties or representations,
nor do they accept any liabilities with respect
to the programs.

Printed in the United States of America


1 2 3 4 5 6 7 16 15 14 13 12 11 10

Editorial review
Copyright hasCengage
2011 deemed that any suppressed
Learning. All Rightscontent doesMay
Reserved. not materially affect
not be copied, the overall
scanned, learning experience.
or duplicated, in whole orCengage Learning
in part. Due reservesrights,
to electronic the right to remove
some additional
third party contentcontent
may beatsuppressed
any time iffrom
subsequent rights
the eBook restrictions
and/or require it.
eChapter(s).
JAVA PROGRAMMING
FROM PROBLEM ANALYSIS TO PROGRAM DESIGN

FIFTH EDITION

D.S. MALIK

Australia  Brazil  Japan  Korea  Mexico  Singapore  Spain  United Kingdom  United States

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
TO

My Daughter

Shelly Malik

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
B RIEF C ONTENTS

PREFACE xix
1. An Overview of Computers and Programming Languages 1

2. Basic Elements of Java 25

3. Introduction to Objects and Input/Output 113

4. Control Structures I: Selection 177

5. Control Structures II: Repetition 249

6. Graphical User Interface (GUI) and Object-Oriented Design (OOD) 327

7. User-Defined Methods 383

8. User-Defined Classes and ADTs 465

9. Arrays 551

10. Inheritance and Polymorphism 639

11. Handling Exceptions and Events 723

12. Advanced GUIs and Graphics 783

13. Recursion 873

14. Searching and Sorting 907

APPENDIX A Java Reserved Words 939

APPENDIX B Operator Precedence 941

APPENDIX C Character Sets 945

APPENDIX D Additional Java Topics 949

APPENDIX E Answers to Odd-Numbered Exercises 997

INDEX 1023
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
TABLE OF C ONTENTS

Preface xix

AN OVERVIEW OF COMPUTERS AND


1 PROGRAMMING LANGUAGES 1
Introduction 2

An Overview of the History of Computers 2

Elements of a Computer System 4


Hardware 4
Software 6

Language of a Computer 6

Evolution of Programming Languages 8

Processing a Java Program 10

Internet, World Wide Web, Browser, and Java 13

Programming with the Problem


Analysis–Coding–Execution Cycle 13

Programming Methodologies 19
Structured Programming 19
Object-Oriented Programming 19

Quick Review 21

Exercises 23

Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents | vii

BASIC ELEMENTS OF JAVA 25


2 A Java Program 26

Basics of a Java Program 28


Comments 29
Special Symbols 30
Reserved Words (Keywords) 30
Identifiers 31

Data Types 32
Primitive Data Types 32

Arithmetic Operators and Operator Precedence 36


Order of Precedence 39

Expressions 40
Mixed Expressions 41

Type Conversion (Casting) 43

class String 45
Strings and the Operator + 46

Input 48
Allocating Memory with Named Constants and Variables 48
Putting Data into Variables 51
Declaring and Initializing Variables 55
Input (Read) Statement 56
Reading a Single Character 61

Increment and Decrement Operators 64

Output 66

Packages, Classes, Methods, and the import Statement 71

Creating a Java Application Program 72

Debugging: Understanding and Fixing Syntax Errors 77

Programming Style and Form 80


Syntax 80

Avoiding Bugs: Consistent, Proper Formatting and


Code Walk-Through 84

Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
viii | Java Programming: From Problem Analysis to Program Design, Fifth Edition

More on Assignment Statements (Optional) 85

Quick Review 94

Exercises 97

Programming Exercises 106

INTRODUCTION TO OBJECTS AND INPUT/OUTPUT 113


3 Objects and Reference Variables 114

Using Predefined Classes and Methods in a Program 118


Dot Between Class (Object) Name and Class Member: A
Precaution 120

class String 121

Input/Output 129
Formatting Output with printf 129
Using Dialog Boxes for Input/Output 139
Formatting the Output Using the String Method format 146

File Input/Output 149


Storing (Writing) Output to a File 152

Debugging: Understanding Logic Errors and


Debugging with print or println Statements 163

Quick Review 165

Exercises 167

Programming Exercises 171

CONTROL STRUCTURES I: SELECTION 177


4 Control Structures 178

Relational Operators 180

Relational Operators and Primitive Data Types 181

Logical (Boolean) Operators and Logical Expressions 183

Order of Precedence 185


boolean Data Type and Logical (Boolean) Expressions 189

Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents | ix

Selection: if and if...else 190


One-Way Selection 190
Two-Way Selection 193
Compound (Block of) Statements 197
Multiple Selections: Nested if 198
Comparing if...else Statements with a Series
of if Statements 200
Short-Circuit Evaluation 201
Comparing Floating-Point Numbers for Equality:
A Precaution 202
Conditional Operator (? :) (Optional) 204

Avoiding Bugs by Avoiding Partially Understood


Concepts and Techniques 204

Program Style and Form (Revisited): Indentation 208

switch Structures 208

Avoiding Bugs by Avoiding Partially Understood


Concepts and Techniques (Revisited) 215

Comparing Strings 223


Strings, the Assignment Operator, and the Operator new 229

Quick Review 230

Exercises 232

Programming Exercises 241

CONTROL STRUCTURES II: REPETITION 249


5 Why Is Repetition Needed? 250

while Looping (Repetition) Structure 251


Designing while Loops 254
Counter-Controlled while Loops 255
Sentinel-Controlled while Loops 257
Flag-Controlled while Loops 263
EOF-Controlled while Loops 266
More on Expressions in while Statements 271

for Looping (Repetition) Structure 278

Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
x | Java Programming: From Problem Analysis to Program Design, Fifth Edition

do...while Looping (Repetition) Structure 288


Choosing the Right Looping Structure 293

break and continue Statements 293

Avoiding Bugs by Avoiding Patches 295

Debugging Loops 298

Nested Control Structures 299

Quick Review 304

Exercises 306

Programming Exercises 319

GRAPHICAL USER INTERFACE (GUI) AND


6 OBJECT-ORIENTED DESIGN (OOD) 327
Graphical User Interface (GUI) Components 328
Creating a Window 332
JFrame 332
Getting Access to the Content Pane 338
JLabel 339
JTextField 343
JButton 347

Object-Oriented Design 363


A Simplified OOD Methodology 364

Implementing Classes and Operations 370


Primitive Data Types and the Wrapper Classes 370

Quick Review 377

Exercises 378

Programming Exercises 381

USER-DEFINED METHODS 383


7 Predefined Methods 384
Using Predefined Methods in a Program 388

User-Defined Methods 391


Value-Returning Methods 391

Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents | xi

return Statement 395


Final Program 398

Flow of Execution 404

Void Methods 407

Primitive Data Type Variables as Parameters 411

Reference Variables as Parameters 414


Parameters and Memory Allocation 414
Reference Variables of the String Type as Parameters:
A Precaution 414
The class StringBuffer 418

Primitive Type Wrapper Classes as Parameters 421

Scope of an Identifier Within a Class 422

Method Overloading: An Introduction 427

Debugging: Using Drivers and Stubs 440

Avoiding Bugs: One-Piece-at-a-Time Coding 442

Quick Review 442

Exercises 445

Programming Exercises 456

USER-DEFINED CLASSES AND ADTS 465


8 Classes and Objects 466
Constructors 471
Unified Modeling Language Class Diagrams 472
Variable Declaration and Object Instantiation 473
Accessing Class Members 475
Built-in Operations on Classes 476
Assignment Operator and Classes: A Precaution 476
Class Scope 478

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xii | Java Programming: From Problem Analysis to Program Design, Fifth Edition

Methods and Classes 479


Definitions of the Constructors and Methods
of the class Clock 479

Classes and the Method toString 494

Copy Constructor 500

Static Members of a Class 501


static Variables (Data Members) of a Class 503

Finalizers 507

Accessor and Mutator Methods 507

Debugging—Designing and Documenting a Class 510

Reference this (Optional) 512


Cascaded Method Calls (Optional) 514

Inner Classes 517

Abstract Data Types 517

Quick Review 537

Exercises 538

Programming Exercises 547

ARRAYS 551
9 Why Do We Need Arrays? 552

Arrays 553
Alternate Ways to Declare an Array 555
Accessing Array Elements 555
Specifying Array Size during Program Execution 557
Array Initialization during Declaration 558
Arrays and the Instance Variable length 558
Processing One-Dimensional Arrays 559
Array Index Out of Bounds Exception 564
Declaring Arrays as Formal Parameters to Methods 564
Assignment Operator, Relational Operators, and Arrays:
A Precaution 565
Arrays as Parameters to Methods 567

Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents | xiii

Searching an Array for a Specific Item 572

Arrays of Objects 574


Arrays of string Objects 574
Arrays of Objects of Other Classes 576

Arrays and Variable Length Parameter List (Optional) 581

Two-Dimensional Arrays 589


Accessing Array Elements 591
Two-Dimensional Array Initialization during Declaration 594
Processing Two-Dimensional Arrays 595
Passing Two-Dimensional Arrays as Parameters to Methods 599

Multidimensional Arrays 603

class Vector (Optional) 616


Primitive Data Types and the class Vector 620
Vector Objects and the foreach Loop 620

Quick Review 621

Exercises 623

Programming Exercises 634

INHERITANCE AND POLYMORPHISM 639


10 Inheritance 640
Using Methods of the Superclass in a Subclass 642
Constructors of the Superclass and Subclass 648
Protected Members of a Class 657
Protected Access vs Package Access 660

class Object 661

Java Stream Classes 663

Polymorphism 664
Operator instanceof 670

Abstract Methods and Classes 674

Interfaces 681

Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Other documents randomly have
different content
back
back
back
back
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookball.com

You might also like